<?php
	session_start();
	date_default_timezone_set('Africa/Mogadishu');
	include("library/conn.php");
	
	$getLoginID = mysqli_query($conn, "SELECT MAX(loginID) FROM user_logins WHERE userID = '". @$_SESSION['userIdd'] ."'");
	$loginDetails = mysqli_fetch_array($getLoginID);
	$loginID = $loginDetails[0];
	$logoutDate = date("Y-m-d H:i:s");
	$check_user_type = $_SESSION['userTypeID'];

	
    mysqli_query($conn, "UPDATE last_visited_page SET visitedPageURL = 'https://africandaafi.hirgal.so/dashboard', visitedDate = '". date("Y-m-d H:i:s") ."' WHERE userID = '". @$_SESSION['userIdd'] ."'") or die(mysqli_error($conn));
    // mysqli_query($conn, "UPDATE last_visited_page SET visitedPageURL = '/african/dashboard', visitedDate = '". date("Y-m-d H:i:s") ."' WHERE userID = '". @$_SESSION['userIdd'] ."'") or die(mysqli_error($conn));
	mysqli_query($conn, "UPDATE user_logins SET logoutDateTime = '". $logoutDate ."' WHERE loginID = ". $loginID ." AND userID = '". @$_SESSION['userIdd'] ."'");
	mysqli_query($conn, "UPDATE system_users SET loginStatus = '0' WHERE userID = '" . @$_SESSION["userIdd"] . "'") or die(mysqli_error($conn));

    unset($_SESSION["userIdd"]);
	unset($_SESSION["userName"]);
	unset($_SESSION["fullName"]);
	unset($_SESSION["departmentName"]);
	unset($_SESSION["userTypeID"]);
	unset($_SESSION["userType"]);
	unset($_SESSION["userPhone"]);
	unset($_SESSION["userEmail"]);
	unset($_SESSION["userPhoto"]);

	if ($check_user_type == 'PS0008') {
		?><script>location = "./"</script><?php
	} else {
		?><script>location = "admin"</script><?php
	}
	
?>