prepare("SELECT COUNT(*) FROM orders WHERE order_no = ?"); $stmt->execute([$order_no]); $exists = $stmt->fetchColumn() > 0; } while ($exists); return $order_no; } /** * Fetch the single admin settings row */ function get_admin_settings($pdo) { $stmt = $pdo->prepare("SELECT * FROM settings WHERE id = 1 LIMIT 1"); $stmt->execute(); return $stmt->fetch(); } /** * Clean phone numbers to keep only digits */ function clean_phone_number($number) { // Remove all non-numeric characters $cleaned = preg_replace('/[^0-9]/', '', $number); return $cleaned; } /** * Auto generate order message for WhatsApp */ function generate_whatsapp_message($order) { $name = $order['customer_name'] ?? ''; $phone = $order['phone'] ?? ''; $whatsapp = $order['whatsapp'] ?? ''; $email = $order['email'] ?? ''; $curtain_type = $order['curtain_type'] ?? ''; $fabric = $order['fabric'] ?? ''; $color = $order['color'] ?? ''; $width = $order['width'] ?? ''; $height = $order['height'] ?? ''; $quantity = $order['quantity'] ?? ''; $notes = !empty($order['notes']) ? $order['notes'] : 'None'; return "Hello Royal Curtain, I would like to place an order. Customer Name: {$name} Phone: {$phone} WhatsApp: {$whatsapp} Email: {$email} Curtain Type: {$curtain_type} Fabric: {$fabric} Color: {$color} Size: Width: {$width} Height: {$height} Quantity: {$quantity} Additional Notes: {$notes} Thank You."; } /** * Generate regular WhatsApp link (wa.me) */ function get_whatsapp_link($phone, $message = '') { $cleaned_phone = clean_phone_number($phone); if (!empty($message)) { return "https://wa.me/" . $cleaned_phone . "?text=" . urlencode($message); } return "https://wa.me/" . $cleaned_phone; } /** * Generate WhatsApp Web link */ function get_whatsapp_web_link($phone, $message = '') { $cleaned_phone = clean_phone_number($phone); if (!empty($message)) { return "https://web.whatsapp.com/send?phone=" . $cleaned_phone . "&text=" . urlencode($message); } return "https://web.whatsapp.com/send?phone=" . $cleaned_phone; } /** * Render Bootstrap badge for order status */ function render_status_badge($status) { $class = ''; switch ($status) { case 'Pending': $class = 'bg-warning text-dark'; break; case 'Confirmed': $class = 'bg-info text-dark'; break; case 'Processing': $class = 'bg-primary text-light'; break; case 'Completed': $class = 'bg-success text-light'; break; case 'Cancelled': $class = 'bg-danger text-light'; break; default: $class = 'bg-secondary text-light'; } return "" . htmlspecialchars($status) . ""; } /** * Sanitize output */ function s($str) { return htmlspecialchars($str ?? '', ENT_QUOTES, 'UTF-8'); } ?>