Location: PHPKode > projects > OpenNitro > trunk/Nitro/Modules/BackOffice/AllowedLanguages/Module.inc.php
<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Modules :: NitroBOSubModule :: AllowedLanguages                  |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2006 June Systems B.V.                                      |
// +---------------------------------------------------------------------------+
// | This source file is copyrighted by June Systems BV, the Netherlands       |
// | If you would like to use this file in your projects, please contact       |
// | hide@address.com                                                     |
// +---------------------------------------------------------------------------+
// | Authors: Jesper Avôt <hide@address.com>                        |
// +---------------------------------------------------------------------------+
//
// $Id: Module.inc.php 229 2008-04-17 09:20:31Z oli $
//

/**
 * Include Form controls and Listing classes
 */
require_once "Nitro/Libraries/Form.inc.php";

/**
 * Language
 *
 * @author			Jesper Avôt <hide@address.com>
 * @copyright		2006 June Systems B.V.
 * @package			Modules
 * @subpackage  NitroBO
 */
class NitroBO_AllowedLanguages extends NitroBOSubModule {	
	/**
	 * Define some Module things
	 */
	var $ModuleName = "NitroBO_AllowedLanguages";
	var $ModuleVersion = "1.0";
	var $ModuleAuthor = Array("Jesper Avôt");
	
	/**
	 * Does Nothing
	 */
	function NitroBO_AllowedLanguages() { }
	
	/**
	 * GetSettingsDefinition function
	 *
	 * Which Settings are allowed in this Module?
	 */
	function GetSettingsDefinition()
	{
		DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
		
		if (!isset($this->_ModuleSettings)) {
			$this->_ModuleSettings = Array(
				'P'			 		=> Array('SessionVariable' => FALSE, 'FormVariable' => 'P', 				'Default' => NULL), 
				'Allowed' 	=> Array('SessionVariable' => FALSE, 'FormVariable' => 'Allowed',		'Default' => NULL)
			);
		}
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $this->_ModuleSettings;
	}
	
	/**
	 * GetSettingsDefinition function
	 *
	 * Which Settings are allowed in this Module for XML Requests?
	 */
	function GetXMLDefinition()
	{
		DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
		
		if (!isset($this->_XMLDefinition)) {
			$this->_XMLDefinition = Array(
				'SaveAllowed' 	=> Array('Type' 				=> "HTML", 
																 'Name' 				=> "Save the Allowed Languages", 
																 'DivID' 				=> "UserField", 
																 'FunctionName' => "SaveAllowed")
			);
		}
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $this->_XMLDefinition;
	}
	
	/**
	 * GetObjectsDefinition function
	 *
	 * Which Objects are allowed ?
	 */
	function GetObjectsDefinition()
	{
		DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$this->_ModuleObjects = Array(
			'Draw' => Array('Type'					=> 'HTML',
											'Name'					=> 'Text',
											'FunctionName'	=> 'Draw',
											'Default'				=> TRUE)
		);
	
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $this->_ModuleObjects;
	}

	/**
	 * Draw function
	 */
	function Draw()
	{
		DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$RV = "<h2>" . Language('Allowed Languages') . "</h2><div id=\"ErrorDiv_0\"></div>";
		$RV.= $this->GetAllowedLanguages();
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}
	
	/**
	 * SaveAllowed function
	 */
	function SaveAllowed()
	{
		DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$Result = $this->DB->query("TRUNCATE TABLE `LanguageAllowed`");
				
		if ($Result) {
			$Transaction = new Transaction($this->DB, $this->Sess->UserID, TRUE);
			$Allowed = (eregi(",", $this->GetSetting('Allowed')) ? explode(",", $this->GetSetting('Allowed')) : Array($this->GetSetting('Allowed')));
			
			if (is_array($Allowed)) {
				foreach ($Allowed AS $Language) {
					$Language = str_replace(Array("FROM_", "TO_"), "", $Language);
					
					if ($Language != "") {
						$Transaction->addData('LanguageAllowed', 
																	Array('Language' => $Language));
					}
				}
			}
			
			if ($Transaction->Commit() !== FALSE) {
				$RV = Array("NoError", Language('Languages Allowed Saved'), TRUE);
			} else {
				$RV = Array("Error", Language('Languages Allowed could not be Saved'));
			}
		}
				
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return Array("ErrorDiv_0" => $this->PrePareMSG($RV, 0));
	}
	
	/**
	 * GetAllowedLanguages function
	 */
	function GetAllowedLanguages()
	{
		DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$Query = "SELECT 
								CONCAT(IF(LA.Language IS NULL, 'FROM_', 'TO_'), L.Language) AS ID, 
								L.Name 
							FROM 
								`Language` AS L
							LEFT 
							JOIN 
								`LanguageAllowed` AS LA
							ON 
								L.Language = LA.Language 
							ORDER 
							BY 
								L.Name";
		
		$Form = new Form("AllowedLanguagesForm", "/?P=" . $this->GetSetting('P'), "POST", "application/x-www-form-urlencoded");
		$Form->HideButtons();
		$Form->AddOptionString("Temp", "FROMTOSELECT/Query=".$this->NitroBODBAlias.":" . $Query . "/SIZE=30/STYLE=width: 300px;/LABEL= /FROMID=Available/FROMHEAD=" . Language('Available Languages') . "/TOID=Allowed/TOHEAD=" . Language('Allowed Languages'));
		$Form->AddOptionString("Temp2", "HTML/LABLE= /VALUE=" . urlencode("<input type='button' onclick=\"PrepareAllowedForSave(); ModuleXMLRequest('SaveAllowed', GetXMLURL('AllowedLanguagesForm')); return false;\" value='" . Language('Save') . "' />"));
		
		$Form -> SetTemplateIDs("file:" . NITRO_PATH . "Defaults/Templates/BackOffice/form.tpl", "file:" . NITRO_PATH . "Defaults/Templates/BackOffice/widget.tpl");
		
		$RV = $Form->Draw();
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}
}
?>
Return current item: OpenNitro