Location: PHPKode > projects > OpenNitro > trunk/Nitro/Modules/BackOffice/NitroBOSubModule.inc.php
<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: NitroBOSubModule                                                 |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2006 June Systems BV                                        |
// +---------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or modify it   |
// | under the terms of the GNU Lesser General Public License as published by  |
// | the Free Software Foundation; either version 2.1 of the License, or (at   |
// | your option) any later version.                                           |
// |                                                                           |
// | This library is distributed in the hope that it will be useful, but       |
// | WITHOUT ANY WARRANTY; without even the implied warranty of                |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser   |
// | General Public License for more details.                                  |
// |                                                                           |
// | You should have received a copy of the GNU Lesser General Public License  |
// | along with this library; if not, write to the Free Software Foundation,   |
// | Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA            |
// +---------------------------------------------------------------------------+
// | Authors: Siggi Oskarsson <hide@address.com>                          |
// |          Jesper Avôt     <hide@address.com>                         |
// +---------------------------------------------------------------------------+
//
// $Id: NitroBOSubModule.inc.php 229 2008-04-17 09:20:31Z oli $
//

/**
 * All NitroBO Submodules extend this class
 *
 * @package			Nitro
 * @subpackage  Modules
 * @version   	$Revision:$
 * @author			Siggi Oskarsson <hide@address.com>
 * @author			Jesper Avôt     <hide@address.com>
 * @copyright		2006 June Systems BV
 */
 
/**
 * Include required files
 */
include_once 'Nitro/NitroSettings.inc.php';
 
/**
 * Abstract class definition for NitroBO modules.
 *
 * NitroBOSubModule implements the interface for the NitroBO environement
 * All NitroBO modules should extend this class and implement the abstract functions.
 *
 * @access 			public
 * @abstract
 *
 */ 
class NitroBOSubModule extends NitroSettings {
	/**
	 * @var	int	Unique ID of object of instance of the class
	 */
	/*private*/
	var $ObjectID;

	/**
	 * @var	object the NitroBO DB Object
	 */
	/*private*/
	var $DB;
	var $_ModuleSettings;
	var $_ModuleObjects;
	var $Settings;
	var $SubModulesDir;
	var $AllowedLanguages = Array();
	var $Sess;
	var $NitroBODBAlias;

