Reapply "V1_Sans_Congé_Anticipéfemini collaboratrice"
This reverts commit 7f15e380e3.
This commit is contained in:
62
project/public/php/markNotificationRead.php
Normal file
62
project/public/php/markNotificationRead.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// Autoriser CORS
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Affichage erreurs PHP (utile pour debug)
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Connexion base de données
|
||||
$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;
|
||||
}
|
||||
|
||||
// Récupération données JSON POST
|
||||
$postData = json_decode(file_get_contents("php://input"), true);
|
||||
if (!isset($postData['notificationId'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["success" => false, "message" => "Paramètre notificationId manquant"]);
|
||||
exit;
|
||||
}
|
||||
$notificationId = intval($postData['notificationId']);
|
||||
if ($notificationId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["success" => false, "message" => "ID notification invalide"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Mettre à jour notification lu = 1
|
||||
$query = "UPDATE Notifications SET lu = 1 WHERE Id = ?";
|
||||
$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", $notificationId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["success" => true, "message" => "Notification marquée comme lue"]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(["success" => false, "message" => "Erreur lors de la mise à jour"]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
Reference in New Issue
Block a user