36842-vm/order.php
2025-12-11 07:44:58 +00:00

243 lines
13 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/mail/MailService.php';
$product = isset($_GET['product']) ? htmlspecialchars($_GET['product']) : 'Product';
$message_sent = false;
$error_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$client_name = strip_tags(trim($_POST["client_name"] ?? ''));
$phone_number = strip_tags(trim($_POST["phone_number"] ?? ''));
$delivery_address = strip_tags(trim($_POST["delivery_address"] ?? ''));
$model = strip_tags(trim($_POST["model"] ?? ''));
$dimensions = strip_tags(trim($_POST["dimensions"] ?? ''));
$thickness = strip_tags(trim($_POST["thickness"] ?? ''));
$quantity = strip_tags(trim($_POST["quantity"] ?? ''));
$notes = strip_tags(trim($_POST["notes"] ?? ''));
$delivery_date = strip_tags(trim($_POST["delivery_date"] ?? ''));
if (empty($client_name) || empty($phone_number) || empty($delivery_address) || empty($quantity) ) {
$error_message = "Please fill out all required fields.";
} else {
$to = getenv('MAIL_TO') ?: 'admin@example.com';
$subject = "New Order for " . $product;
if (isset($_POST['pro_forma_request']) && $_POST['pro_forma_request'] == '1') {
$pro_forma_email = strip_tags(trim($_POST['pro_forma_email'] ?? ''));
if (filter_var($pro_forma_email, FILTER_VALIDATE_EMAIL)) {
$subject .= " (Pro-forma Invoice Request)";
}
}
$email_body = "<h3>New Order Details:</h3>";
$email_body .= "<strong>Product:</strong> {$product}<br>";
$email_body .= "<strong>Client Name:</strong> {$client_name}<br>";
$email_body .= "<strong>Phone Number:</strong> {$phone_number}<br>";
$email_body .= "<strong>Delivery Address:</strong> {$delivery_address}<br>";
$email_body .= "<h4>📦 Carton Order Details</h4>";
$email_body .= "<strong>Model:</strong> {$model}<br>";
$email_body .= "<strong>Dimensions (cm):</strong> {$dimensions}<br>";
$email_body .= "<strong>Thickness:</strong> {$thickness}<br>";
$email_body .= "<strong>Quantity:</strong> {$quantity}<br>";
$email_body .= "<h4>🗒 Notes</h4>";
$email_body .= "<p>" . ($notes ?: 'N/A') . "</p>";
$email_body .= "<strong>📅 Delivery Preferred Date:</strong> {$delivery_date}<br>";
$text_body = "New Order Details:\n\n";
$text_body .= "Product: {$product}\n";
$text_body .= "Client Name: {$client_name}\n";
$text_body .= "Phone Number: {$phone_number}\n";
$text_body .= "Delivery Address: {$delivery_address}\n";
$text_body .= "--- Carton Order Details ---\n";
$text_body .= "Model: {$model}\n";
$text_body .= "Dimensions (cm): {$dimensions}\n";
$text_body .= "Thickness: {$thickness}\n";
$text_body .= "Quantity: {$quantity}\n";
$text_body .= "--- Notes ---\n";
$text_body .= ($notes ?: 'N/A') . "\n";
$text_body .= "Delivery Preferred Date: {$delivery_date}\n";
if (isset($pro_forma_email) && filter_var($pro_forma_email, FILTER_VALIDATE_EMAIL)) {
$email_body .= "<hr><h4>Pro-forma Invoice Request</h4>";
$email_body .= "<p>Please send a pro-forma invoice to: <strong>{$pro_forma_email}</strong></p>";
$text_body .= "\n--- Pro-forma Invoice Request ---\n";
$text_body .= "Please send a pro-forma invoice to: {$pro_forma_email}\n";
}
$attachments = [];
if (isset($_FILES['design_file']) && $_FILES['design_file']['error'] == UPLOAD_ERR_OK) {
$attachments[] = $_FILES['design_file'];
}
$result = MailService::sendMail($to, $subject, $email_body, $text_body, [], $attachments);
if (!empty($result['success'])) {
$message_sent = true;
} else {
$error_message = "Sorry, there was an error sending your order. Please try again later.";
error_log("MailService Error: " . ($result['error'] ?? 'Unknown error'));
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order <?php echo $product; ?> - <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Packaging Solutions'); ?></title>
<meta name="description" content="Order <?php echo $product; ?>.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&family=Lato:wght@400;700&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top" id="mainNav">
<div class="container">
<a class="navbar-brand" href="index.php"><img src="assets/pasted-20251210-201942-d2c32489.jpg" alt="<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'PackagingCo'); ?> Logo" style="height: 40px;"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.php#why-us">Why Us</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#offers">Offers</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#products">Products</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#faq">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<li class="nav-item"><a class="nav-link" href="partnership.php">Partnership</a></li>
<li class="nav-item"><a class="nav-link" href="admin.php">Admin</a></li>
</ul>
</div>
</div>
</nav>
<section class="page-section">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8 text-center">
<h2 class="mt-0">Order: <?php echo $product; ?></h2>
<hr class="divider">
<p class="text-muted mb-5">Fill out the form below to place your order.</p>
</div>
</div>
<div class="row gx-5 justify-content-center">
<div class="col-lg-8">
<?php if ($message_sent): ?>
<div class="alert alert-success text-center" role="alert">
Thank you! Your order has been received. We will contact you shortly.
</div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger text-center" role="alert">
<?php echo htmlspecialchars($error_message); ?>
</div>
<?php endif; ?>
<form id="orderForm" method="POST" action="order.php?product=<?php echo urlencode($product); ?>" enctype="multipart/form-data">
<div class="form-floating mb-3">
<input class="form-control" id="client_name" name="client_name" type="text" placeholder="Enter your name..." required />
<label for="client_name">Client Name</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="phone_number" name="phone_number" type="tel" placeholder="Enter your phone number..." required />
<label for="phone_number">Phone Number</label>
</div>
<div class="form-floating mb-3">
<textarea class="form-control" id="delivery_address" name="delivery_address" placeholder="Enter your delivery address" style="height: 10rem;" required></textarea>
<label for="delivery_address">Delivery Address</label>
</div>
<fieldset class="mb-3">
<legend class="h5">📦 Carton Order Details</legend>
<div class="form-floating mb-3">
<input class="form-control" id="model" name="model" type="text" placeholder="Enter model" />
<label for="model">Model</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="dimensions" name="dimensions" type="text" placeholder="e.g., 30x20x10" />
<label for="dimensions">Dimensions (cm)</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="thickness" name="thickness" type="text" placeholder="e.g., 3mm" />
<label for="thickness">Thickness</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="quantity" name="quantity" type="number" placeholder="Enter quantity" required min="1" />
<label for="quantity">Quantity</label>
</div>
</fieldset>
<div class="form-floating mb-3">
<textarea class="form-control" id="notes" name="notes" placeholder="Enter optional notes" style="height: 10rem;"></textarea>
<label for="notes">🗒 Notes (Optional)</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="delivery_date" name="delivery_date" type="date" />
<label for="delivery_date">📅 Delivery Preferred Date</label>
</div>
<div class="mb-3">
<label for="design_file" class="form-label">Drop your design (JPG, PNG)</label>
<input class="form-control" type="file" id="design_file" name="design_file" accept=".jpg,.jpeg,.png">
</div>
<div class="d-grid">
<button class="btn btn-primary btn-xl" id="submitButton" type="submit">Place Order</button>
</div>
<div class="text-center mt-3">
<button class="btn btn-outline-secondary" id="proFormaButton" type="button">Recevoir une facture pro-format</button>
</div>
</form>
</div>
</div>
</div>
</section>
<footer class="bg-light py-5">
<div class="container">
<div class="small text-center text-muted">Copyright &copy; <?php echo date("Y"); ?> - <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'PackagingCo'); ?></div>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
document.getElementById('proFormaButton').addEventListener('click', function() {
const email = prompt('Please enter your email address to receive the pro-forma invoice:');
if (email) {
const form = document.getElementById('orderForm');
let proFormaEmailInput = form.querySelector('input[name="pro_forma_email"]');
if (!proFormaEmailInput) {
proFormaEmailInput = document.createElement('input');
proFormaEmailInput.type = 'hidden';
proFormaEmailInput.name = 'pro_forma_email';
form.appendChild(proFormaEmailInput);
}
proFormaEmailInput.value = email;
let proFormaRequestInput = form.querySelector('input[name="pro_forma_request"]');
if (!proFormaRequestInput) {
proFormaRequestInput = document.createElement('input');
proFormaRequestInput.type = 'hidden';
proFormaRequestInput.name = 'pro_forma_request';
form.appendChild(proFormaRequestInput);
}
proFormaRequestInput.value = '1';
form.submit();
}
});
</script>
</body>
</html>