-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_task_details.php
42 lines (37 loc) · 1.22 KB
/
fetch_task_details.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
<?php
include('koneksi.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$date = $_POST['date'];
$user = $_POST['user'];
$query = "SELECT id, laporan, img_dir, status, TIME_FORMAT(waktu, '%H:%i') as jam
FROM laporan
WHERE DATE_FORMAT(waktu, '%Y-%m-%d') = ? AND nama = ?
ORDER BY waktu ASC";
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $date, $user);
$stmt->execute();
$result = $stmt->get_result();
$tasks = [];
while ($row = $result->fetch_assoc()) {
$statusText = $row['status'] === '0' ? 'Diterima' : 'Belum Diterima';
$tasks[] = [
'id' => $row['id'],
'laporan' => $row['laporan'],
'img_dir' => 'data:image/jpeg;base64,' . base64_encode($row['img_dir']),
'status' => $statusText,
'jam' => $row['jam']
];
}
if (!empty($tasks)) {
echo json_encode([
'success' => true,
'tasks' => $tasks
]);
} else {
echo json_encode(['success' => false, 'pesan' => 'Data ga ketemu bro']);
}
$stmt->close();
$conn->close();
} else {
echo json_encode(['success' => false, 'pesan' => 'Metode request salah nih']);
}