encryptData($email); $encryptedPhone = $encryptionHelper->encryptData($phone); $encryptedFirstName = $encryptionHelper->encryptData('Driver'); $encryptedLastName = $encryptionHelper->encryptData('Tester'); $encryptedGender = $encryptionHelper->encryptData('Male'); $encryptedBirthdate = $encryptionHelper->encryptData('1990-01-01'); $encryptedSite = $encryptionHelper->encryptData('Jordan'); try { $con = Database::get('main'); // 1. Check if driver exists $stmt = $con->prepare("SELECT id FROM driver WHERE email = :email LIMIT 1"); $stmt->bindParam(':email', $encryptedEmail); $stmt->execute(); $driver = $stmt->fetch(PDO::FETCH_ASSOC); if ($driver) { $driverId = $driver['id']; $update = $con->prepare("UPDATE driver SET password = :password, phone = :phone WHERE id = :id"); $update->bindParam(':password', $hashedPassword); $update->bindParam(':phone', $encryptedPhone); $update->bindParam(':id', $driverId); $update->execute(); echo "Driver tester updated successfully.\n"; } else { $driverId = bin2hex(random_bytes(10)); // 20 chars unique id $insert = $con->prepare("INSERT INTO driver (id, phone, email, password, gender, birthdate, site, first_name, last_name) VALUES (:id, :phone, :email, :password, :gender, :birthdate, :site, :first_name, :last_name)"); $insert->bindParam(':id', $driverId); $insert->bindParam(':phone', $encryptedPhone); $insert->bindParam(':email', $encryptedEmail); $insert->bindParam(':password', $hashedPassword); $insert->bindParam(':gender', $encryptedGender); $insert->bindParam(':birthdate', $encryptedBirthdate); $insert->bindParam(':site', $encryptedSite); $insert->bindParam(':first_name', $encryptedFirstName); $insert->bindParam(':last_name', $encryptedLastName); $insert->execute(); echo "Driver tester created successfully with ID: $driverId\n"; } // 2. Ensure phone_verification row exists $stmtPhone = $con->prepare("SELECT * FROM phone_verification WHERE phone_number = :phone LIMIT 1"); $stmtPhone->bindParam(':phone', $encryptedPhone); $stmtPhone->execute(); if ($stmtPhone->fetch()) { $updatePhone = $con->prepare("UPDATE phone_verification SET is_verified = 1 WHERE phone_number = :phone"); $updatePhone->bindParam(':phone', $encryptedPhone); $updatePhone->execute(); } else { $insertPhone = $con->prepare("INSERT INTO phone_verification (phone_number, is_verified) VALUES (:phone, 1)"); $insertPhone->bindParam(':phone', $encryptedPhone); $insertPhone->execute(); } // 3. Ensure CarRegistration row exists $stmtCar = $con->prepare("SELECT * FROM CarRegistration WHERE driverID = :driverID LIMIT 1"); $stmtCar->bindParam(':driverID', $driverId); $stmtCar->execute(); if ($stmtCar->fetch()) { $updateCar = $con->prepare("UPDATE CarRegistration SET make = 'Toyota', model = 'Prius', year = '2020' WHERE driverID = :driverID"); $updateCar->bindParam(':driverID', $driverId); $updateCar->execute(); } else { $insertCar = $con->prepare("INSERT INTO CarRegistration (driverID, make, model, year) VALUES (:driverID, 'Toyota', 'Prius', '2020')"); $insertCar->bindParam(':driverID', $driverId); $insertCar->execute(); } echo "Verification and Car Registration configured.\n"; } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; } ?>