prepare("SELECT id FROM attendance WHERE employee_id = ? AND date = ?");
$stmt->execute([$employee_id, $current_date]);
$attendance_record = $stmt->fetch();
if ($attendance_record) {
$stmt = db()->prepare("UPDATE attendance SET check_in_time = ?, status = 'Present' WHERE id = ?");
$stmt->execute([$current_time, $attendance_record['id']]);
} else {
$stmt = db()->prepare("INSERT INTO attendance (employee_id, date, status, check_in_time) VALUES (?, ?, 'Present', ?)");
$stmt->execute([$employee_id, $current_date, $current_time]);
}
} elseif ($action === 'check-out') {
$stmt = db()->prepare("UPDATE attendance SET check_out_time = ? WHERE employee_id = ? AND date = ?");
$stmt->execute([$current_time, $employee_id, $current_date]);
}
header('Location: mark_attendance.php');
exit();
}
// Only allow Admin and HR to access this page
if (!isset($_SESSION['user_role']) || ($_SESSION['user_role'] !== 'Admin' && $_SESSION['user_role'] !== 'HR')) {
header('Location: index.php');
exit();
}
$pdo = db();
$today = date('Y-m-d');
// Fetch all employees (users)
$stmt = $pdo->prepare('SELECT id, username, role FROM users ORDER BY username');
$stmt->execute();
$employees = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
Mark Attendance
| Employee Name |
Role |
Actions |
|
|
|