<?php

include_once ("includes/setup_pemohon.inc.php");
Header("Cache-Control: no-cache");

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

$indicator_Query = "SELECT t_pemohon.*
				  FROM t_pemohon
				  WHERE emel = ? 
				  AND id_pemohon != ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, fetch_postget_val("emel", $_POST, $_GET), PDO::PARAM_STR);
$PDO_stmt->bindValue(2, $id, PDO::PARAM_STR);
$PDO_stmt->execute();
$indicator_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

if($indicator_List['id_pemohon'] > 0)
{
	//echo -888;
	//exit(0);
}
	
try
{
	$PASS_COUNTER = 0; //COUNTER FOR DOUBLE CONFIRM
	$PASS_VALUE = 1; //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('nama', fetch_postget_val("nama", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('emel', fetch_postget_val("emel", $_POST, $_GET), PDO::PARAM_STR,1);
	$indicator_Array[] = array('no_tel', fetch_postget_val("no_tel", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('id_soalanrahsia', fetch_postget_val("id_soalanrahsia", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('jawapan_rahsia', fetch_postget_val("jawapan_rahsia", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('id_kemaskini', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_kemaskini', $dateTimeNow, PDO::PARAM_STR);
	$whereCondition = "WHERE id_pemohon = $id";
	$PASS_COUNTER += PDO_UPDATE($PDO, 't_pemohon', $indicator_Array, $whereCondition);


	//*****************************************
	//COMMIT if PASS_COUNTER == PASS_VALUE
	//*****************************************
	if ($PASS_COUNTER == $PASS_VALUE)
	{
		$PDO->commit();
		echo $PASS_COUNTER;
		
		$my_details->fullname = fetch_postget_val("nama", $_POST, $_GET);
		$my_details->email = fetch_postget_val("email", $_POST, $_GET);		
	}
	else
	{
		$PDO->rollBack();
		echo -1;
	}
}
catch (Exception $e) 
{
	$PDO->rollBack();
	echo "Failed: " . $e->getMessage();
}

?>