<?php

	include_once ("includes/setup.inc.php");
	$dateTimeNow = dateTimeNow();
	
	if($my_details->usr_id > 0)
	{
		try
		{
			$PDO->beginTransaction();
		
			$PASS_VALUE_SETUP = 2;
			$pengguna_Array = array();
			$pengguna_Array[] = array('masaakhirlogout', $dateTimeNow, PDO::PARAM_STR);
			$whereCondition = "WHERE id_pengguna = ".$my_details->usr_id;
			$PASS_COUNTER_SETUP += PDO_UPDATE($PDO, $MY_TB_NAME, $pengguna_Array, $whereCondition);
			
			$loginLog_Array = array();
			$loginLog_Array[] = array('id_pengguna', $my_details->usr_id, PDO::PARAM_INT);
			$loginLog_Array[] = array('id_peranan', $my_details->user_level, PDO::PARAM_INT);
			$loginLog_Array[] = array('status_login', 'B', PDO::PARAM_STR);
			$loginLog_Array[] = array('jenis_log', 'O', PDO::PARAM_STR);
			$loginLog_Array[] = array('bil_percubaan', 0, PDO::PARAM_INT);
			$loginLog_Array[] = array('tkh_log', $dateTimeNow, PDO::PARAM_STR);
			$loginLog_Array[] = array('ip_address', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
			
			$PASS_COUNTER_SETUP += PDO_INSERT($PDO, 's_loginlog', $loginLog_Array);
		
			//*****************************************
			//COMMIT if PASS_COUNTER_SETUP == PASS_VALUE_SETUP
			//*****************************************
			if ($PASS_COUNTER_SETUP == $PASS_VALUE_SETUP)
			{
				$PDO->commit();
			}
			else
			{
				$PDO->rollBack();
			}
		}
		catch (Exception $e) 
		{
			$PDO->rollBack();
			echo "Failed: " . $e->getMessage();
		}
	}
	
	$auth->kill_session();
	session_destroy();
	Header("location: login.php");
?>