admin 20
This commit is contained in:
@@ -3,16 +3,21 @@ require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$country = filterRequest("country");
|
||||
|
||||
$sql = "SELECT * FROM `kazan` WHERE `country` = :country";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':country', $country, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
if (!empty($country)) {
|
||||
$sql = "SELECT * FROM `kazan` WHERE `country` = :country";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':country', $country, PDO::PARAM_STR);
|
||||
} else {
|
||||
$sql = "SELECT * FROM `kazan` ORDER BY id DESC";
|
||||
$stmt = $con->prepare($sql);
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($row) {
|
||||
jsonSuccess($row);
|
||||
} else {
|
||||
jsonError("No Kazan record found");
|
||||
jsonSuccess([], "No Kazan record found");
|
||||
}
|
||||
?>
|
||||
@@ -5,7 +5,7 @@ $id = filterRequest("id");
|
||||
|
||||
$allowedFields = [
|
||||
"kazan", "comfortPrice", "speedPrice", "deliveryPrice",
|
||||
"freePrice", "latePrice", "heavyPrice", "adminId", "createdAt", "naturePrice"
|
||||
"freePrice", "latePrice", "heavyPrice", "adminId", "naturePrice", "fuelPrice", "familyPrice"
|
||||
];
|
||||
|
||||
$setParts = [];
|
||||
@@ -33,6 +33,7 @@ $stmt->execute($params);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Kazan data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update kazan data");
|
||||
// If no rows were changed but execute was successful, it might be because the data is the same
|
||||
jsonSuccess(null, "Kazan data remains unchanged or updated");
|
||||
}
|
||||
?>
|
||||
@@ -1,29 +1,32 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$promoCode = filterRequest("promoCode");
|
||||
$promo_code = filterRequest("promo_code");
|
||||
$amount = filterRequest("amount");
|
||||
$description = filterRequest("description");
|
||||
$passengerID = filterRequest("passengerID"); // يفترض أنه ID وليس قيمة مشفرة
|
||||
$passengerID = filterRequest("passengerID");
|
||||
|
||||
if (empty($promo_code)) {
|
||||
jsonError("Promo code is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$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)
|
||||
:promo_code, :amount, :description, :passengerID,
|
||||
NOW(), DATE_ADD(NOW(), INTERVAL 1 MONTH)
|
||||
)";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindValue(':promoCode', $promoCode);
|
||||
$stmt->bindValue(':promo_code', $promo_code);
|
||||
$stmt->bindValue(':amount', $amount);
|
||||
$stmt->bindValue(':description', $description);
|
||||
$stmt->bindValue(':passengerID', $passengerID);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
if ($stmt->execute()) {
|
||||
jsonSuccess(null, "Promo data saved successfully");
|
||||
} else {
|
||||
jsonError("Failed to save promo data");
|
||||
|
||||
@@ -3,27 +3,28 @@ 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";
|
||||
if (!empty($promo_code)) {
|
||||
$sql = "SELECT `id`, `promo_code`, `amount`, `description`, `passengerID`, `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);
|
||||
} else {
|
||||
$sql = "SELECT `id`, `promo_code`, `amount`, `description`, `passengerID`, `validity_start_date`, `validity_end_date` FROM `promos` ORDER BY id DESC";
|
||||
$stmt = $con->prepare($sql);
|
||||
}
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':promo_code', $promo_code, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result) {
|
||||
if ($result || (empty($promo_code) && is_array($result))) {
|
||||
jsonSuccess($result);
|
||||
} else {
|
||||
jsonError("Failed to retrieve promo records");
|
||||
if (!empty($promo_code)) {
|
||||
jsonError("Promo code not found or expired");
|
||||
} else {
|
||||
jsonSuccess([], "No promos found");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -2,30 +2,39 @@
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
$promoCode = filterRequest("promoCode");
|
||||
$description = filterRequest("description");
|
||||
$validityStartDate = filterRequest("validityStartDate");
|
||||
$validityEndDate = filterRequest("validityEndDate");
|
||||
if (empty($id)) {
|
||||
jsonError("ID is required for update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE `promos` SET
|
||||
`promo_code` = :promoCode,
|
||||
`description` = :description,
|
||||
`validity_start_date` = :validityStartDate,
|
||||
`validity_end_date` = :validityEndDate
|
||||
WHERE `id` = :id";
|
||||
$allowedFields = [
|
||||
"promo_code", "amount", "description", "passengerID",
|
||||
"validity_start_date", "validity_end_date"
|
||||
];
|
||||
|
||||
$setParts = [];
|
||||
$params = [];
|
||||
|
||||
foreach ($allowedFields as $field) {
|
||||
if (isset($_POST[$field])) {
|
||||
$value = filterRequest($field);
|
||||
$setParts[] = "`$field` = :$field";
|
||||
$params[":$field"] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($setParts)) {
|
||||
jsonError("No valid fields to update.");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE `promos` SET " . implode(", ", $setParts) . " WHERE `id` = :id";
|
||||
$params[":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");
|
||||
if ($stmt->execute($params)) {
|
||||
jsonSuccess(null, "Promo updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update promo data");
|
||||
jsonError("Failed to update promo");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user