Files
Siro/backend/driver_assurance/add.php
T

44 lines
1.7 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../connect.php';
// ‏المسار القديم للتأمين الصحي. المسار الجديد (خطط، أهلية، أقساط) في
// ‏plans.php و subscribe.php و get.php — هذا يبقى لمن سُجّل هنا سابقاً.
// ‏الهوية من الـJWT لا من الطلب. كان الملف يقرأ driver_id من المدخلات
// ‏بلا أي فحص، فأي حامل رمز صالح يكتب سجل تأمين باسم أي سائق.
$driver_id = $user_id ?? '';
if (empty($driver_id) || ($role ?? '') !== 'driver') {
jsonError('Unauthorized', 401);
}
$assured = filterRequest("assured");
$health_insurance_provider = filterRequest("health_insurance_provider");
// ‏upsert لا insert: العمود driver_id عليه مفتاح فريد، فأي حفظ ثانٍ
// ‏لنفس السائق كان يفشل بخرق المفتاح — والحفظ الثاني هو الحالة
// ‏الطبيعية (تعديل مزوّد التأمين) لا الاستثناء.
$sql = "INSERT INTO `driver_health_assurance` (
`driver_id`,
`assured`,
`health_insurance_provider`
) VALUES (
:driver_id,
:assured,
:health_insurance_provider
)
ON DUPLICATE KEY UPDATE
`assured` = VALUES(`assured`),
`health_insurance_provider` = VALUES(`health_insurance_provider`)";
$stmt = $con->prepare($sql);
$stmt->bindParam(':driver_id', $driver_id);
$stmt->bindParam(':assured', $assured);
$stmt->bindParam(':health_insurance_provider', $health_insurance_provider);
if ($stmt->execute()) {
jsonSuccess(null, "Health assurance data saved successfully");
} else {
jsonError("Failed to save health assurance data");
}
?>