<?php
class OrganizationOptions {
	const C_CONTACT 	= "contact";
	const C_CONT_NAME1 	= "name1";
	const C_CONT_NAME2 	= "name2";
	const C_CONT_ADDR1	= "address1";
	const C_CONT_ADDR2 	= "address2";
	const C_CONT_ADDR3 	= "address3";
	const C_CONT_ADDR4 	= "address4" ;
	const C_CONT_ADDR5 	= "address5" ;
	const C_CONT_TEL 	= "telno" ;
	const C_CONT_FAX 	= "faxno" ;
	const C_CONT_EMAIL 	= "email";
	const C_CONT_WEB 	= "website";
	
	const C_SETTING 		= "setting" ;
	const C_SET_FAIL_COUNT 	= "failcount";
	const C_SET_REF_NO 	 	= "refno";
	const C_SET_LIC   	 	= "license" ;
	const C_EMAIL_SERVER 	= "email_server" ;
	const C_EMAIL_PORT      = "email_port" ;
	const C_EMAIL_USER 	 	= "email_user" ;
	const C_EMAIL_PWD 	 	= "email_pwd" ;
	const C_EMAIL_ENABLE_AUTHENTICATION = "email_enable_authentication";
	const C_EMAIL_SSL = "email_ssl";
	const C_UPLOAD_SIZE_LIMT = "upload_size_limit";
	const C_BASE_CURRENCY = "base_currency";
	const C_CLAIM_DAY_LAST = "claim_day_last";
	const C_EMP_CODE_TO_EXPORT = "emp_code_to_export";
    
    const C_ALLOW_DELETE_MASTER = "allow_deletion_master";
	const C_USE_PAYMENT_REFERENCE = "use_payment_reference";
	
	const C_USE_BU = "use_bu";

	const C_START_TIME = "start_time";
	const C_END_TIME = "end_time";

	const C_USE_REMINDER = "use_reminder";
	const C_REMINDER_MESSAGE1 = "reminder_message1";
	const C_REMINDER_MESSAGE2 = "reminder_message2";
	const C_REMINDER_MESSAGE3 = "reminder_message3";
	const C_REMINDER_MESSAGE4 = "reminder_message4";
	const C_REMINDER_INTERVAL = "reminder_interval";
	const C_REMINDER_INTERVAL_UNIT = "reminder_interval_unit";

	const C_REMINDER_INTERVAL_APPROVAL = "reminder_interval_approval";
	const C_REMINDER_INTERVAL_APPROVAL_UNIT = "reminder_interval_approval_unit";
	
	private $opt = array() ;
	
