Update: 2026-07-13 22:23:21
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// transit/driver/suspend.php — تعليق/إعادة تفعيل سائق
|
||||
// POST: driver_id, action (suspend|activate)
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_admin.php';
|
||||
|
||||
$driverId = filterRequest('driver_id', 'int');
|
||||
$action = filterRequest('action');
|
||||
if (!$driverId) jsonError('driver_id is required', 400);
|
||||
if (!in_array($action, ['suspend', 'activate'])) jsonError('action must be suspend or activate', 400);
|
||||
|
||||
$chk = $transit_con->prepare("SELECT id, status FROM transit_drivers WHERE id=? AND org_id=? LIMIT 1");
|
||||
$chk->execute([$driverId, $transit_org_id]);
|
||||
$driver = $chk->fetch();
|
||||
if (!$driver) jsonError('Driver not found or access denied', 404);
|
||||
|
||||
// إعادة التفعيل غير ممكنة إلا لسائق سبق تفعيله عبر الدعوة (status كان suspended)
|
||||
if ($action === 'activate' && $driver['status'] !== 'suspended') {
|
||||
jsonError('Only a suspended driver can be reactivated', 409);
|
||||
}
|
||||
|
||||
$newStatus = $action === 'suspend' ? 'suspended' : 'active';
|
||||
$transit_con->prepare("UPDATE transit_drivers SET status=? WHERE id=?")->execute([$newStatus, $driverId]);
|
||||
|
||||
appLog("[TRANSIT][DRIVER][suspend] driver #{$driverId} org#{$transit_org_id} → {$newStatus}");
|
||||
|
||||
jsonSuccess(['driver_id' => $driverId, 'status' => $newStatus]);
|
||||
Reference in New Issue
Block a user