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

$num_errors = 0;

$katalaluan_baru = fetch_postget_val("pengguna_pwd", $_POST, $_GET);
$newpwd = fetch_postget_val("newpwd", $_POST, $_GET);
$dateTimeNow = dateTimeNow();

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();
	
	//*****************************************
	//GET id_pengguna
	//*****************************************
	$pengguna_Array = array();
	$pengguna_Array[] = array('katalaluan', sha1($newpwd), PDO::PARAM_STR,1);
	$pengguna_Array[] = array('temp_pwd', 0, PDO::PARAM_INT);
	$pengguna_Array[] = array('masaakhirtukar', $dateTimeNow, PDO::PARAM_STR);
	$pengguna_Array[] = array('id_kemaskini', $my_details->usr_id, PDO::PARAM_STR);
	$pengguna_Array[] = array('tkh_kemaskini', $dateTimeNow, PDO::PARAM_STR);
	
	$whereCondition = "WHERE id_pengguna = ".$my_details->usr_id;
	$PASS_COUNTER += PDO_UPDATE($PDO, 't_pengguna', $pengguna_Array, $whereCondition);
	//*****************************************
	//COMMIT if PASS_COUNTER == PASS_VALUE
	//*****************************************
	if ($PASS_COUNTER == $PASS_VALUE)
	{
		$PDO->commit();
		echo $PASS_COUNTER;
	}
	else
	{
		$PDO->rollBack();
	}
	
}
catch (Exception $e) 
{
	$PDO->rollBack();
	echo "Failed: " . $e->getMessage();
}
?>