Update: 2026-07-13 22:23:21

This commit is contained in:
Hamza-Ayed
2026-07-13 22:23:22 +03:00
parent fd3f4a365a
commit c6f48a1f91
45 changed files with 3533 additions and 36 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
// transit/vehicle/update.php — تعديل بيانات مركبة
// POST: vehicle_id, [plate, make, model, year, color, capacity, vehicle_type, notes]
require_once __DIR__ . '/../../transit/connect_admin.php';
$vehicleId = filterRequest('vehicle_id', 'int');
if (!$vehicleId) jsonError('vehicle_id is required', 400);
$chk = $transit_con->prepare("SELECT id FROM transit_vehicles WHERE id=? AND org_id=? LIMIT 1");
$chk->execute([$vehicleId, $transit_org_id]);
if (!$chk->fetch()) jsonError('Vehicle not found or access denied', 404);
$plate = filterRequest('plate');
if ($plate) {
$plate = strtoupper($plate);
$dup = $transit_con->prepare("SELECT id FROM transit_vehicles WHERE plate=? AND id<>? LIMIT 1");
$dup->execute([$plate, $vehicleId]);
if ($dup->fetch()) jsonError('Vehicle plate already registered', 409);
}
$vType = filterRequest('vehicle_type');
if ($vType && !in_array($vType, ['bus','minibus','van','other'])) $vType = null;
$transit_con->prepare(
"UPDATE transit_vehicles
SET plate=COALESCE(?, plate), make=COALESCE(?, make), model=COALESCE(?, model),
year=COALESCE(?, year), color=COALESCE(?, color), capacity=COALESCE(?, capacity),
vehicle_type=COALESCE(?, vehicle_type), notes=COALESCE(?, notes)
WHERE id=?"
)->execute([
$plate, filterRequest('make'), filterRequest('model'),
filterRequest('year', 'int'), filterRequest('color'), filterRequest('capacity', 'int'),
$vType, filterRequest('notes'),
$vehicleId,
]);
jsonSuccess(['vehicle_id' => $vehicleId], 'Vehicle updated');