<?php
require_once (PATH_TABLES . "activity/ChecklistHeaderTable.php") ;
require_once (PATH_TABLES . "activity/ChecklistDetailTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class ChecklistHeaderClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= ChecklistHeaderTable::C_TABLE ;
		$this->fldid 	= ChecklistHeaderTable::C_ID ;
	}
	function __destruct() {
	}

	function getChecklistRecord($id){
		$sql = "SELECT H.*, D.* ". 
				" FROM " . ChecklistHeaderTable::C_TABLE . " H " .
				" LEFT OUTER JOIN " . ChecklistDetailTable::C_TABLE . " D " .
				" ON (D." . ChecklistDetailTable::C_HEADER_ID." = H.".ChecklistHeaderTable::C_ID . ") " .
                " WHERE H." . ChecklistHeaderTable::C_ID . " = " . $id . " " .
                " ORDER BY D." . ChecklistDetailTable::C_ORDER . " ";
        
        $result = null;
        try{
            $result = $this->db->getTable($sql);
        } catch (Exception $e){
            Log::write("[ChecklistDetailClass]" . $e->getMessage());
        }
        
        return $result;
        
	}

	function getInChecklistRecord($id){
		
		if(is_null($id) && count($id)==0)
			return null;

        $result = null;
        try{
			
				$sql = "SELECT *". 
				" FROM " . ChecklistHeaderTable::C_TABLE . " " .
				" WHERE " . ChecklistHeaderTable::C_ID . " IN (" . $id . ") " ;

				$result = $this->db->getTable($sql);
			
            
        } catch (Exception $e){
            Log::write("[ChecklistDetailClass]" . $e->getMessage());
        }
        
        return $result;
        
	}

	function getAllChecklist(){
		$sql = "SELECT * ". 
				" FROM " . ChecklistHeaderTable::C_TABLE . "  " ;
				
        try{
			$result = $this->db->getTable($sql);
			
			if(!is_null($result) && count($result)>0){
				return $result;
			}else{
				return null;
			}
			
        } catch (Exception $e){
            Log::write("[ChecklistDetailClass]" . $e->getMessage());
        }
        
        
	}
}
?>