<?php
require_once (PATH_CONTROLLERS . "Common.php") ;
require_once (PATH_LIB    . 'ImageResize.php');
require_once (PATH_MODELS . "admin/UserClass.php");

class PortalJobSchedule extends ActivityBase {

	function __construct() {
		$this->db 		= $_SESSION[SE_DB] ;
        $this->dbsun    = $_SESSION[SE_DB_SUN];
		// $this->fldid 	= TaskScheduleTable::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::PortalJobSchedule:
                    $this->processJobScheduleView() ;
                    break ;
                case Command::PortalJobScheduleFilter:
                    $this->processJobScheduleFilter($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 processJobScheduleView() {
        ob_start() ;
        include (PATH_VIEWS . "portal/JobScheduleView.php") ;
        $dataReturn = array();
        $dataReturn['htmlContent']  =  Util::minifyHtml(ob_get_clean()) ;
        $dataReturn['headTitle']    =  "My Job Schedule" ;
        $this->sendJsonResponse(Status::Ok,"Load Home Info",$dataReturn,$this->type);
    }

    private function processJobScheduleFilter($params) {

        // $cls         = new TaskPlanClass($this->db);
        // $rows        = $cls->getTaskPlanList($params['status']);
        
        $htmlStr     = "<thead>" .
                            "<tr>" .
                                "<th width='10%'>Job Number</th>" .
                                "<th width='10%'>Assign ID</th>" .
                                "<th width='10%'>Assign Date</th>" .
                                "<th width='10%'>Assign Start Time</th>" .
                                "<th width='20%'>Job Description</th>" .
                                "<th width='10%'>Phone</th>" .
                                "<th width='10%'>Allocate(Day/Hours)</th>" .
                                "<th width='10%'>&nbsp</th>" .
                            "</tr>" .
                        "</thead> <tbody> <tr></tr>";


        // if(!is_null($rows) || count($rows) > 0){

        //     foreach ($rows as $row) {

                $btnStr  = "<button title=\"Print Preview\" onclick=\"\" id=\"btnPrintPreview\" class=\"btn btn-default glyphicon glyphicon-print btn-sm\"></button>";
                $btnStr  .= "<button  title=\"View\" onclick=\"\" id=\"btnEdit\" data-toggle=\"modal\" class=\"btn btn-primary glyphicon glyphicon-edit btn-sm\"></button>"; 
                $btnStr  .= "<button title=\"Delete\" onclick=\"\" id=\"btnDelete\" data-toggle=\"modal\" class=\"btn btn-danger glyphicon glyphicon-trash btn-sm\"></button>";

            
        //        $htmlStr .= "<tr  id=\"plan-rows-" . $row[TaskPlanTable::C_ID] . "\">" .
        //                         "<td style='display:none'>" . $row[TaskPlanTable::C_ID] . "</td>" . 
        //                         "<td>" . $row[TaskPlanTable::C_DESC] . "</td>" .
        //                         "<td>" . $this->getScheduleType($row[TaskPlanTable::C_SCHEDULE_TYPE]) . "</td>" .
        //                         "<td>" . date_create($row[TaskPlanTable::C_START_TIME])->format('d/m/Y') . "</td>" .
        //                         "<td>" . date_create($row[TaskPlanTable::C_END_TIME])->format('d/m/Y') . "</td>" .
        //                         "<td>" . date_create($row[TaskPlanTable::C_START_TIME])->format('h:i A') . "</td>" .
        //                         "<td><div>" . $btnStr . "</div></td>".
        //                     "</tr>";
        //     }
            
        // }
        $htmlStr    .=  "<tr>" .
                            "<td><a href=''>DAIZ00401</a></td>" .
                            "<td><a href=''>A-VIN200401</a></td>" .
                            "<td>01/04/2020</td>" .
                            "<td>09:00</td>" .
                            "<td>This is the job description</td>" .
                            "<td>08123849201</td>" .
                            "<td>2 hours</td>" .
                            "<td>" . $btnStr ."</td>" .
                        "</tr>" .
                        "<tr>" .
                            "<td><a href=''>DAIZ00402</a></td>" .
                            "<td><a href=''>A-VIN200402</a></td>" .
                            "<td>01/04/2020</td>" .
                            "<td>12:00</td>" .
                            "<td>This is the job description 2</td>" .
                            "<td>08123849201</td>" .
                            "<td>5 hours</td>" .
                            "<td>" . $btnStr ."</td>" .
                        "</tr>";
        
        $htmlStr .="</tbody>";
        
        $this->sendJsonResponse(Status::Ok,"",$htmlStr,$this->type);

        // unset($cls);
        
    }

    private function getUserOption(){
        $vls = $this->getValueList(UserTable::C_TABLE, UserTable::C_ID, UserTable::C_NAME,null) ;
        return Util::createOptionValue($vls) ;
    }

}
?>