<?php
class eventclass_qa_maintenance_inspection  extends TableEventsBase {
	
	function init() {
		$this->events = array(
	'AfterAdd' => true 
);
		$this->fieldValues = array(
	'filterLimit' => array(
		 
	),
	'mapIcon' => array(
		 
	),
	'viewCustom' => array(
		 
	),
	'lookupWhere' => array(
		 
	),
	'viewFileText' => array(
		 
	),
	'defaultValue' => array(
		'inspection_date' => array(
			'edit' => true 
		),
		'inspected_date_signed' => array(
			'edit' => true 
		),
		'concurred_date_signed' => array(
			'edit' => true 
		) 
	),
	'autoUpdateValue' => array(
		 
	),
	'uploadFolder' => array(
		 
	),
	'viewPluginInit' => array(
		 
	),
	'editPluginInit' => array(
		 
	) 
);
			}
		function AfterAdd( &$values, &$keys, $inline, $pageObject ) {
		// Get selected checklist setup

$rs = DB::Query("
SELECT checklist_setup_id
FROM qa_maintenance_inspection
WHERE id=".$keys["id"]."
");


if($rs)
{
    $row = $rs->fetchAssoc();


    if($row && $row["checklist_setup_id"])
    {


        $items = DB::Query("
            SELECT id
            FROM qa_maintenance_checklist_item
            WHERE checklist_setup_id=".$row["checklist_setup_id"]."
            ORDER BY line_no
        ");


        while($item = $items->fetchAssoc())
        {


            DB::Insert(
                "qa_maintenance_checklist_result",
                array(
                    "qa_maintenance_inspection_id"=>$keys["id"],
                    "checklist_id"=>$item["id"],
                    "checked_flag"=>0
                )
            );


        }

    }

}
		;
		
	}
	public function default_inspection_date_efedit(  ) {
	$defaultValue = now();
return $defaultValue;
}

public function default_inspected_date_signed_efedit(  ) {
	$defaultValue = now();
return $defaultValue;
}

public function default_concurred_date_signed_efedit(  ) {
	$defaultValue = now();
return $defaultValue;
}	

}


?>