<?php
require_once (PATH_TABLES . "activity/ProjectTable.php") ;
require_once (PATH_MODELS . "activity/ProjectPhaseClass.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class ProjectClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= ProjectTable::C_TABLE ;
		$this->fldid 	= ProjectTable::C_ID ;
		$this->flddesc 	= ProjectTable::C_TITLE ;
		$this->fldorg 	= ProjectTable::C_ORG_ID ;
	}
	function __destruct() {
	}


    function isUsed($id) {
 
        //return ""; 
        if($this->isAllowDeleteMaster())
            return parent::isUsed ($id);
        
        /* claim header */
        $sql  = "SELECT * FROM " . ProjectPhaseTable::C_TABLE;
        $sql .= " WHERE " . ProjectPhaseTable::C_PROJECT_ID. " = " . $id;
        $rows = $this->db->getTable($sql);
        
        if(!is_null($rows) && count($rows) > 0)
            return "project phase";
        
        return parent::isUsed($id);
    }
    
    function getProjectList($titlefilter = '', $customerFilter = 0, $statusFilter = 'all'){
        $sql = "SELECT * FROM " . ProjectTable::C_TABLE . " ";
        $filter = "WHERE " . ProjectTable::C_TITLE . " like '%" . $titlefilter . "%' ";
        
        if($customerFilter != 0){
            if($filter != "") $filter .= "AND ";
            else $filter .= "WHERE ";
            
            $filter .= " " . ProjectTable::C_CUSTOMER_ID . " = " . $customerFilter . " ";
        }
        if($statusFilter != 'all'){
            if($filter != "") $filter .= "AND ";
            else $filter .= "WHERE ";
            
            if($statusFilter == 'active')
                $filter .= " " . ProjectTable::C_STATUS . " = 1 ";
            else if($statusFilter == 'non-active')
                $filter .= " " . ProjectTable::C_STATUS . " = 0 ";
        }
        
        $rows = $this->db->getTable($sql . $filter);
        
        return $rows;
    }
}
?>