<?php
session_start();
require 'config/db.php';

if(!isset($_SESSION['manager_id'])) header("Location: login.php");

$manager_id = $_SESSION['manager_id'];
$manager_table = "manager2_attendance";
$today = date('Y-m-d');

// Check if already marked
$stmt = $pdo->prepare("SELECT * FROM $manager_table WHERE manager_id=? AND att_date=?");
$stmt->execute([$manager_id,$today]);
if($stmt->rowCount()==0){
    $pdo->prepare("INSERT INTO $manager_table (manager_id, att_date, status) VALUES (?,?,?)")
        ->execute([$manager_id, $today, 'Present']); // Default: Present
}

header("Location: dashboard.php");
