<?php

include_once ("includes/setup.inc.php");
//Header("Content-type: application/xml");
Header("Cache-Control: no-cache");

$num_errors = 0;
$id = fetch_postget_val("id", $_POST, $_GET);
$dateTimeNow = dateTimeNow();

try
{
	$PASS_COUNTER = 0; //COUNTER FOR DOUBLE CONFIRM
	$PASS_VALUE = 2; //NUMBER OF QUERY TO EXECUTE. IMPORTANT FOR CHECKING!!

	//PDO INIT
	$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$PDO->beginTransaction();

	$indicator_Array = array();
	$indicator_Array[] = array('id_status_appointment', 2, PDO::PARAM_INT);
	$whereCondition = "WHERE id_vatklinik_appointment = $id";
	$PASS_COUNTER += PDO_UPDATE($PDO, 'm_vatklinik_appointment', $indicator_Array, $whereCondition);
	
	$indicator_Array[] = array('id_vatklinik_appointment', $id, PDO::PARAM_INT);
	$indicator_Array[] = array('insert_by', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
	
	$PASS_COUNTER += PDO_INSERT($PDO, 's_appointment_status_log', $indicator_Array);

	//*****************************************
	//COMMIT if PASS_COUNTER == PASS_VALUE
	//*****************************************
	if ($PASS_COUNTER == $PASS_VALUE)
	{
		$PDO->commit();
		echo $PASS_COUNTER;
	}
	else
	{
		$PDO->rollBack();
		echo -1;
	}
}
catch (Exception $e) 
{
	$PDO->rollBack();
	echo "Failed: " . $e->getMessage();
}

?>