169 lines
6.3 KiB
PHP
169 lines
6.3 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'mail/MailService.php';
|
|
|
|
$message_sent = false;
|
|
$error_msg = '';
|
|
$services = [];
|
|
|
|
// Fetch services for dropdown
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT id, title_ar FROM services ORDER BY id ASC");
|
|
$services = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (Exception $e) {
|
|
// Silent fail for dropdown, but log it
|
|
error_log("DB Error: " . $e->getMessage());
|
|
}
|
|
|
|
// Handle Form Submission
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = trim($_POST['name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$phone = trim($_POST['phone'] ?? '');
|
|
$service_id = (int)($_POST['service_id'] ?? 0);
|
|
$details = trim($_POST['message'] ?? '');
|
|
|
|
if (empty($name) || empty($email)) {
|
|
$error_msg = 'يرجى ملء الاسم والبريد الإلكتروني.';
|
|
} else {
|
|
try {
|
|
// 1. Save to DB
|
|
$stmt = $pdo->prepare("INSERT INTO quotes (customer_name, customer_email, customer_phone, service_id, message) VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->execute([$name, $email, $phone, $service_id, $details]);
|
|
|
|
// 2. Send Email
|
|
// Using MailService as per context
|
|
$admin_email = getenv('MAIL_TO') ?: getenv('MAIL_FROM'); // Fallback
|
|
if ($admin_email) {
|
|
MailService::sendMail(
|
|
$admin_email,
|
|
"طلب تسعير جديد: $name",
|
|
"<p>عميل جديد طلب تسعير.</p><ul><li>الاسم: $name</li><li>Email: $email</li><li>الهاتف: $phone</li><li>التفاصيل: $details</li></ul>",
|
|
"طلب تسعير جديد من $name"
|
|
);
|
|
}
|
|
|
|
$message_sent = true;
|
|
} catch (Exception $e) {
|
|
$error_msg = 'حدث خطأ أثناء إرسال الطلب. يرجى المحاولة لاحقاً.';
|
|
error_log($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
$selected_service = isset($_GET['service']) ? (int)$_GET['service'] : 0;
|
|
|
|
$page_title = 'طلب عرض سعر - شركة الشحن واللوجستيات';
|
|
$extra_styles = '
|
|
<style>
|
|
.quote-box {
|
|
background: var(--surface);
|
|
padding: 3rem;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 20px rgba(0,0,0,0.05);
|
|
border-top: 5px solid var(--accent);
|
|
max-width: 800px;
|
|
margin: 4rem auto;
|
|
}
|
|
h1 { margin-top: 0; color: var(--primary); text-align: center; }
|
|
.form-group { margin-bottom: 1.5rem; }
|
|
label { display: block; margin-bottom: 0.5rem; font-weight: 600; }
|
|
input, select, textarea {
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 4px;
|
|
font-family: inherit;
|
|
box-sizing: border-box;
|
|
}
|
|
input:focus, select:focus, textarea:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 0 2px rgba(197, 160, 89, 0.2);
|
|
}
|
|
.btn-submit {
|
|
background: var(--accent);
|
|
color: white;
|
|
border: none;
|
|
padding: 1rem 2rem;
|
|
font-size: 1.1rem;
|
|
font-weight: 700;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
transition: background 0.3s;
|
|
}
|
|
.btn-submit:hover { background: #b08d4b; }
|
|
.alert {
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
margin-bottom: 2rem;
|
|
text-align: center;
|
|
}
|
|
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
|
|
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
|
|
</style>
|
|
';
|
|
|
|
require_once 'includes/header.php';
|
|
?>
|
|
|
|
<div class="container">
|
|
<div class="quote-box">
|
|
<h1>طلب عرض سعر</h1>
|
|
<p style="text-align: center; color: #64748B; margin-bottom: 2rem;">املأ النموذج أدناه وسيقوم فريق المبيعات بالتواصل معك في أقرب وقت.</p>
|
|
|
|
<?php if ($message_sent): ?>
|
|
<div class="alert alert-success">
|
|
تم استلام طلبك بنجاح! سنتواصل معك قريباً.
|
|
</div>
|
|
<?php elseif ($error_msg): ?>
|
|
<div class="alert alert-error">
|
|
<?php echo htmlspecialchars($error_msg); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$message_sent): ?>
|
|
<form method="POST" action="quote.php">
|
|
<div class="form-group">
|
|
<label for="name">الاسم الكامل *</label>
|
|
<input type="text" id="name" name="name" required placeholder="محمد أحمد">
|
|
</div>
|
|
|
|
<div class="form-group" style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
|
|
<div>
|
|
<label for="email">البريد الإلكتروني *</label>
|
|
<input type="email" id="email" name="email" required placeholder="name@company.com">
|
|
</div>
|
|
<div>
|
|
<label for="phone">رقم الهاتف</label>
|
|
<input type="text" id="phone" name="phone" placeholder="05xxxxxxxx">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="service_id">نوع الخدمة المطلوبة</label>
|
|
<select id="service_id" name="service_id">
|
|
<option value="0">-- اختر الخدمة --</option>
|
|
<?php foreach ($services as $s): ?>
|
|
<option value="<?php echo $s['id']; ?>" <?php echo ($selected_service == $s['id']) ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($s['title_ar']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
<option value="-1">أخرى / استشارة عامة</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="message">تفاصيل الشحنة / الرسالة</label>
|
|
<textarea id="message" name="message" rows="5" placeholder="أذكر الوزن التقريبي، الوجهة، وأي تفاصيل أخرى..."></textarea>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-submit">إرسال الطلب</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|