<?php
include '../config.php';
session_start();

if (!isset($_SESSION['username'])) {
header("Location: ../admin/index.php");
}else{
    
session_destroy();
header("Location: ../admin/index.php");
}

$employee_id = $_SESSION['employee_id'];
$now = date("Y-m-d H:i:s");

// Proper query using DATE(login_time)
$sql = "UPDATE attendance 
        SET logout_time = '$now' 
        WHERE employee_id = '$employee_id' 
        AND DATE(login_time) = CURDATE()
        ORDER BY id DESC 
        LIMIT 1";

if (!$conn->query($sql)) {
    // Optional: log or show the error
    die("Logout failed: " . $conn->error);
}

?>
