query("SELECT * FROM outlets ORDER BY name")->fetchAll(PDO::FETCH_ASSOC); } else { $stmt = $pdo->prepare(" SELECT o.* FROM outlets o JOIN user_outlets uo ON o.id = uo.outlet_id WHERE uo.user_id = ? ORDER BY o.name "); $stmt->execute([$currentUser['id']]); $outlets = $stmt->fetchAll(PDO::FETCH_ASSOC); } $current_outlet_id = isset($_GET['outlet_id']) ? (int)$_GET['outlet_id'] : (count($outlets) > 0 ? (int)$outlets[0]['id'] : 1); // Security check: ensure user has access to this outlet if (!has_permission('all')) { $has_access = false; foreach ($outlets as $o) { if ($o['id'] == $current_outlet_id) { $has_access = true; break; } } if (!$has_access && count($outlets) > 0) { $current_outlet_id = (int)$outlets[0]['id']; } } $settings = get_company_settings(); ?> Kitchen Display System

Kitchen Display

Loading orders...
`; win.document.write(html); win.document.close(); } function updateStatus(orderId, newStatus) { if (!CAN_EDIT) return; Swal.fire({ title: 'Update Status?', text: `Move order #${orderId} to ${newStatus}?`, icon: 'question', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, update it!' }).then((result) => { if (result.isConfirmed) { performUpdate(orderId, newStatus); } }); } async function performUpdate(orderId, newStatus) { try { const response = await fetch('api/kitchen.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ order_id: orderId, status: newStatus }) }); const result = await response.json(); if (result.success) { fetchOrders(); Swal.fire({ icon: 'success', title: 'Updated!', text: `Order #${orderId} moved to ${newStatus}`, timer: 1500, showConfirmButton: false }); } else { Swal.fire('Error', result.error || 'Failed to update', 'error'); } } catch (error) { console.error('Error updating status:', error); Swal.fire('Error', 'Failed to connect to server', 'error'); } } async function serveAll() { if (!CAN_EDIT) return; const result = await Swal.fire({ title: 'Serve All Orders?', text: "This will mark all active orders as completed and clear the screen.", icon: 'warning', showCancelButton: true, confirmButtonColor: '#d33', cancelButtonColor: '#3085d6', confirmButtonText: 'Yes, Serve All!' }); if (result.isConfirmed) { try { const response = await fetch('api/kitchen.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'serve_all', outlet_id: OUTLET_ID }) }); const data = await response.json(); if (data.success) { fetchOrders(); Swal.fire('Cleared!', 'All orders have been served.', 'success'); } else { Swal.fire('Error', data.error || 'Failed to clear orders', 'error'); } } catch (error) { console.error('Error:', error); Swal.fire('Error', 'Server connection failed', 'error'); } } } const outletSelector = document.getElementById('outlet-selector'); if (outletSelector) { outletSelector.addEventListener('change', function() { window.location.href = '?outlet_id=' + this.value; }); } setInterval(() => { const clock = document.getElementById('clock'); if (clock) clock.textContent = new Date().toLocaleTimeString(); }, 1000); fetchOrders(); setInterval(fetchOrders, 10000);