prepare("SELECT phone FROM `driver` WHERE `id` = :id"); $stmtPhone->bindParam(':id', $id, PDO::PARAM_INT); $stmtPhone->execute(); $driverData = $stmtPhone->fetch(PDO::FETCH_ASSOC); // التحقق من وجود السائق if (!$driverData) { jsonError("Driver not found"); exit(); } $phone = $driverData['phone']; // 2. تحديث حالة السائق $sql = "UPDATE `driver` SET `status` = 'deleteFromHimself' WHERE `id` = :id"; $stmt = $con->prepare($sql); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() > 0) { // 3. الإضافة إلى القائمة السوداء (blacklist_driver) // نستخدم NOW() لتسجيل الوقت الحالي تلقائياً // لا نمرر id العمود الأول لأنه غالباً Auto Increment في قاعدة البيانات $insertSql = "INSERT INTO `blacklist_driver` (`driver_id`, `phone`, `reason`, `created_at`) VALUES (:driver_id, :phone, :reason, NOW())"; $insertStmt = $con->prepare($insertSql); $insertStmt->execute([ ':driver_id' => $id, ':phone' => $phone, ':reason' => $reason ]); jsonSuccess(null, "Record marked as deleted and added to blacklist successfully"); } else { jsonError("Failed to update record or no change made"); } } catch (PDOException $e) { // في حال حدوث خطأ في قاعدة البيانات (مثلاً تكرار الإضافة) error_log("[deletecaptainAccounr] " . $e->getMessage()); jsonError("Database Error"); } ?>