Initial commit with updated Auth and media ignored
This commit is contained in:
31
ride/promo/add.php
Executable file
31
ride/promo/add.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$promoCode = filterRequest("promoCode");
|
||||
$amount = filterRequest("amount");
|
||||
$description = filterRequest("description");
|
||||
$passengerID = filterRequest("passengerID"); // يفترض أنه ID وليس قيمة مشفرة
|
||||
|
||||
$sql = "INSERT INTO `promos`(
|
||||
`promo_code`, `amount`, `description`, `passengerID`,
|
||||
`validity_start_date`, `validity_end_date`
|
||||
)
|
||||
VALUES (
|
||||
:promoCode, :amount, :description, :passengerID,
|
||||
NOW(), DATE_ADD(NOW(), INTERVAL 1 WEEK)
|
||||
)";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindValue(':promoCode', $promoCode);
|
||||
$stmt->bindValue(':amount', $amount);
|
||||
$stmt->bindValue(':description', $description);
|
||||
$stmt->bindValue(':passengerID', $passengerID);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Promo data saved successfully");
|
||||
} else {
|
||||
jsonError("Failed to save promo data");
|
||||
}
|
||||
?>
|
||||
16
ride/promo/delete.php
Normal file
16
ride/promo/delete.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
$sql = "DELETE FROM `promos` WHERE `id` = :id";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT); // استخدام bindParam لحماية الاستعلام
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Promo data deleted successfully");
|
||||
} else {
|
||||
jsonError("Failed to delete promo data");
|
||||
}
|
||||
?>
|
||||
29
ride/promo/get.php
Normal file
29
ride/promo/get.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$promo_code = filterRequest("promo_code");
|
||||
|
||||
$sql = "SELECT
|
||||
`id`,
|
||||
`promo_code`,
|
||||
`amount`,
|
||||
`description`,
|
||||
`validity_start_date`,
|
||||
`validity_end_date`
|
||||
FROM
|
||||
`promos`
|
||||
WHERE
|
||||
`promo_code` = :promo_code
|
||||
AND CURDATE() BETWEEN validity_start_date AND validity_end_date";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':promo_code', $promo_code, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result) {
|
||||
jsonSuccess($result);
|
||||
} else {
|
||||
jsonError("Failed to retrieve promo records");
|
||||
}
|
||||
?>
|
||||
27
ride/promo/getPromoBytody.php
Executable file
27
ride/promo/getPromoBytody.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
|
||||
$passengerID = filterRequest("passengerID");
|
||||
|
||||
$sql = "SELECT
|
||||
`id`, `promo_code`, `amount`, `description`, `passengerID`, `validity_start_date`,
|
||||
DATEDIFF(promos.validity_end_date, CURDATE()) AS validity_end_date
|
||||
FROM
|
||||
`promos`
|
||||
WHERE
|
||||
(passengerID = '$passengerID' OR passengerID LIKE '%all%')
|
||||
AND promos.validity_start_date <= CURDATE()
|
||||
AND promos.validity_end_date >= CURDATE();";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result) {
|
||||
jsonSuccess($result);
|
||||
} else {
|
||||
// Print an empty list
|
||||
jsonSuccess([]);
|
||||
}
|
||||
?>
|
||||
31
ride/promo/getPromoFirst.php
Executable file
31
ride/promo/getPromoFirst.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// Get passengerID and encrypt it only if هو رقم مشفر (إذا لزم الأمر)
|
||||
// $passengerID = $encryptionHelper->encryptData(filterRequest("passengerID"));
|
||||
$passengerID = filterRequest("passengerID"); // استخدم هذا إذا ID رقم فقط
|
||||
|
||||
$sql = "SELECT
|
||||
`id`,
|
||||
`promo_code`,
|
||||
`amount`,
|
||||
`description`,
|
||||
`validity_start_date`,
|
||||
`validity_end_date`
|
||||
FROM
|
||||
`promos`
|
||||
WHERE
|
||||
`passengerID` = ? AND CURDATE() BETWEEN validity_start_date AND validity_end_date";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(1, $passengerID);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result) {
|
||||
jsonSuccess($result);
|
||||
} else {
|
||||
jsonError("Failed to retrieve promo records");
|
||||
}
|
||||
?>
|
||||
31
ride/promo/update.php
Normal file
31
ride/promo/update.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
$promoCode = filterRequest("promoCode");
|
||||
$description = filterRequest("description");
|
||||
$validityStartDate = filterRequest("validityStartDate");
|
||||
$validityEndDate = filterRequest("validityEndDate");
|
||||
|
||||
$sql = "UPDATE `promos` SET
|
||||
`promo_code` = :promoCode,
|
||||
`description` = :description,
|
||||
`validity_start_date` = :validityStartDate,
|
||||
`validity_end_date` = :validityEndDate
|
||||
WHERE `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':promoCode', $promoCode);
|
||||
stmt->bindParam(':description', $description);
|
||||
stmt->bindParam(':validityStartDate', $validityStartDate);
|
||||
$stmt->bindParam(':validityEndDate', $validityEndDate);
|
||||
stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Promo data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update promo data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user