diff --git a/admin_truck_expiry_report.php b/admin_truck_expiry_report.php new file mode 100644 index 0000000..5ff2b59 --- /dev/null +++ b/admin_truck_expiry_report.php @@ -0,0 +1,56 @@ + + +
+
+ +
+
+

Truck Expiry Report

+ +
+ + + + + + + + + + + + query(" + SELECT t.*, u.full_name as owner_name + FROM trucks t + JOIN users u ON t.user_id = u.id + WHERE t.registration_expiry_date < DATE_ADD(NOW(), INTERVAL 30 DAY) + OR t.insurance_expiry_date < DATE_ADD(NOW(), INTERVAL 30 DAY) + ")->fetchAll(); + + foreach ($trucks as $truck): + $regExpired = strtotime($truck['registration_expiry_date']) < time(); + $insExpired = strtotime($truck['insurance_expiry_date']) < time(); + $isExpired = $regExpired || $insExpired; + ?> + + + + + + + + + +
OwnerPlate NoRegistration ExpiryInsurance ExpiryStatus
+
+
+
+ + diff --git a/admin_truck_owner_edit.php b/admin_truck_owner_edit.php index 56f862c..eb8c642 100644 --- a/admin_truck_owner_edit.php +++ b/admin_truck_owner_edit.php @@ -48,60 +48,68 @@ $countries = db()->query("SELECT id, name_en, name_ar FROM countries ORDER BY na $cities = db()->query("SELECT id, country_id, name_en, name_ar FROM cities ORDER BY name_en ASC")->fetchAll(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token(); - $fullName = trim($_POST['full_name'] ?? ''); - $email = trim($_POST['email'] ?? ''); - $phone = trim($_POST['phone'] ?? ''); - $countryId = (int)($_POST['country_id'] ?? 0); - $cityId = (int)($_POST['city_id'] ?? 0); - $addressLine = trim($_POST['address_line'] ?? ''); - $status = trim($_POST['status'] ?? ''); - $password = $_POST['password'] ?? ''; - - $bankAccount = trim($_POST['bank_account'] ?? ''); - $bankName = trim($_POST['bank_name'] ?? ''); - $bankBranch = trim($_POST['bank_branch'] ?? ''); - $isCompany = isset($_POST['is_company']) ? 1 : 0; + if (isset($_POST['approve_truck'])) { + $truckId = (int)$_POST['truck_id']; + db()->prepare("UPDATE trucks SET is_approved = 1 WHERE id = ? AND user_id = ?")->execute([$truckId, $userId]); + $flash = 'Truck approved successfully.'; + } elseif (isset($_POST['reject_truck'])) { + $truckId = (int)$_POST['truck_id']; + db()->prepare("UPDATE trucks SET is_approved = 0 WHERE id = ? AND user_id = ?")->execute([$truckId, $userId]); + $flash = 'Truck status set to unapproved.'; + } else { + $fullName = trim($_POST['full_name'] ?? ''); + $email = trim($_POST['email'] ?? ''); + $phone = trim($_POST['phone'] ?? ''); + $countryId = (int)($_POST['country_id'] ?? 0); + $cityId = (int)($_POST['city_id'] ?? 0); + $addressLine = trim($_POST['address_line'] ?? ''); + $status = trim($_POST['status'] ?? ''); + $password = $_POST['password'] ?? ''; + + $bankAccount = trim($_POST['bank_account'] ?? ''); + $bankName = trim($_POST['bank_name'] ?? ''); + $bankBranch = trim($_POST['bank_branch'] ?? ''); + $isCompany = isset($_POST['is_company']) ? 1 : 0; - if ($fullName === '') $errors[] = 'Full name is required.'; - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Valid email is required.'; - if ($phone === '') $errors[] = 'Phone number is required.'; - if (!in_array($status, ['pending', 'active', 'rejected'], true)) $errors[] = 'Invalid status.'; - - if ($countryId <= 0 || $cityId <= 0) { - $errors[] = 'Please select country and city.'; - } + if ($fullName === '') $errors[] = 'Full name is required.'; + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Valid email is required.'; + if ($phone === '') $errors[] = 'Phone number is required.'; + if (!in_array($status, ['pending', 'active', 'rejected'], true)) $errors[] = 'Invalid status.'; + + if ($countryId <= 0 || $cityId <= 0) { + $errors[] = 'Please select country and city.'; + } - if (!$errors) { - try { - db()->beginTransaction(); + if (!$errors) { + try { + db()->beginTransaction(); - $stmtUser = db()->prepare("UPDATE users SET full_name = ?, email = ?, status = ? WHERE id = ? AND role = 'truck_owner'"); - $stmtUser->execute([$fullName, $email, $status, $userId]); - - if ($password !== '') { - $stmtPass = db()->prepare("UPDATE users SET password = ? WHERE id = ? AND role = 'truck_owner'"); - $stmtPass->execute([password_hash($password, PASSWORD_DEFAULT), $userId]); + $stmtUser = db()->prepare("UPDATE users SET full_name = ?, email = ?, status = ? WHERE id = ? AND role = 'truck_owner'"); + $stmtUser->execute([$fullName, $email, $status, $userId]); + + if ($password !== '') { + $stmtPass = db()->prepare("UPDATE users SET password = ? WHERE id = ? AND role = 'truck_owner'"); + $stmtPass->execute([password_hash($password, PASSWORD_DEFAULT), $userId]); + } + + $stmtProfile = db()->prepare(" + UPDATE truck_owner_profiles + SET phone = ?, address_line = ?, country_id = ?, city_id = ?, + bank_account = ?, bank_name = ?, bank_branch = ?, is_company = ? + WHERE user_id = ? + "); + $stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $userId]); + + db()->commit(); + $flash = 'Truck Owner profile updated successfully.'; + } catch (Throwable $e) { + db()->rollBack(); + $errors[] = 'Failed to update truck owner profile. Please try again.'; } - - $stmtProfile = db()->prepare(" - UPDATE truck_owner_profiles - SET phone = ?, address_line = ?, country_id = ?, city_id = ?, - bank_account = ?, bank_name = ?, bank_branch = ?, is_company = ? - WHERE user_id = ? - "); - $stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $userId]); - - db()->commit(); - $flash = 'Truck Owner profile updated successfully.'; - } catch (Throwable $e) { - db()->rollBack(); - $errors[] = 'Failed to update truck owner profile. Please try again.'; } } } -$idCards = json_decode($owner['id_card_path'] ?? '[]', true) ?: []; - // -- OUTPUT START -- if (!$isAjax): render_header('Edit Truck Owner', 'admin', true); @@ -207,16 +215,45 @@ if (!$isAjax): Truck Type - Load Capacity (T) + Capacity (T) Plate No + Reg Expiry + Ins Expiry + Status + Actions - + + + + + + + Expired/Disabled + + Approved + + Pending + + + +
+ + + + + + + +
+ diff --git a/register.php b/register.php index 0a137c0..cd213b3 100644 --- a/register.php +++ b/register.php @@ -16,9 +16,6 @@ $values = [ 'city_id' => '', 'address_line' => '', 'company_name' => '', - 'truck_type' => '', - 'load_capacity' => '', - 'plate_no' => '', 'bank_account' => '', 'bank_name' => '', 'bank_branch' => '', @@ -48,9 +45,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token(); 'city_id' => $cityId > 0 ? (string)$cityId : '', 'address_line' => $addressLine, 'company_name' => $companyName, - 'truck_type' => trim($_POST['truck_type'] ?? ''), - 'load_capacity' => trim($_POST['load_capacity'] ?? ''), - 'plate_no' => trim($_POST['plate_no'] ?? ''), 'bank_account' => trim($_POST['bank_account'] ?? ''), 'bank_name' => trim($_POST['bank_name'] ?? ''), 'bank_branch' => trim($_POST['bank_branch'] ?? ''), @@ -107,16 +101,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token(); ); $shipperStmt->execute([$userId, $companyName, $phone, $countryId, $cityId, $addressLine]); } else { - $truckType = trim($_POST['truck_type'] ?? ''); - $loadCapacity = trim($_POST['load_capacity'] ?? ''); - $plateNo = trim($_POST['plate_no'] ?? ''); - - if ($truckType === '' || $loadCapacity === '' || $plateNo === '') { - $errors[] = 'Please complete truck details.'; - } elseif (!is_numeric($loadCapacity) || (float)$loadCapacity <= 0) { - $errors[] = 'Load capacity must be numeric and greater than zero.'; - } - $uploadDir = __DIR__ . '/uploads/profiles/' . $userId . '/'; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0775, true); @@ -150,25 +134,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token(); if ($path) $idCardPaths[] = $path; } - $regPaths = []; - if (is_uploaded_file($_FILES['truck_reg_front']['tmp_name'] ?? '')) { - $path = $saveImage($_FILES['truck_reg_front']['tmp_name'], (int)$_FILES['truck_reg_front']['size'], 'reg_front_'); - if ($path) $regPaths[] = $path; - } - if (is_uploaded_file($_FILES['truck_reg_back']['tmp_name'] ?? '')) { - $path = $saveImage($_FILES['truck_reg_back']['tmp_name'], (int)$_FILES['truck_reg_back']['size'], 'reg_back_'); - if ($path) $regPaths[] = $path; - } - - $truckPic = null; - $truckTmp = $_FILES['truck_picture']['tmp_name'] ?? ''; - if (is_uploaded_file($truckTmp)) { - $truckSize = (int)($_FILES['truck_picture']['size'] ?? 0); - $truckPic = $saveImage($truckTmp, $truckSize, 'truck_'); - } - - if (count($idCardPaths) < 2 || count($regPaths) < 2 || !$truckPic) { - $errors[] = 'Please upload all required truck-owner images (ID front/back, registration front/back, truck photo).'; + if (count($idCardPaths) < 2) { + $errors[] = 'Please upload ID front and back.'; } if (!$errors) { @@ -188,19 +155,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token(); json_encode($idCardPaths, JSON_UNESCAPED_SLASHES), $values['is_company'] ]); - - $truckStmt = $pdo->prepare( - "INSERT INTO trucks (user_id, truck_type, load_capacity, plate_no, truck_pic_path, registration_path) - VALUES (?, ?, ?, ?, ?, ?)" - ); - $truckStmt->execute([ - $userId, - $truckType, - $loadCapacity, - $plateNo, - $truckPic, - json_encode($regPaths, JSON_UNESCAPED_SLASHES) - ]); } } @@ -319,7 +273,7 @@ render_header('Shipper & Truck Owner Registration');