<?php
require_once (PATH_CONTROLLERS . "Common.php") ;


class PortalMilestone extends ActivityBase {

	function __construct() {
		$this->db 		= $_SESSION[SE_DB] ;
        $this->dbsun    = $_SESSION[SE_DB_SUN];
		//$this->fldid 	= MilestoneTable::C_ID ;
		$this->orgid 	= $_SESSION[SE_ORGID] ;
	}
	
	function __destruct() {
		unset($this->db) ;
	}
	
	public function processRequest($params) {
		$this->type = REQ_VIEW ;
		try {
			$this->db->open() ;
            $this->dbsun->open() ;
			$this->loadSetting() ;
			if (isset($params) && count($params) > 0) {
				if (isset($params['type']))
					$this->type = $params['type'] ;
			}
			switch ($this->type) {
                case Command::PortalMilestone:
                    $this->processMilestoneInfo() ;
                    break ;
                case Command::PortalMilestoneFilter:
                    $this->processMilestoneFilter($params);
					break;
				case Command::PortalMilestoneAddView:
					$this->processViewMilestoneAdd();
					break;
                case Command::PortalMilestoneUpdateView:
                    $this->processViewMilestoneUpdate($params);
                    break;
             
                case REQ_UPDATE:
                    $this->updateRecord($params) ;
					break ;
				case REQ_ADD:
					$this->addRecord($params) ;
					break ;
					case REQ_DELETE:
					$this->processPlanDelete($params);
					break;
              
                //========================================
				default:
					$this->sendJsonResponse(Status::Error,"invalid request.","",$this->type) ;
					break ;
			}
			$this->db->close() ;
            $this->dbsun->close() ;
			return true ;
		} catch (Exception $e) {
			$this->db->close() ;
			$this->dbsun->close() ;
			die ($e->getMessage()) ;
		}
	}

    private function processMilestoneInfo() {
        ob_start() ;
 
        include (PATH_VIEWS . "portal/milestone/MilestoneInfoView.php") ;
        $dataReturn = array();
        $dataReturn['htmlContent']  =  Util::minifyHtml(ob_get_clean()) ;
        $dataReturn['headTitle']    =  "My Milestone" ;
        $this->sendJsonResponse(Status::Ok,"Load Home Info",$dataReturn,$this->type);
	}
	
	private function processViewMilestoneAdd() {
        ob_start() ;
        
        include (PATH_VIEWS . "portal/milestone/MilestoneAddView.php") ;
        $addHeaderContent= array() ;
        $addHeaderContent["all"] =  Util::minifyHtml(ob_get_clean()) ;
        
        $this->sendJsonResponse(Status::Ok,"Milestone Add Content",$addHeaderContent,$this->type);
    }
}
?>