	/**
	 * Constructor: Sets $ObjectID as the class object handle (use child ID by default?)
	 *
	 * @param integer	$ObjectID
	 * return	void
	 */
	function NitroBOSubModule($ObjectID = FALSE, $Database, $Sess, $SubModulesDir)
	{
		DebugGroup(__CLASS__, __FUNCTION__, 'NitroBOSubModule', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$this->ObjectID = $ObjectID;
		$this->DB = $Database;
		$this->AllowedLanguages = Array("Default" => "Default");
		
		foreach (NitroGetAllowedLanguages($this->DB) AS $LangCode => $LangName) {
			$this->AllowedLanguages[$LangCode] = $LangName;
		}
		
		$this->Sess = $Sess;
		$this->SubModulesDir = $SubModulesDir;
		
		parent::NitroSettings();
		
		DebugCloseGroup(DEBUG_MOD_OK);
	}

	// All classes which extend this class, are obligated to overide GetSettingsDefinition
	/**
	 * Abstract: This function should return the definition of settings used by this module.
	 *
	 * Overide this function to implement the SettingsDefinition for a sub module.
	 * 
	 * param:		void
	 * @return 	Array()			SettingsDefinition Array (return by ref)
	 *
	 * @todo	 	Style definitions for GetSettingsDefinition.
 	 * @todo		Make funtion abstract when migrating to PHP5
	 *					
	 * USE:			$SettingDef = & GetSettingsDefinition()
	 * 					To get objects by reference!
	 */
	function GetSettingsDefinition()
	{
		Debug(__CLASS__, __FUNCTION__, 'GetSettingsDefinition called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		return Array();
	}

	/**
	 * Returns Array of FormVariable => ModuleVariable
	 *
	 * @return	mixed	Array of module variables per form variable or FALSE failure
	 */
	function GetSettingsDefinitionForm()
	{
		DebugGroup(__CLASS__, __FUNCTION__, 'GetSettingsDefinitionForm called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$RV = FALSE;

		if (is_array($this->_ModuleSettings)) {
			$RV = Array();
			
			foreach ($this->_ModuleSettings AS $ModuleVariable => $Vars) {
				if ( $Vars["FormVariable"] ) {
					$RV[ $Vars["FormVariable"] ] = $ModuleVariable;
				}
			}
		}
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}

	/**
	 * Returns Array of FormVariable => SessionVariable
	 *
	 * @return	mixed	Array of Session variables per form variable or FALSE failure
	 */
	function GetSettingsDefinitionSession()
	{
		DebugGroup(__CLASS__, __FUNCTION__, 'GetSettingsDefinitionSession called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$RV = FALSE;

		if (is_array($this->_ModuleSettings)) {
			$RV = Array();
			
			foreach ($this->_ModuleSettings AS $ModuleVariable => $Vars) {
				if ($Vars["SessionVariable"] && $Vars["FormVariable"]) {
					$RV[$Vars["FormVariable"]] = $Vars["SessionVariable"];
				}
			}
		}
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}

	/**
	 *
	 * Return CVS Revision for this class
	 *
	 * param:  		void
	 * @return 		integer		CVS Revision
	 */
	/*public*/ 
	function Version()
	{
		Debug(__CLASS__, __FUNCTION__, 'Version called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		return $this->_Version;
	}
	
	/**
	 * SetSession function
	 */
	function SetSession($SessionName, $SessionValue)
	{
		if (strlen($SessionName) && strlen($SessionValue)) {
			$_SESSION[$SessionName] = $SessionValue;
		}
	}
	
	/**
	 * GetSession function
	 */
	function GetSession($SessionName)
	{
		if ($_SESSION[$SessionName]) {
			return $_SESSION[$SessionName];
		}
	}
	
	/**
	 * unSetSession function
	 */
	function unSetSession($SessionName)
	{
		if ($_SESSION[$SessionName]) {
			unset($_SESSION[$SessionName]);
		}
	}
	
	/**
	 * PrePare MSG function
	**/
	function PrePareMSG($MsgArr, $ErrID = FALSE)
	{
		DebugGroup(__CLASS__, __FUNCTION__, "_PrePareMSG func.", __FILE__, __LINE__, DEBUG_MOD_OK);
		
		switch ($MsgArr[0]) {
			case "Error":
				$RV = '<span class="RedError">' . $MsgArr[1] . '</span>';
				break;
			case "NoError":
				$RV = '<span class="NoError">' . $MsgArr[1] . '</span>';
				break;
			default:
				$RV = $MsgArr[1];
				break;
		}
		
		if (isset($MsgArr[2]) && $MsgArr[2] !== FALSE) {
			$RV.= "<script type='text/javascript'>window.setTimeout(\"document.getElementById('ErrorDiv_" . $ErrID . "').innerHTML = '';\", 10000);</script>";
		}
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}
	
	/**
	 * CreateTabInterface function
	 */
	function CreateTabInterface($TabName, $TabContent, $TemplateName = "BackOffice/tabs")
	{
		DebugGroup(__CLASS__, __FUNCTION__, "CreateTabInterface func.", __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$TabInterface = new NitroTemplate(NitroGetTemplateID($TemplateName));
		$TabInterface->ClearAll();
		$TabInterface->Assign("TabName", $TabName);
		$TabInterface->Assign("TabContent", $TabContent);
		
		$RV = $TabInterface->Fetch();
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}
	
	/**
	 * GetUpdateTab
	 */
	function GetUpdateTab($TabID)
	{
		DebugGroup(__CLASS__, __FUNCTION__, "GetUpdateTab func.", __FILE__, __LINE__, DEBUG_MOD_OK);
		
		$RV = urlencode("UpdatePageTab('" . $TabID . "', 'DisplayName', '', true);");
		
		DebugCloseGroup(DEBUG_MOD_OK);
		
		return $RV;
	}
	
	/**
	 *
	 * Overide this function to implement pre processing for a sub module. 
	 *
	 * If pre processing is done return TRUE else return FALSE (default).
	 *
	 * param: 	void
	 * @return	boolean			TRUE/FALSE
	 */
	/*public*/ 
	function PreProcess()
	{
		Debug(__CLASS__, __FUNCTION__, 'PreProcess called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		return FALSE;
	}
	
	/**
	 *
	 * Abstract: Sub module functionality should be implemented here.
	 * 
	 * Overide this function to implement processing for a sub module.
	 *
	 * param: 	void
	 * @return	mixed				A valid PHP type, class or void
	 *
 	 * @todo		Make funtion abstract when migrating to PHP5
	 */
	/*public*/ 
	function Process()
	{
		Debug(__CLASS__, __FUNCTION__, 'Process called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		return FALSE;
	}
	
	/**
	 *
	 * Abstract: This function must return the definition of objects used in this module.
	 * 
	 * Overide this function to implement ObjectsDefinition for a sub module.
	 *
	 * param: 	void
	 * @return	Array() 		A module objects definition array
	 *
	 * @todo	 	Style definitions for GetObjectsDefinition.
 	 * @todo		Make funtion abstract when migrating to PHP5
	 */
	/*abstract public*/ 
	function GetObjectsDefinition()
	{
		Debug(__CLASS__, __FUNCTION__, 'GetObjectsDefinition called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		return Array();
	}
	
	/**
	 *
	 * Abstract: This function must return the definition of xml objects used in this module.
	 * 
	 * Overide this function to implement ObjectsDefinition for a sub module.
	 *
	 * param: 	void
	 * @return	Array() 		A module objects definition array
	 *
	 * @todo	 	Style definitions for GetObjectsDefinition.
 	 * @todo		Make funtion abstract when migrating to PHP5
	 */
	/*abstract public*/ 
	function GetXMLDefinition()
	{
		Debug(__CLASS__, __FUNCTION__, 'GetXMLDefinition called in prototype module, not implemented in module.', __FILE__, __LINE__, DEBUG_MOD_OK);
		
		return array();
	}
	
	/**
	 * CountSubModules
	 *
	 * Opens the SubModules directory and count's the SubModules for stats or something like that
	 */
	function CountSubModules()
	{		
		$moduleDir = $this->SubModulesDir;
		$RV = 0;
		
		if (is_dir($moduleDir)) {
			$SubModules = Array();
			
			if ($dh = @opendir($moduleDir)) {
				while (($file = readdir($dh)) !== false) {
					if ($file != '..' && $file != '.' && !ereg("^\..*", $file) && is_dir($moduleDir . '/' . $file)) {
						$RV++;
					}
				}
				
				closedir($dh);
			}
		}
		
		return $RV;
	}
	
	function ValidateSettings()
	{
		$definition = $this->GetSettingsDefinition();
		$Errors = FALSE;
		
		if (is_array($definition)) {
			foreach($definition AS $id => $settings) {
				if (strlen($settings['Validate']) && ($check = NitroValidate($this->GetSetting($id), $settings['Validate'])) !== TRUE) {
					if ($Errors === FALSE) $Errors = Array();
					$Errors[$id] = $check;
				}
			}
		}
		
		return $Errors;
	}
}
?>
Return current item: OpenNitro