add files

This commit is contained in:
luthfihadinugroho79
2026-06-10 19:42:59 +07:00
parent 7bf3c98e59
commit e950468760
3541 changed files with 0 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
// api/notifikasi.php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
require_once '../includes/config.php';
requireLogin();
startSession();
$uid = (int)$_SESSION['user_id'];
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$only_unread = isset($_GET['unread']) ? "AND is_read=0" : "";
$res = $conn->query("SELECT * FROM notifikasi WHERE id_user=$uid $only_unread ORDER BY created_at DESC LIMIT 50");
$data = [];
while ($r = $res->fetch_assoc()) $data[] = $r;
$unread = $conn->query("SELECT COUNT(*) c FROM notifikasi WHERE id_user=$uid AND is_read=0")->fetch_assoc()['c'];
jsonResponse(['notifikasi'=>$data,'unread'=>(int)$unread]);
}
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
$d = json_decode(file_get_contents('php://input'), true);
$id = (int)($d['id']??0);
if ($id) {
$conn->query("UPDATE notifikasi SET is_read=1 WHERE id=$id AND id_user=$uid");
} else {
$conn->query("UPDATE notifikasi SET is_read=1 WHERE id_user=$uid");
}
jsonResponse(['success'=>true]);
}
?>