<?php
require_once (PATH_TABLES . "activity/JobCentreTable.php") ;
require_once (PATH_TABLES . "activity/JobCentreResourcesTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class JobCentreResourcesClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= JobCentreResourcesTable::C_TABLE ;
		$this->fldid2 	= JobCentreResourcesTable::C_ID ;
        $this->fldid   = JobCentreResourcesTable::C_RESOURCE_ID ;
	}

	function __destruct() {
	}

	function getJobCenterResource($id){
        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        
        return null;
    }

    function deleteRecordByJobId($jobId) {
    	$sql = "DELETE FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $jobId;
        
        $this->db->executeSql($sql);
    }

    function getAccManagerList($id){
    	$userCls       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::AccountManager;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $accManager = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$accManager .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$accManager .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['accManager'] = $accManager;
            return $data;
        }
        
        return null;
    }

    function getProjManagerList($id){
    	$userCls       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::ProjectManager;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $ProjManager = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$ProjManager .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$ProjManager .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['ProjManager'] = $ProjManager;
            return $data;
        }
        
        return null;
    }

    function getTechConsultantList($id){
    	$userCls       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::TechnicalConsultant;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $TechConsultant = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$TechConsultant .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$TechConsultant .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['TechConsultant'] = $TechConsultant;
            return $data;
        }

        return null;
    }

    function getAppConsultantList($id){
    	$userCls       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::ApplicationConsultant;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $AppConsultant = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$AppConsultant .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$AppConsultant .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['AppConsultant'] = $AppConsultant;
            return $data;
        }
        
        return null;
    }

    function getDeveloperList($id){
    	$userCls       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::Developer;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $dev = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$dev .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$dev .= $userCls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['Developer'] = $dev;
            return $data;
        }
        
        return null;
    }

    function getCustProjSponsorList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectSponsor;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $CustProjSponsor = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$CustProjSponsor .= $cls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME] . "<br>";
            	} else {
            		$CustProjSponsor .= $cls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME];
            	}
            }

            $data['CustProjSponsor'] = $CustProjSponsor;
            return $data;
        }
        
        return null;
    }

    function getCustProjAdvisorList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectAdvisor;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $CustProjAdvisor = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$CustProjAdvisor .= $cls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME] . "<br>";
            	} else {
            		$CustProjAdvisor .= $cls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME];
            	}
            }

            $data['CustProjAdvisor'] = $CustProjAdvisor;
            return $data;
        }
        
        return null;
    }

    function getCustProjManagerList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectManager;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $CustProjManager = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$CustProjManager .= $cls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME] . "<br>";
            	} else {
            		$CustProjManager .= $cls->getRecord($row[JobCentreResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME];
            	}
            }

            $data['CustProjManager'] = $CustProjManager;
            return $data;
        }
        
        return null;
    }

    function getCustProjMemberList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobCentreResourcesTable::C_TABLE . " WHERE " . JobCentreResourcesTable::C_ID . " = " . $id;
        $sql .= " AND " . JobCentreResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectMember;
        $sql .= " ORDER BY " . JobCentreResourcesTable::C_RESOURCE_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        
        return null;
    }
}
?>