Initial commit with updated Auth and media ignored
This commit is contained in:
52
Admin/passenger/admin_delete_and_blacklist_passenger.php
Executable file
52
Admin/passenger/admin_delete_and_blacklist_passenger.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
function normalize_phone($s) { return preg_replace('/\D+/', '', (string)$s); }
|
||||
|
||||
$id = filterRequest("id"); // أو
|
||||
$phone = filterRequest("phone"); // أحدهما مطلوب
|
||||
$reason= filterRequest("reason"); // اختياري
|
||||
$exp = filterRequest("expires_at"); // اختياري Y-m-d H:i:s
|
||||
|
||||
if (empty($id) && empty($phone)) { jsonError("Provide id or phone"); exit; }
|
||||
|
||||
try {
|
||||
$con->beginTransaction();
|
||||
|
||||
// احضر السجل
|
||||
if (!empty($id)) {
|
||||
$sel = $con->prepare("SELECT id, phone FROM passengers WHERE id = :id LIMIT 1");
|
||||
$sel->execute(['id' => $id]);
|
||||
} else {
|
||||
$sel = $con->prepare("SELECT id, phone FROM passengers WHERE phone = :ph LIMIT 1");
|
||||
$sel->execute(['ph' => $phone]);
|
||||
}
|
||||
$p = $sel->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$p) { throw new Exception("Passenger not found"); }
|
||||
|
||||
$phRaw = $p['phone'];
|
||||
$phNorm= normalize_phone($phRaw);
|
||||
|
||||
// أدخِل/حدّث في البلاك ليست
|
||||
$ins = $con->prepare("
|
||||
INSERT INTO passenger_blacklist (phone, phone_normalized, reason, expires_at)
|
||||
VALUES (:ph, :phn, :r, :exp)
|
||||
ON DUPLICATE KEY UPDATE reason = VALUES(reason), expires_at = VALUES(expires_at)
|
||||
");
|
||||
$ins->execute([
|
||||
'ph' => $phRaw,
|
||||
'phn' => $phNorm,
|
||||
'r' => $reason ?: 'Deleted & blacklisted',
|
||||
'exp' => $exp ?: null
|
||||
]);
|
||||
|
||||
// حذف فعلي
|
||||
$del = $con->prepare("DELETE FROM passengers WHERE id = :id");
|
||||
$del->execute(['id' => $p['id']]);
|
||||
|
||||
$con->commit();
|
||||
jsonSuccess(null, "Passenger deleted and blacklisted");
|
||||
} catch (Throwable $e) {
|
||||
$con->rollBack();
|
||||
jsonError("Failed: ".$e->getMessage());
|
||||
}
|
||||
14
Admin/passenger/admin_unblacklist.php
Executable file
14
Admin/passenger/admin_unblacklist.php
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
function normalize_phone($s) { return preg_replace('/\D+/', '', (string)$s); }
|
||||
|
||||
$phone = filterRequest("phone");
|
||||
if (empty($phone)) { jsonError("phone is required"); exit; }
|
||||
|
||||
$phn = normalize_phone($phone);
|
||||
$stmt = $con->prepare("DELETE FROM passenger_blacklist WHERE phone_normalized = :phn");
|
||||
$stmt->execute(['phn' => $phn]);
|
||||
|
||||
if ($stmt->rowCount() > 0) { jsonSuccess(null, "Removed from blacklist"); }
|
||||
else { jsonError("Phone was not blacklisted"); }
|
||||
50
Admin/passenger/admin_update_passenger.php
Executable file
50
Admin/passenger/admin_update_passenger.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
|
||||
|
||||
$id = filterRequest("id"); // مفضّل
|
||||
|
||||
$first_name = filterRequest("first_name");
|
||||
$last_name = filterRequest("last_name");
|
||||
$new_phone = filterRequest("phone");
|
||||
|
||||
if (empty($id) ) { jsonError("Provide id or phone_lookup"); exit; }
|
||||
if ($first_name === null && $last_name === null && $new_phone === null) {
|
||||
jsonError("Nothing to update"); exit;
|
||||
}
|
||||
|
||||
$sets = [];
|
||||
$params = [];
|
||||
$new_phone = $encryptionHelper->encryptData($new_phone);
|
||||
$first_name = $encryptionHelper->encryptData($first_name);
|
||||
$last_name = $encryptionHelper->encryptData($last_name);
|
||||
|
||||
$enc_norm = $encryptionHelper->encryptData($norm);
|
||||
if ($first_name !== null) { $sets[] = "first_name = :first_name"; $params['first_name'] = trim($first_name); }
|
||||
if ($last_name !== null) { $sets[] = "last_name = :last_name"; $params['last_name'] = trim($last_name); }
|
||||
if ($new_phone !== null) {
|
||||
$sets[] = "phone = :phone";
|
||||
$params['phone'] = trim($new_phone);
|
||||
|
||||
// منع تكرار الهاتف على راكب آخر
|
||||
$q = $con->prepare("SELECT id FROM passengers WHERE phone = :ph LIMIT 1");
|
||||
$q->execute(['ph' => $params['phone']]);
|
||||
$row = $q->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row) {
|
||||
if (!empty($id) && $row['id'] != $id) { jsonError("Phone already used by another passenger"); exit; }
|
||||
if (empty($id) && $row['id'] != $phoneLookup) { jsonError("Phone already used by another passenger"); exit; }
|
||||
}
|
||||
}
|
||||
|
||||
$whereSql = "";
|
||||
$whereParams = [];
|
||||
if (!empty($id)) { $whereSql = "id = :pid"; $whereParams['pid'] = $id; }
|
||||
else { $whereSql = "phone = :plk"; $whereParams['plk'] = $phoneLookup; }
|
||||
|
||||
$sql = "UPDATE passengers SET ".implode(", ", $sets).", updated_at = CURRENT_TIMESTAMP WHERE $whereSql";
|
||||
$stmt = $con->prepare($sql);
|
||||
$ok = $stmt->execute(array_merge($params, $whereParams));
|
||||
|
||||
if ($ok && $stmt->rowCount() > 0) { jsonSuccess(null, "Passenger updated"); }
|
||||
else { jsonError("No change or passenger not found"); }
|
||||
Reference in New Issue
Block a user