34968-vm/driver_signup_process.php
Flatlogic Bot 2be0d2d4c4 V20
2025-10-16 14:27:25 +00:00

72 lines
3.0 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$phone_number = $_POST['phone_number'];
$vehicle_details = $_POST['vehicle_details'];
if (empty($full_name) || empty($email) || empty($password) || empty($phone_number) || empty($vehicle_details)) {
die('Please fill all required fields.');
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
die('Invalid email format.');
}
try {
$pdo = db();
// Check if driver already exists
$sql = "SELECT id FROM drivers WHERE email = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$email]);
if ($stmt->fetch()) {
die('Email already exists.');
}
// Insert into drivers table
$password_hash = password_hash($password, PASSWORD_BCRYPT);
$sql = "INSERT INTO drivers (full_name, email, password_hash, phone_number, vehicle_details, approval_status) VALUES (?, ?, ?, ?, ?, 'pending')";
$stmt = $pdo->prepare($sql);
if ($stmt->execute([$full_name, $email, $password_hash, $phone_number, $vehicle_details])) {
// Send email notification to admins
require_once __DIR__ . '/mail/MailService.php';
$stmt_emails = $pdo->prepare("SELECT email FROM email_recipients WHERE form_type = ?");
$stmt_emails->execute(['driver_signup']);
$recipients = $stmt_emails->fetchAll(PDO::FETCH_COLUMN);
if (!empty($recipients)) {
$subject = 'New Driver Signup: ' . $full_name;
$html_content = "<p>A new driver has signed up and is awaiting approval.</p>" .
"<p><strong>Name:</strong> {$full_name}</p>" .
"<p><strong>Email:</strong> {$email}</p>" .
"<p><strong>Phone:</strong> {$phone_number}</p>" .
"<p><strong>Vehicle:</strong> {$vehicle_details}</p>" .
"<p>Please visit the admin panel to review and approve the application.</p>";
$text_content = "A new driver has signed up and is awaiting approval.\n\n" .
"Name: {$full_name}\n" .
"Email: {$email}\n" .
"Phone: {$phone_number}\n" .
"Vehicle: {$vehicle_details}\n\n" .
"Please visit the admin panel to review and approve the application.";
MailService::sendMail($recipients, $subject, $html_content, $text_content);
}
// Redirect to a pending approval page
header("Location: driver_pending_approval.php");
exit;
} else {
die("Error: Could not execute the query.");
}
} catch (PDOException $e) {
die("Could not connect to the database: " . $e->getMessage());
}
}
?>