<?php
/*
	DevSaver web framework
	copyright (c) 2013-2016 DevSaver
		web:  www.devsaver.com
		mail: support@devsaver.com
*/


/**
* description
*
* @library	
* @author	
* @since	
*/
class CXMLFormLanguage {
	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Init($langs) {

		$this->langs = $langs;
		
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Process($form) {

		global $site;

/*
		if (!$site->vars->data["set_multilanguage"]) {
			return $form;
		}
*/		

		
		if (count($form["languages"]) < 2) {
			return $form;
		}
		
		if (is_array($form["box"])) {
		} else {
	
			if (is_array($form["fields"])) {
				foreach ($form["fields"] as $key => $val) {

				}								
			}
		}

		//debug($form,1);

		return $form;
		
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	static function LanguageButtons() {

		global $site , $form_languages;

		//get all languages

		$languages = $site->db->QFetchRowArray(
			"SELECT * FROM {$site->tables['core:languages']} ORDER BY lang_order ASC"
		);

		if (is_array($languages)) {
			foreach ($languages as $key => $lang) {
				$langs[$lang["lang_code"]]	= array(
					"code"		=> $lang["lang_code"],
					"id"		=> $lang["lang_id"],
					"dir"		=> $lang["lang_dir"],
					"default"	=> $lang["lang_default"],
					"title"		=> $form_languages[$lang["lang_code"]],
				);
			}			
		}

		//debug($languages,1);
		


		return $langs;
	
		
		//prepare the html for the forms



	}
	

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	static function GetLanguage($id , $type = "id") {
		global $site;

		switch ($type) {
			default:
				$cond = "lang_id={$id}";
			break;

			case "code":
				$cond = "lang_code LIKE '{$id}'";
			break;


		}
		

		$lang = $site->db->QFetchArray(
			"SELECT * FROM {$site->tables['core:languages']} WHERE {$cond}"
		);

		return array(
			"code"		=> $lang["lang_code"],
			"id"		=> $lang["lang_id"],
			"dir"		=> $lang["lang_dir"],
			"default"	=> $lang["lang_default"],
			"title"		=> $lang["lang_title"],
		);
	}
	

	
}

?>