prepare( "SELECT * FROM laporan_masyarakat WHERE id=?" ); $stmt->execute([(int)$_GET['id']]); $data = $stmt->fetch(); if (!$data) { jsonResponse([ 'error' => 'Laporan tidak ditemukan' ], 404); } jsonResponse($data); } $stmt = $db->query( "SELECT * FROM laporan_masyarakat ORDER BY created_at DESC" ); jsonResponse($stmt->fetchAll()); break; case 'POST': $body = getRequestBody(); $stmt = $db->prepare( "INSERT INTO laporan_masyarakat ( nama_pelapor, no_hp, nama_warga, alamat, latitude, longitude, keterangan, status ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ); $stmt->execute([ $body['nama_pelapor'] ?? '', $body['no_hp'] ?? '', $body['nama_warga'] ?? '', $body['alamat'] ?? '', $body['latitude'] ?? null, $body['longitude'] ?? null, $body['keterangan'] ?? '', 'Menunggu Verifikasi' ]); jsonResponse([ 'message' => 'Laporan berhasil dikirim' ], 201); break; case 'PUT': if (empty($_GET['id'])) { jsonResponse([ 'error' => 'id wajib' ], 400); } $body = getRequestBody(); $stmt = $db->prepare( "UPDATE laporan_masyarakat SET status=? WHERE id=?" ); $stmt->execute([ $body['status'], (int)$_GET['id'] ]); jsonResponse([ 'message' => 'Status laporan diperbarui' ]); break; case 'DELETE': if (empty($_GET['id'])) { jsonResponse([ 'error' => 'id wajib' ], 400); } $stmt = $db->prepare( "DELETE FROM laporan_masyarakat WHERE id=?" ); $stmt->execute([ (int)$_GET['id'] ]); jsonResponse([ 'message' => 'Laporan dihapus' ]); break; default: jsonResponse([ 'error' => 'Method not allowed' ], 405); }