	function __construct() {
		$this->initOptions() ;
	}
	function __destruct() {
	}
	function getOption() {
		return $this->opt ;
	}
	function setOption($value) {
		$this->opt = $value ;
	}
	function loadXml($xml) {

		$xr = simplexml_load_string($xml);
		if ($xr) {
			$op = array() ;
			$op[self::C_CONT_NAME1] = (string) $xr->contact->{self::C_CONT_NAME1} ;
			$op[self::C_CONT_NAME2] = (string) $xr->contact->{self::C_CONT_NAME2} ;
			$op[self::C_CONT_ADDR1] = (string) $xr->contact->{self::C_CONT_ADDR1} ;
			$op[self::C_CONT_ADDR2] = (string) $xr->contact->{self::C_CONT_ADDR2} ;
			$op[self::C_CONT_ADDR3] = (string) $xr->contact->{self::C_CONT_ADDR3} ;
			$op[self::C_CONT_ADDR4] = (string) $xr->contact->{self::C_CONT_ADDR4} ;
			$op[self::C_CONT_ADDR5] = (string) $xr->contact->{self::C_CONT_ADDR5} ;
			$op[self::C_CONT_TEL] 	= (string) $xr->contact->{self::C_CONT_TEL} ;
			$op[self::C_CONT_FAX] 	= (string) $xr->contact->{self::C_CONT_FAX} ;
			$op[self::C_CONT_EMAIL] = (string) $xr->contact->{self::C_CONT_EMAIL} ;
			$op[self::C_CONT_WEB] 	= (string) $xr->contact->{self::C_CONT_WEB} ;
			$this->opt[self::C_CONTACT] = $op;
			
			$op = array();
			$op[self::C_SET_FAIL_COUNT] 					= (string) $xr->setting->{self::C_SET_FAIL_COUNT} ;
			$op[self::C_SET_REF_NO] 						= (string) $xr->setting->{self::C_SET_REF_NO} ;
			$op[self::C_SET_LIC] 							= (string) $xr->setting->{self::C_SET_LIC} ;
			$op[self::C_EMAIL_SERVER] 						= (string) $xr->setting->{self::C_EMAIL_SERVER} ;
			$op[self::C_EMAIL_PORT] 						= (string) $xr->setting->{self::C_EMAIL_PORT} ;
			$op[self::C_EMAIL_USER] 						= (string) $xr->setting->{self::C_EMAIL_USER} ;
			$op[self::C_EMAIL_PWD] 							= (string) $xr->setting->{self::C_EMAIL_PWD} ;
			$op[self::C_EMAIL_ENABLE_AUTHENTICATION] 		= (string) $xr->setting->{self::C_EMAIL_ENABLE_AUTHENTICATION} ;
			$op[self::C_EMAIL_SSL]                          = (string) $xr->setting->{self::C_EMAIL_SSL} ;
			$op[self::C_UPLOAD_SIZE_LIMT] 					= (string) $xr->setting->{self::C_UPLOAD_SIZE_LIMT} ;
			$op[self::C_BASE_CURRENCY]                      = (string) $xr->setting->{self::C_BASE_CURRENCY} ;
			$op[self::C_CLAIM_DAY_LAST] 					= (string) $xr->setting->{self::C_CLAIM_DAY_LAST} ;
			$op[self::C_ALLOW_DELETE_MASTER] 				= (string) $xr->setting->{self::C_ALLOW_DELETE_MASTER} ;
			$op[self::C_EMP_CODE_TO_EXPORT] 				= (string) $xr->setting->{self::C_EMP_CODE_TO_EXPORT} ;
			$op[self::C_USE_PAYMENT_REFERENCE] 				= (string) $xr->setting->{self::C_USE_PAYMENT_REFERENCE} ;
			$op[self::C_USE_BU] 							= (string) $xr->setting->{self::C_USE_BU} ;
			$op[self::C_START_TIME] 						= (string) $xr->setting->{self::C_START_TIME} ;
			$op[self::C_END_TIME] 							= (string) $xr->setting->{self::C_END_TIME} ;
			
			$op[self::C_USE_REMINDER] 					= (string) $xr->setting->{self::C_USE_REMINDER} ;
			$op[self::C_REMINDER_MESSAGE1] 					= (string) $xr->setting->{self::C_REMINDER_MESSAGE1} ;
			$op[self::C_REMINDER_MESSAGE2] 					= (string) $xr->setting->{self::C_REMINDER_MESSAGE2} ;
			$op[self::C_REMINDER_MESSAGE3] 					= (string) $xr->setting->{self::C_REMINDER_MESSAGE3} ;
			$op[self::C_REMINDER_MESSAGE4] 					= (string) $xr->setting->{self::C_REMINDER_MESSAGE4} ;
			$op[self::C_REMINDER_INTERVAL] 					= (string) $xr->setting->{self::C_REMINDER_INTERVAL} ;
			$op[self::C_REMINDER_INTERVAL_UNIT] 					= (string) $xr->setting->{self::C_REMINDER_INTERVAL_UNIT} ;

			$op[self::C_REMINDER_INTERVAL_APPROVAL] 					= (string) $xr->setting->{self::C_REMINDER_INTERVAL_APPROVAL} ;
			$op[self::C_REMINDER_INTERVAL_APPROVAL_UNIT] 					= (string) $xr->setting->{self::C_REMINDER_INTERVAL_APPROVAL_UNIT} ;
			
			$this->opt[self::C_SETTING] = $op ;
			
		}
		unset($xr) ;
	}
	function getXml() {
		$xml = '<?xml version="1.0" encoding="utf-8"?>';
		$xml .= '<configuration>' ;
		
		$xml .= '<' . self::C_CONTACT . '>';
		$xml .= $this->createXmlElement(self::C_CONT_NAME1,$this->opt[self::C_CONTACT][self::C_CONT_NAME1]);
		$xml .= $this->createXmlElement(self::C_CONT_NAME2,$this->opt[self::C_CONTACT][self::C_CONT_NAME2]) ;
		$xml .= $this->createXmlElement(self::C_CONT_ADDR1,$this->opt[self::C_CONTACT][self::C_CONT_ADDR1]) ;
		$xml .= $this->createXmlElement(self::C_CONT_ADDR2,$this->opt[self::C_CONTACT][self::C_CONT_ADDR2]) ;
		$xml .= $this->createXmlElement(self::C_CONT_ADDR3,$this->opt[self::C_CONTACT][self::C_CONT_ADDR3]) ;
		$xml .= $this->createXmlElement(self::C_CONT_ADDR4,$this->opt[self::C_CONTACT][self::C_CONT_ADDR4]) ;
		$xml .= $this->createXmlElement(self::C_CONT_ADDR5,$this->opt[self::C_CONTACT][self::C_CONT_ADDR5]) ;
		$xml .= $this->createXmlElement(self::C_CONT_TEL,$this->opt[self::C_CONTACT][self::C_CONT_TEL]);
		$xml .= $this->createXmlElement(self::C_CONT_FAX,$this->opt[self::C_CONTACT][self::C_CONT_FAX]);
		$xml .= $this->createXmlElement(self::C_CONT_EMAIL,$this->opt[self::C_CONTACT][self::C_CONT_EMAIL]);
		$xml .= $this->createXmlElement(self::C_CONT_WEB,$this->opt[self::C_CONTACT][self::C_CONT_WEB]);
		$xml .= '</' . self::C_CONTACT . '>';
		
		$xml .= '<' . self::C_SETTING . '>';
		$xml .= $this->createXmlElement(self::C_SET_FAIL_COUNT,$this->opt[self::C_SETTING][self::C_SET_FAIL_COUNT]) ;
		$xml .= $this->createXmlElement(self::C_SET_REF_NO,$this->opt[self::C_SETTING][self::C_SET_REF_NO]) ;
		$xml .= $this->createXmlElement(self::C_SET_LIC,$this->opt[self::C_SETTING][self::C_SET_LIC]) ;
		$xml .= $this->createXmlElement(self::C_EMAIL_SERVER,$this->opt[self::C_SETTING][self::C_EMAIL_SERVER]) ;
		$xml .= $this->createXmlElement(self::C_EMAIL_PORT,$this->opt[self::C_SETTING][self::C_EMAIL_PORT]) ;
		$xml .= $this->createXmlElement(self::C_EMAIL_USER,$this->opt[self::C_SETTING][self::C_EMAIL_USER]) ;
		$xml .= $this->createXmlElement(self::C_EMAIL_PWD,$this->opt[self::C_SETTING][self::C_EMAIL_PWD]) ;
		$xml .= $this->createXmlElement(self::C_EMAIL_ENABLE_AUTHENTICATION,$this->opt[self::C_SETTING][self::C_EMAIL_ENABLE_AUTHENTICATION]) ;
		$xml .= $this->createXmlElement(self::C_EMAIL_SSL,$this->opt[self::C_SETTING][self::C_EMAIL_SSL]) ;
		$xml .= $this->createXmlElement(self::C_UPLOAD_SIZE_LIMT,$this->opt[self::C_SETTING][self::C_UPLOAD_SIZE_LIMT]) ;
		$xml .= $this->createXmlElement(self::C_BASE_CURRENCY,$this->opt[self::C_SETTING][self::C_BASE_CURRENCY]) ;
		$xml .= $this->createXmlElement(self::C_CLAIM_DAY_LAST,$this->opt[self::C_SETTING][self::C_CLAIM_DAY_LAST]) ;
		$xml .= $this->createXmlElement(self::C_ALLOW_DELETE_MASTER,$this->opt[self::C_SETTING][self::C_ALLOW_DELETE_MASTER]) ;
		$xml .= $this->createXmlElement(self::C_EMP_CODE_TO_EXPORT,$this->opt[self::C_SETTING][self::C_EMP_CODE_TO_EXPORT]) ;
		$xml .= $this->createXmlElement(self::C_USE_PAYMENT_REFERENCE,$this->opt[self::C_SETTING][self::C_USE_PAYMENT_REFERENCE]) ;
		$xml .= $this->createXmlElement(self::C_USE_BU,$this->opt[self::C_SETTING][self::C_USE_BU]) ;
		$xml .= $this->createXmlElement(self::C_START_TIME,$this->opt[self::C_SETTING][self::C_START_TIME]) ;
		$xml .= $this->createXmlElement(self::C_END_TIME,$this->opt[self::C_SETTING][self::C_END_TIME]) ;

		$xml .= $this->createXmlElement(self::C_USE_REMINDER,$this->opt[self::C_SETTING][self::C_USE_REMINDER]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_MESSAGE1,$this->opt[self::C_SETTING][self::C_REMINDER_MESSAGE1]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_MESSAGE2,$this->opt[self::C_SETTING][self::C_REMINDER_MESSAGE2]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_MESSAGE3,$this->opt[self::C_SETTING][self::C_REMINDER_MESSAGE3]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_MESSAGE4,$this->opt[self::C_SETTING][self::C_REMINDER_MESSAGE4]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_INTERVAL,$this->opt[self::C_SETTING][self::C_REMINDER_INTERVAL]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_INTERVAL_UNIT,$this->opt[self::C_SETTING][self::C_REMINDER_INTERVAL_UNIT]) ;

		$xml .= $this->createXmlElement(self::C_REMINDER_INTERVAL_APPROVAL,$this->opt[self::C_SETTING][self::C_REMINDER_INTERVAL_APPROVAL]) ;
		$xml .= $this->createXmlElement(self::C_REMINDER_INTERVAL_APPROVAL_UNIT,$this->opt[self::C_SETTING][self::C_REMINDER_INTERVAL_APPROVAL_UNIT]) ;
		
		$xml .= '</' . self::C_SETTING . '>';
		
		$xml .= '</configuration>';
		return $xml ;
	}
	private function createXmlElement($tag,$value) {
		return '<' . $tag . '>' . $value . '</' . $tag . '>' ;
	}
	function initOptions() {
		$op = array() ;
		$op[self::C_CONT_NAME1] = "" ;
		$op[self::C_CONT_NAME2] = "" ;
		$op[self::C_CONT_ADDR1] = "" ;
		$op[self::C_CONT_ADDR2] = "" ;
		$op[self::C_CONT_ADDR3] = "" ;
		$op[self::C_CONT_ADDR4] = "" ;
		$op[self::C_CONT_ADDR5] = "" ;
		$op[self::C_CONT_TEL] 	= "" ;
		$op[self::C_CONT_FAX] 	= "" ;
		$op[self::C_CONT_EMAIL] = "" ;
		$op[self::C_CONT_WEB] 	= "" ;
		$this->opt[self::C_CONTACT] = $op ; 
		
		$op = array();
		$op[self::C_SET_FAIL_COUNT]                     = 3 ;
		$op[self::C_SET_REF_NO]                         = "" ;
		$op[self::C_SET_LIC]                            = "" ;
		$op[self::C_EMAIL_SERVER]                       = "" ;
		$op[self::C_EMAIL_PORT]                         = "25" ;
		$op[self::C_EMAIL_USER]                         = "" ;
		$op[self::C_EMAIL_PWD]                          = "" ;
		$op[self::C_EMAIL_ENABLE_AUTHENTICATION] 		= "1" ;
		$op[self::C_EMAIL_SSL]                          = "1" ;
		$op[self::C_UPLOAD_SIZE_LIMT]                   = "5000" ;
		$op[self::C_BASE_CURRENCY]                      = "" ;
		$op[self::C_CLAIM_DAY_LAST]                     = "30" ;
		$op[self::C_ALLOW_DELETE_MASTER]                = "0" ;
		$op[self::C_EMP_CODE_TO_EXPORT]                 = "0" ;
		$op[self::C_USE_PAYMENT_REFERENCE]              = "0" ;
		$op[self::C_USE_BU]              				= "0" ;
		$op[self::C_START_TIME]              			= "06:00" ;
		$op[self::C_END_TIME]              				= "18:00" ;

		$op[self::C_USE_REMINDER]              			= "1" ;
		$op[self::C_REMINDER_MESSAGE1]              	= "" ;
		$op[self::C_REMINDER_MESSAGE2]              	= "" ;
		$op[self::C_REMINDER_MESSAGE3]              	= "" ;
		$op[self::C_REMINDER_MESSAGE4]              	= "" ;
		$op[self::C_REMINDER_INTERVAL]              	= "1" ;
		$op[self::C_REMINDER_INTERVAL_UNIT]              	= "1" ;

		$op[self::C_REMINDER_INTERVAL_APPROVAL]              	= "1" ;
		$op[self::C_REMINDER_INTERVAL_APPROVAL_UNIT]              	= "1" ;
		
		$this->opt[self::C_SETTING] = $op ;
		
	}
}
?>