76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
|
header("Access-Control-Allow-Headers: Content-Type");
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
http_response_code(200);
|
|
exit();
|
|
}
|
|
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
$host = "192.168.0.4";
|
|
$username = "wpuser";
|
|
$password = "-2b/)ru5/Bi8P[7_";
|
|
$dbname = "DemandeConge";
|
|
|
|
$conn = new mysqli($host, $username, $password, $dbname);
|
|
if ($conn->connect_error) {
|
|
http_response_code(500);
|
|
echo json_encode(["success" => false, "message" => "Erreur de connexion à la base de données"]);
|
|
exit;
|
|
}
|
|
|
|
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
|
|
|
|
if ($user_id <= 0) {
|
|
http_response_code(400);
|
|
echo json_encode(["success" => false, "message" => "Paramètre user_id manquant ou invalide"]);
|
|
exit;
|
|
}
|
|
|
|
// Récupérer les notifications non lues ou récentes (ex: dernières 30 j)
|
|
$query = "
|
|
SELECT Id, Titre, Message, Type, DemandeCongeId, DateCreation, lu
|
|
FROM Notifications
|
|
WHERE CollaborateurADId = ?
|
|
ORDER BY DateCreation DESC
|
|
LIMIT 50
|
|
";
|
|
|
|
$stmt = $conn->prepare($query);
|
|
if (!$stmt) {
|
|
http_response_code(500);
|
|
echo json_encode(["success" => false, "message" => "Erreur préparation requête"]);
|
|
exit;
|
|
}
|
|
|
|
$stmt->bind_param('i', $user_id); // ✅ correction ici
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
$notifications = [];
|
|
while ($row = $result->fetch_assoc()) {
|
|
$notifications[] = [
|
|
"Id" => intval($row['Id']),
|
|
"Titre" => $row['Titre'],
|
|
"Message" => $row['Message'],
|
|
"Type" => $row['Type'],
|
|
"DemandeCongeId" => intval($row['DemandeCongeId']),
|
|
"DateCreation" => $row['DateCreation'],
|
|
"lu" => intval($row['lu']) === 1,
|
|
];
|
|
}
|
|
|
|
$stmt->close();
|
|
$conn->close();
|
|
|
|
echo json_encode([
|
|
"success" => true,
|
|
"notifications" => $notifications
|
|
]);
|