first commit
This commit is contained in:
33
backend/ride/notificationPassenger/add.php
Executable file
33
backend/ride/notificationPassenger/add.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$title = filterRequest("title");
|
||||
$body = filterRequest("body");
|
||||
$passengerID = filterRequest("passenger_id");
|
||||
|
||||
// SQL الآمن باستخدام placeholders
|
||||
$sql = "INSERT INTO `notifications` (
|
||||
`title`,
|
||||
`body`,
|
||||
`passenger_id`
|
||||
) VALUES (
|
||||
:title,
|
||||
:body,
|
||||
:passengerID
|
||||
)";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([
|
||||
':title' => $title,
|
||||
':body' => $body,
|
||||
':passengerID' => $passengerID
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Notification data saved successfully");
|
||||
} else {
|
||||
jsonError("Failed to save notification data");
|
||||
}
|
||||
|
||||
?>
|
||||
0
backend/ride/notificationPassenger/delete.php
Normal file
0
backend/ride/notificationPassenger/delete.php
Normal file
0
backend/ride/notificationPassenger/error_log
Normal file
0
backend/ride/notificationPassenger/error_log
Normal file
33
backend/ride/notificationPassenger/get.php
Executable file
33
backend/ride/notificationPassenger/get.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
$passenger_id = filterRequest("passenger_id");
|
||||
|
||||
$sql = "SELECT
|
||||
`id`,
|
||||
`title`,
|
||||
`body`,
|
||||
`passenger_id`,
|
||||
`isShown`,
|
||||
`created_at`,
|
||||
`updated_at`
|
||||
FROM
|
||||
`notifications`
|
||||
WHERE
|
||||
`passenger_id` = :passenger_id
|
||||
AND `created_at` >= CURDATE() - INTERVAL 7 DAY
|
||||
ORDER BY `created_at` DESC
|
||||
LIMIT 10";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':passenger_id', $passenger_id, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$notifications = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($notifications) {
|
||||
jsonSuccess($notifications);
|
||||
} else {
|
||||
jsonSuccess([], "No notification data found");
|
||||
}
|
||||
|
||||
?>
|
||||
42
backend/ride/notificationPassenger/update.php
Normal file
42
backend/ride/notificationPassenger/update.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
$fields = [];
|
||||
$params = [':id' => $id];
|
||||
|
||||
$mapping = [
|
||||
"title" => "title",
|
||||
"body" => "body",
|
||||
"passengerID" => "passenger_id",
|
||||
"isShown" => "isShown",
|
||||
"updatedAt" => "updated_at"
|
||||
];
|
||||
|
||||
// تجهيز الـ SET والأرقام المقابلة
|
||||
foreach ($mapping as $requestKey => $dbColumn) {
|
||||
if (isset($_POST[$requestKey])) {
|
||||
$value = filterRequest($requestKey);
|
||||
$fields[] = "`$dbColumn` = :$requestKey";
|
||||
$params[":$requestKey"] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($fields)) {
|
||||
jsonError("No fields to update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$setClause = implode(", ", $fields);
|
||||
$sql = "UPDATE `notifications` SET $setClause WHERE `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Notification data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update notification data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user