getWashCertificateDownload($_GET['bookingId']); // Exit the script exit; } // Require the $_GET variables sealOrPlumber, safetySeal, performedBy, and bookingId, regNumber, and regNumberTrailer to be set if (!isset($_GET['sealOrPlumber']) || !isset($_GET['performedBy']) || !isset($_GET['bookingId']) || !isset($_GET['regNumber']) || !isset($_GET['regNumberTrailer']) || !isset($_GET['department'])) { // We are missing some required fields in the query string echo 'Missing required fields'; exit; } // Check if the certificate already exists in the bucket $wash_certificate_store = new wash_certificate_store(); if ($wash_certificate_store->washCertificateExists($_GET['bookingId'])) { // Return the certificate url echo $wash_certificate_store->getWashCertificateDownload($_GET['bookingId']); // Exit the script exit; } else { // Check if the certificate exists in the filesystem (legacy system) if (file_exists(dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf")) { // Upload the certificate to the bucket $success = $wash_certificate_store->uploadFile("wash_certificate_" . $_GET['bookingId'] . ".pdf", dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf"); // If the certificate was uploaded successfully, delete the local copy if ($success) { //unlink(dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf"); // Return the certificate url echo $wash_certificate_store->getWashCertificateDownload($_GET['bookingId']); exit; } // If the certificate was not uploaded successfully, return an error echo 'Failed to upload the certificate'; // Exit the script exit; } } // Usage example $template = "templates/template2024julv3.xlsx"; $generator = new WashCertificateGenerator($template, $_GET['department']); $generator->generateCertificate(dirname(__FILE__) . "/output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf", $_GET['sealOrPlumber'], $_GET['regNumber'], $_GET['regNumberTrailer'], $_GET['performedBy']); // Determine the generated certificate name $generatedCertificateName = "wash_certificate_" . $_GET['bookingId'] . ".pdf"; // Return the generated certificate path $generatedCertificatePath = "output/certificates/wash_certificate_" . $_GET['bookingId'] . ".pdf"; // Upload the certificate to the bucket $wash_certificate_store->uploadFile($generatedCertificateName, dirname(__FILE__) . '/' . $generatedCertificatePath); // Delete the local copy of the certificate //unlink(dirname(__FILE__) . '/' . $generatedCertificatePath); // Set the status of the booking to completed $booking = new bookings_o(); $booking->id = $_GET['bookingId']; $booking->getObjectProperties(); $booking->status->set('completed'); $booking->washCertificateUrl->set('Protected URL'); $booking->washCertificateStatus->set('completed'); // Return the generated certificate object download URL echo $wash_certificate_store->getWashCertificateDownload($_GET['bookingId']); // Exit the script exit;