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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $user_id  = $_POST['user_id'];
    $log_time = $_POST['log_time'];
    $status   = $_POST['status'];
    $remarks  = $_POST['remarks'];

    $stmt = $conn->prepare("INSERT INTO attendance (user_id, log_time, status, remarks, created_at, updated_at) 
                            VALUES (?, ?, ?, ?, NOW(), NOW())");
    $stmt->bind_param("ssss", $user_id, $log_time, $status, $remarks);
    $stmt->execute();

    header("Location: attendance.php?month=" . date('Y-m', strtotime($log_time)));
    exit();
}
