Refactor code: remove unnecessary comments and clean up whitespace in various files

This commit is contained in:
vista-man
2025-04-10 22:53:25 +02:00
parent e46044682e
commit 4e0f6238b6
8 changed files with 62 additions and 98 deletions

View File

@@ -1,42 +1,35 @@
<!-- filepath: c:\xampp\htdocs\Spik-en-span\process_ticket.php -->
<?php
// Enable error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Database connection
$servername = "localhost";
$username = "database12"; // Updated username
$password = "181t$1lJg"; // Updated password
$username = "database12";
$password = "181t$1lJg";
$dbname = "spik_en_span";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve form data
$name = $_POST['name'];
$email = $_POST['email'];
$category = $_POST['category']; // e.g., 'Volwassenen Vrijdag' or 'Kinderen Zaterdag'
$category = $_POST['category'];
$quantity = (int)$_POST['quantity'];
// Extract day and category from the input
list($categoryType, $day) = explode(' ', $category); // Split into 'Volwassenen'/'Kinderen' and 'Vrijdag'/'Zaterdag'
list($categoryType, $day) = explode(' ', $category);
$day = strtolower($day) === 'vrijdag' ? 'friday' : 'saturday';
$categoryType = strtolower($categoryType) === 'volwassenen' ? 'volwassen' : 'kind';
require __DIR__ . '/../phpmailer/src/PHPMailer.php';
require __DIR__ . '/../phpmailer/src/SMTP.php';
require __DIR__ . '/../phpmailer/src/Exception.php';
require_once __DIR__ . '/../fpdf/fpdf.php'; // Ensure FPDF is included only once
require_once __DIR__ . '/../fpdf/fpdf.php';
use PHPMailer\PHPMailer\PHPMailer;
// Prepare SQL statement
$sql = "INSERT INTO tickets (ticket_id, name, email, category, day, quantity, qr_code_link) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
@@ -44,13 +37,12 @@ if (!$stmt) {
die("Error preparing statement: " . $conn->error);
}
$qrCodes = []; // Array to store QR code URLs for PDF attachment
$qrCodes = [];
// Insert one ticket per row and generate QR codes
for ($i = 0; $i < $quantity; $i++) {
$ticket_id = bin2hex(random_bytes(16)); // Generate a 32-character unique ticket ID
$qrCodeUrl = "https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=" . urlencode($ticket_id); // Generate QR code link
$one_ticket_quantity = 1; // Each row represents one ticket
$ticket_id = bin2hex(random_bytes(16));
$qrCodeUrl = "https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=" . urlencode($ticket_id);
$one_ticket_quantity = 1;
$stmt->bind_param("sssssis", $ticket_id, $name, $email, $categoryType, $day, $one_ticket_quantity, $qrCodeUrl);
if (!$stmt->execute()) {
echo "Error: " . $stmt->error;
@@ -59,80 +51,71 @@ for ($i = 0; $i < $quantity; $i++) {
exit();
}
$qrCodes[] = ['ticket_id' => $ticket_id, 'qr_code_url' => $qrCodeUrl]; // Store QR code details for PDF
$qrCodes[] = ['ticket_id' => $ticket_id, 'qr_code_url' => $qrCodeUrl];
}
$stmt->close();
$conn->close();
// Generate individual PDFs for each QR code
$pdfPaths = []; // Array to store paths of generated PDFs
$pdfPaths = [];
foreach ($qrCodes as $index => $qrCode) {
$pdf = new FPDF();
$pdf->AddPage();
// Add a header with a gradient-like effect
$pdf->SetFillColor(40, 167, 69); // Green background
$pdf->SetTextColor(255, 255, 255); // White text
$pdf->SetFillColor(40, 167, 69);
$pdf->SetTextColor(255, 255, 255);
$pdf->SetFont('Arial', 'B', 24);
$pdf->Cell(0, 20, 'Spik & Span - Ticket Bevestiging', 0, 1, 'C', true);
$pdf->Ln(10);
// Add a colored section for customer details
$pdf->SetFillColor(230, 230, 250); // Light lavender background
$pdf->SetTextColor(0, 0, 0); // Black text
$pdf->SetFillColor(230, 230, 250);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('Arial', '', 14);
$pdf->Cell(0, 10, 'Naam: ' . $name, 0, 1, 'L', true);
$pdf->Cell(0, 10, 'E-mail: ' . $email, 0, 1, 'L', true);
$pdf->Ln(10);
// Add ticket details with a colored background
$pdf->SetFillColor(240, 255, 240); // Light green background
$pdf->SetTextColor(0, 0, 0); // Black text
$pdf->SetFillColor(240, 255, 240);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('Arial', '', 14);
$pdf->Cell(0, 10, 'Ticket ' . ($index + 1) . ':', 0, 1, 'L', true);
$pdf->Cell(0, 10, 'Ticket ID: ' . $qrCode['ticket_id'], 0, 1, 'L', true);
$pdf->Ln(5);
// Add QR code image centered and larger
$qrCodeImage = file_get_contents($qrCode['qr_code_url']);
$qrCodePath = __DIR__ . "/temp_qr_$index.png";
file_put_contents($qrCodePath, $qrCodeImage);
$pdf->Cell(0, 0, '', 0, 1, 'C'); // Move to the center
$pdf->Image($qrCodePath, ($pdf->GetPageWidth() - 80) / 2, $pdf->GetY(), 80, 80); // Larger QR code
$pdf->Cell(0, 0, '', 0, 1, 'C');
$pdf->Image($qrCodePath, ($pdf->GetPageWidth() - 80) / 2, $pdf->GetY(), 80, 80);
$pdf->Ln(90);
// Clean up temporary QR code image
unlink($qrCodePath);
// Add a footer on the same page
$pdf->SetY(-50); // Adjust Y position to ensure the footer fits on the same page
$pdf->SetFillColor(40, 167, 69); // Green background
$pdf->SetTextColor(255, 255, 255); // White text
$pdf->SetY(-50);
$pdf->SetFillColor(40, 167, 69);
$pdf->SetTextColor(255, 255, 255);
$pdf->SetFont('Arial', 'I', 12);
$pdf->Cell(0, 10, 'Bedankt voor uw bestelling bij Spik & Span!', 0, 1, 'C', true);
$pdf->Cell(0, 10, 'Voor vragen kunt u contact opnemen via onze website.', 0, 1, 'C', true);
// Save PDF to a temporary file
$pdfPath = __DIR__ . "/ticket_$index.pdf";
$pdf->Output('F', $pdfPath);
$pdfPaths[] = $pdfPath; // Store the path of the generated PDF
$pdfPaths[] = $pdfPath;
}
// Send confirmation email with all PDF attachments
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Gmail SMTP server
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'ticketsopdracht@gmail.com'; // Your Gmail address
$mail->Password = 'rqxm fbju xbmu qmbr'; // Your App Password from Google
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Use TLS encryption
$mail->Port = 587; // TLS port
$mail->Username = 'ticketsopdracht@gmail.com';
$mail->Password = 'rqxm fbju xbmu qmbr';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('ticketsopdracht@gmail.com', 'Spik & Span'); // Sender email and name
$mail->addAddress($email, $name); // Recipient email and name
$mail->setFrom('ticketsopdracht@gmail.com', 'Spik & Span');
$mail->addAddress($email, $name);
$mail->isHTML(true);
$mail->Subject = 'Bevestiging van je bestelling';
@@ -144,19 +127,16 @@ try {
<p style="font-size: 16px; color: #333;">Met vriendelijke groet,<br><strong>Spik & Span</strong></p>
</div>';
// Attach each PDF to the email
foreach ($pdfPaths as $pdfPath) {
$mail->addAttachment($pdfPath);
}
$mail->send();
// Clean up temporary PDF files
foreach ($pdfPaths as $pdfPath) {
unlink($pdfPath);
}
// Redirect to the order completion page
header("Location: ../order-complete.html");
exit();
} catch (Exception $e) {