-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_attendance.php
58 lines (48 loc) · 1.81 KB
/
fetch_attendance.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
session_start();
require('koneksi.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['name'])) {
$name = $_POST['name'];
$month = isset($_POST['month']) ? $_POST['month'] : null;
$attendanceQuery = "
SELECT
DATE(waktu) as tanggal,
COUNT(CASE WHEN waktu IS NOT NULL THEN 1 END) as status
FROM images
WHERE user = ?
";
$params = array($name);
if ($month) {
$attendanceQuery .= " AND DATE_FORMAT(waktu, '%Y-%m') = ?";
$params[] = $month;
}
$attendanceQuery .= "
GROUP BY DATE(waktu)
HAVING COUNT(*) >= 2
ORDER BY tanggal
";
$attendanceStmt = $conn->prepare($attendanceQuery);
$attendanceStmt->bind_param(str_repeat('s', count($params)), ...$params);
$attendanceStmt->execute();
$attendanceResult = $attendanceStmt->get_result();
$output = '<table>';
$output .= '<thead>';
$output .= '<tr>';
$output .= '<th>Tanggal</th>';
$output .= '<th>Status</th>';
$output .= '<th>Detail Absen</th>';
$output .= '</tr>';
$output .= '</thead>';
$output .= '<tbody>';
while ($attendanceRow = $attendanceResult->fetch_assoc()) {
$output .= '<tr>';
$output .= '<td>' . htmlspecialchars($attendanceRow['tanggal']) . '</td>';
$output .= '<td>' . ($attendanceRow['status'] == 1 ? 'Hadir' : 'Hadir') . '</td>';
$output .= '<td><a href="#" class="view-details" data-name="' . htmlspecialchars($name) . '" data-date="' . htmlspecialchars($attendanceRow['tanggal']) . '" onclick="showAttendanceDetails(\'' . htmlspecialchars($name) . '\', \'' . htmlspecialchars($attendanceRow['tanggal']) . '\')">View Details</a></td>';
$output .= '</tr>';
}
$output .= '</tbody>';
$output .= '</table>';
echo $output;
exit();
}