-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapprove_tasks.php
47 lines (39 loc) · 1.17 KB
/
approve_tasks.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
<?php
session_start();
require('koneksi.php');
require('auth.php');
// Check if user is admin
if (!isset($_SESSION['role']) || ($_SESSION['role'] !== '2' && $_SESSION['role'] !== '4')) {
http_response_code(403);
echo json_encode(['success' => false, 'message' => 'Unauthorized']);
exit();
}
// Get POST data
$data = json_decode(file_get_contents('php://input'), true);
$nama = $data['nama'];
$bulan = $data['bulan'];
$tahun = $data['tahun'];
$comment = $data['comment'];
try {
// Start transaction
$conn->begin_transaction();
// Update semua tugas yang pending di bulan tersebut
$sql = "UPDATE laporan
SET status = 1,
comment = ?
WHERE nama = ?
AND MONTH(waktu) = ?
AND YEAR(waktu) = ?
AND status = 0";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssii", $comment, $nama, $bulan, $tahun);
$stmt->execute();
// Commit transaction
$conn->commit();
echo json_encode(['success' => true]);
} catch (Exception $e) {
// Rollback jika ada error
$conn->rollback();
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
$conn->close();