exec(" CREATE TABLE IF NOT EXISTS notification_templates ( id INT AUTO_INCREMENT PRIMARY KEY, event_name VARCHAR(50) NOT NULL UNIQUE, email_subject_en VARCHAR(255), email_body_en TEXT, email_subject_ar VARCHAR(255), email_body_ar TEXT, whatsapp_body_en TEXT, whatsapp_body_ar TEXT, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); "); } catch (Throwable $e) { // Ignore if table exists or permission issue, subsequent queries will fail if critical } $action = $_GET['action'] ?? 'list'; $id = (int)($_GET['id'] ?? 0); $errors = []; $flash = get_flash(); if ($action === 'edit' && $id > 0) { // Handle Edit $stmt = db()->prepare("SELECT * FROM notification_templates WHERE id = ?"); $stmt->execute([$id]); $template = $stmt->fetch(); if (!$template) { set_flash('error', 'Template not found.'); header('Location: ' . url_with_lang('admin_notification_templates.php')); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $email_subject_en = trim($_POST['email_subject_en'] ?? ''); $email_body_en = trim($_POST['email_body_en'] ?? ''); $email_subject_ar = trim($_POST['email_subject_ar'] ?? ''); $email_body_ar = trim($_POST['email_body_ar'] ?? ''); $whatsapp_body_en = trim($_POST['whatsapp_body_en'] ?? ''); $whatsapp_body_ar = trim($_POST['whatsapp_body_ar'] ?? ''); if ($email_subject_en === '' || $email_body_en === '') { $errors[] = 'English subject and body are required.'; } if (!$errors) { $stmt = db()->prepare(" UPDATE notification_templates SET email_subject_en = ?, email_body_en = ?, email_subject_ar = ?, email_body_ar = ?, whatsapp_body_en = ?, whatsapp_body_ar = ? WHERE id = ? "); $stmt->execute([ $email_subject_en, $email_body_en, $email_subject_ar, $email_body_ar, $whatsapp_body_en, $whatsapp_body_ar, $id ]); set_flash('success', 'Template updated successfully.'); header('Location: ' . url_with_lang('admin_notification_templates.php')); exit; } } render_header('Edit Notification Template', 'admin', true); ?>

Edit Template:

Back to List
', $errors)) ?>
English
Use placeholders like {shipment_id}, {user_name}, {offer_price}.
Arabic

query("SELECT * FROM notification_templates ORDER BY event_name ASC"); $templates = $stmt->fetchAll(); render_header('Notification Templates', 'admin', true); ?>

Notification Templates

Event Name Subject (EN) Subject (AR) Actions
Edit