<?php
require_once (PATH_CONTROLLERS . "Common.php") ;
require_once (PATH_LIB . "LicenseFile.php") ;
/*require_once (PATH_MODELS . "request/RequestHeaderClass.php");
require_once (PATH_MODELS . "request/RequestHeaderMsgClass.php");
require_once (PATH_MODELS . "request/RequestApprovalGroupClass.php");
require_once (PATH_MODELS . "request/RequestFlowHistoryClass.php");
require_once (PATH_MODELS . "request/InvoiceHeaderClass.php");*/
require_once (PATH_MODELS . "admin/UserClass.php");
/*require_once (PATH_MODELS . "content/ContentClass.php") ;
require_once (PATH_MODELS . "content/ContentCategoryClass.php") ;*/


class MobileHome extends ActivityBase {
	private $clsemp ;
	private $clspwd;
    private $user;
	function __construct() {
		$this->db 		= $_SESSION[SE_DB] ;
		$this->orgid 	= $_SESSION[SE_ORGID] ;
        $this->user = new UserClass($this->db);
	}
	function __destruct() {
        unset($this->user);
		unset($this->db) ;
	}
	public function processRequest($params) {
		// log::write(print_r($params,true));
		$this->type = REQ_VIEW ;
		try {
			$this->db->open() ;
			$this->loadSetting() ;
			if (isset($params) && count($params) > 0) {
				if (isset($params['type']))
					$this->type = $params['type'] ;
			}
			switch ($this->type) {
				case Command::MobileHome:
 					$this->processHomeInfo() ;
					break ;
				case Command::MobileLogout:
					$this->processLogout() ;
					break ;
				case REQ_VIEW:
					$this->processView() ;
					break ;
				/*case Command::PortalInvoiceManagerFilter:
					$this->processInvoiceManagerInfo() ; // for manager only
					break ;*/
				/*case Command::PortalInvoiceApprovalLog:
					$this->processInvoiceApprovalLog($params) ; // for manager only
					break ;*/
				/*case Command::PortalRequestManagerFilter:
					$this->processRequestManagerInfo() ; // for manager only
					break ;*/
				/*case Command::PortalRequestApprovalLog:
					$this->processRequestApprovalLog($params) ; // for manager only
					break ;*/
				case Command::changePwd:
					$this->processChangePwd($params);
					break ;
           /*     case Command::PortalRequestUpdateLanguage:
                    $this->updateLanguage($params);
                    break;*/
				default:
					$this->sendJsonResponse(Status::Error,"invalid request.","",$this->type) ;
					break ;
			}
			$this->db->close() ;
			return true ;
		} catch (Exception $e) {
			$this->db->close() ;
			die ($e->getMessage()) ;
		}
	}
	
	private function processLogout() {
		session_unset();
		$this->sendJsonResponse(Status::Ok,"","",$this->type) ;
	}
	
	private function processView() {
		ob_start() ;
        
		include (PATH_VIEWS . "mobile/MobileHomeView.php") ;
		echo Util::minifyHtml(ob_get_clean()) ;
	}
	private function processHomeInfo() {
		$dataReturn = array();
		$dataReturn['htmlContent']	= $this->getHomeInfo() ;
		$dataReturn['headTitle']	=  "My Dashboard" ;
		
		$this->sendJsonResponse(Status::Ok,"Load Home",$dataReturn,$this->type);
	}
	private function createMenuFunc($href,$desc,$type) {
		return "javascript:showPage('" . Util::convertLink($href) . "','". $desc . "'". ",'" . "$type" . "');" ;
	}
	
    private function getCompanyName() {
		$clsUser  = new UserClass($this->db);
		$clsCoy   = new CompanyClass($this->db) ;
		
		$coyid 	= $clsUser->getRecord($_SESSION[SE_USERID])[UserTable::C_COY_ID];		
		$coy   = $clsCoy->getRecord($coyid) ;
		
		return trim($coy[CompanyTable::C_DESC]) ;
	}
	
    private function getCompanyLogo() {
		$clsUser  = new UserClass($this->db);
		$coyid 	= $clsUser->getRecord($_SESSION[SE_USERID])[UserTable::C_COY_ID];

		$fn = Util::getLogoFile(PATH_PICTURE, "company-".$coyid) ;
		if ($fn == "")
			return "" ;
		else 
			return "..\web\picture\company-" . $coyid . "/" . $fn ;
	}
}
?>