39728-vm/includes/header.php
2026-04-19 10:09:23 +00:00

208 lines
13 KiB
PHP

<?php
require_once __DIR__ . '/app.php';
$user = current_user();
$activeNav = $activeNav ?? 'dashboard';
$pageTitle = $pageTitle ?? app_name();
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
$projectName = $_SERVER['PROJECT_NAME'] ?? app_name();
$metaDescription = $projectDescription !== '' ? $projectDescription : tr('منصة مبيعات ومخزون متعددة الفروع لحلوى الريامي.', 'Multi-branch sweets sales and stock workspace for Al Riyami Sweets.');
$flash = pull_flash();
$assetVersion = date('YmdHi');
// Determine if we are on a public page (like login)
$isPublic = !isset($user) || !$user;
?>
<!doctype html>
<html lang="<?= h(current_lang()) ?>" dir="<?= is_rtl() ? 'rtl' : 'ltr' ?>">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?= h($pageTitle) ?> · <?= h($projectName) ?></title>
<?php if ($projectDescription): ?>
<meta name="description" content='<?= h($projectDescription) ?>' />
<meta property="og:description" content="<?= h($projectDescription) ?>" />
<meta property="twitter:description" content="<?= h($projectDescription) ?>" />
<?php else: ?>
<meta name="description" content="<?= h($metaDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<meta property="og:image" content="<?= h($projectImageUrl) ?>" />
<meta property="twitter:image" content="<?= h($projectImageUrl) ?>" />
<?php endif; ?>
<meta name="theme-color" content="#343a40" />
<?php if (get_setting('company_favicon')): ?>
<link rel="icon" href="<?= h(get_setting('company_favicon')) ?>">
<?php endif; ?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<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=<?= h($assetVersion) ?>">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body class="<?= $isPublic ? 'auth-body' : '' ?>">
<?php if ($isPublic): ?>
<!-- Public Layout for Login -->
<main class="container">
<?php else: ?>
<!-- Private Admin Layout -->
<div class="d-flex" id="wrapper">
<!-- Sidebar -->
<div class="border-end bg-dark text-white shadow-sm" id="sidebar-wrapper">
<div class="sidebar-heading text-center py-4 fs-5 fw-bold text-uppercase border-bottom border-secondary d-flex flex-column align-items-center">
<?php if (get_setting('company_logo')): ?>
<img src="<?= h(get_setting('company_logo')) ?>" alt="Logo" style="max-height: 50px; margin-bottom: 10px; background: white; padding: 5px; border-radius: 5px;">
<?php else: ?>
<i class="bi bi-shop me-2 fs-2 mb-2"></i>
<?php endif; ?>
<span><?= h(current_lang() === 'ar' ? get_setting('company_name_ar', 'حلوى الريامي') : get_setting('company_name_en', 'Al Riyami Sweets')) ?></span>
</div>
<div class="p-3 text-center border-bottom border-secondary">
<div class="fw-semibold"><?= h(current_lang() === 'ar' ? $user['name_ar'] : $user['name_en']) ?></div>
<div class="text-white-50 small"><?= h(role_label($user['role'])) ?> · <?= h(branch_label($user['branch_code'])) ?></div>
</div>
<div class="list-group list-group-flush my-3 pb-5">
<a class="list-group-item list-group-item-action <?= $activeNav === 'dashboard' ? 'active' : '' ?>" href="<?= h(url_for('index.php')) ?>">
<i class="bi bi-speedometer2"></i> <?= h(tr('لوحة التحكم', 'Dashboard')) ?>
</a>
<?php if (has_permission('stock', 'show') || has_permission('categories', 'show') || has_permission('units', 'show')): ?>
<!-- المخزون (Inventory) - Now First -->
<a class="list-group-item list-group-item-action <?= in_array($activeNav, ['stock', 'categories', 'units']) ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#collapseStock" role="button" aria-expanded="<?= in_array($activeNav, ['stock', 'categories', 'units']) ? 'true' : 'false' ?>" aria-controls="collapseStock">
<div class="d-flex justify-content-between align-items-center w-100">
<span><i class="bi bi-box-seam"></i> <?= h(tr('المخزون', 'Inventory')) ?></span>
<i class="bi bi-chevron-down toggle-icon" style="transition: transform 0.2s;"></i>
</div>
</a>
<div class="collapse <?= in_array($activeNav, ['stock', 'categories', 'units']) ? 'show' : '' ?>" id="collapseStock">
<div class="list-group list-group-flush" style="background-color: rgba(0,0,0,0.15);">
<a class="list-group-item list-group-item-action <?= $activeNav === 'stock' ? 'active' : '' ?>" href="<?= h(url_for('stock.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('قائمة الأصناف', 'Items List')) ?>
</a>
<a class="list-group-item list-group-item-action <?= $activeNav === 'categories' ? 'active' : '' ?>" href="<?= h(url_for('categories.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('التصنيفات', 'Categories')) ?>
</a>
<a class="list-group-item list-group-item-action <?= $activeNav === 'units' ? 'active' : '' ?>" href="<?= h(url_for('units.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('الوحدات', 'Units')) ?>
</a>
</div>
</div>
<?php endif; ?>
<?php if (has_permission('sales', 'show') || has_permission('normal_sale', 'show') || has_permission('pos', 'show')): ?>
<!-- المبيعات (Sales) - Now Collapsible -->
<a class="list-group-item list-group-item-action <?= in_array($activeNav, ['sales', 'normal', 'pos']) ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#collapseSales" role="button" aria-expanded="<?= in_array($activeNav, ['sales', 'normal', 'pos']) ? 'true' : 'false' ?>" aria-controls="collapseSales">
<div class="d-flex justify-content-between align-items-center w-100">
<span><i class="bi bi-cart"></i> <?= h(tr('المبيعات', 'Sales')) ?></span>
<i class="bi bi-chevron-down toggle-icon" style="transition: transform 0.2s;"></i>
</div>
</a>
<div class="collapse <?= in_array($activeNav, ['sales', 'normal', 'pos']) ? 'show' : '' ?>" id="collapseSales">
<div class="list-group list-group-flush" style="background-color: rgba(0,0,0,0.15);">
<a class="list-group-item list-group-item-action <?= $activeNav === 'sales' ? 'active' : '' ?>" href="<?= h(url_for('sales.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('قائمة الفواتير', 'Invoice list')) ?>
</a>
<a class="list-group-item list-group-item-action <?= $activeNav === 'normal' ? 'active' : '' ?>" href="<?= h(url_for('normal_sale.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('فاتورة جديدة', 'New invoice')) ?>
</a>
<a class="list-group-item list-group-item-action <?= $activeNav === 'pos' ? 'active' : '' ?>" href="<?= h(url_for('pos.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('نقاط البيع', 'POS')) ?>
</a>
</div>
</div>
<?php endif; ?>
<?php if (has_permission('purchases', 'show')): ?>
<a class="list-group-item list-group-item-action <?= in_array($activeNav, ['purchases', 'new_purchase']) ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#collapsePurchases" role="button" aria-expanded="<?= in_array($activeNav, ['purchases', 'new_purchase']) ? 'true' : 'false' ?>" aria-controls="collapsePurchases">
<div class="d-flex justify-content-between align-items-center w-100">
<span><i class="bi bi-bag-plus"></i> <?= h(tr('المشتريات', 'Purchases')) ?></span>
<i class="bi bi-chevron-down toggle-icon" style="transition: transform 0.2s;"></i>
</div>
</a>
<div class="collapse <?= in_array($activeNav, ['purchases', 'new_purchase']) ? 'show' : '' ?>" id="collapsePurchases">
<div class="list-group list-group-flush" style="background-color: rgba(0,0,0,0.15);">
<a class="list-group-item list-group-item-action <?= $activeNav === 'purchases' ? 'active' : '' ?>" href="<?= h(url_for('purchases.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('قائمة المشتريات', 'Purchase list')) ?>
</a>
<a class="list-group-item list-group-item-action <?= $activeNav === 'new_purchase' ? 'active' : '' ?>" href="<?= h(url_for('new_purchase.php')) ?>" style="padding-left: 2.5rem; padding-right: 2.5rem;">
<i class="bi bi-dot"></i> <?= h(tr('فاتورة مشتريات جديدة', 'New purchase')) ?>
</a>
</div>
</div>
<?php endif; ?>
<a class="list-group-item list-group-item-action <?= $activeNav === 'suppliers' ? 'active' : '' ?>" href="<?= h(url_for('suppliers.php')) ?>">
<i class="bi bi-truck"></i> <?= h(tr('الموردون', 'Suppliers')) ?>
</a>
<a class="list-group-item list-group-item-action <?= $activeNav === 'customers' ? 'active' : '' ?>" href="<?= h(url_for('customers.php')) ?>">
<i class="bi bi-people-fill"></i> <?= h(tr('العملاء', 'Customers')) ?>
</a>
<?php if (has_permission('reports', 'show')): ?>
<a class="list-group-item list-group-item-action <?= $activeNav === 'reports' ? 'active' : '' ?>" href="<?= h(url_for('reports.php')) ?>">
<i class="bi bi-bar-chart"></i> <?= h(tr('التقارير', 'Reports')) ?>
</a>
<?php endif; ?>
<?php if (has_permission('users', 'show')): ?>
<a class="list-group-item list-group-item-action <?= $activeNav === 'users' ? 'active' : '' ?>" href="<?= h(url_for('users.php')) ?>">
<i class="bi bi-people"></i> <?= h(tr('المستخدمون والأدوار', 'Users & Roles')) ?>
</a>
<?php endif; ?>
<?php if (has_permission('settings', 'show')): ?>
<a class="list-group-item list-group-item-action" href="#" data-bs-toggle="modal" data-bs-target="#settingsModal">
<i class="bi bi-gear"></i> <?= h(tr('إعدادات الشركة', 'Company Settings')) ?>
</a>
<?php endif; ?>
</div>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom top-navbar px-3">
<div class="d-flex align-items-center justify-content-between w-100">
<div class="d-flex align-items-center">
<button class="btn btn-outline-secondary me-2" id="menu-toggle"><i class="bi bi-list"></i></button>
<h4 class="mb-0 ms-2 fw-semibold d-none d-md-block"><?= h($pageTitle) ?></h4>
</div>
<div class="d-flex align-items-center gap-3">
<div class="language-switcher btn-group" role="group">
<a class="btn btn-sm <?= current_lang() === 'ar' ? 'btn-primary' : 'btn-outline-primary' ?>" href="<?= h(url_for(basename($_SERVER['PHP_SELF']), array_merge($_GET, ['lang' => 'ar']))) ?>">AR</a>
<a class="btn btn-sm <?= current_lang() === 'en' ? 'btn-primary' : 'btn-outline-primary' ?>" href="<?= h(url_for(basename($_SERVER['PHP_SELF']), array_merge($_GET, ['lang' => 'en']))) ?>">EN</a>
</div>
<div class="dropdown">
<button class="btn btn-light dropdown-toggle border" type="button" id="userMenu" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-person-circle"></i> <?= h(current_lang() === 'ar' ? $user['name_ar'] : $user['name_en']) ?>
</button>
<ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="userMenu">
<li><a class="dropdown-item" href="<?= h(url_for('logout.php')) ?>"><i class="bi bi-box-arrow-right text-danger"></i> <?= h(tr('تسجيل الخروج', 'Sign out')) ?></a></li>
</ul>
</div>
</div>
</div>
</nav>
<div class="container-fluid p-4">
<!-- Flash messages integration using SweetAlert2 -->
<?php if ($flash): ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
Swal.fire({
icon: '<?= h($flash['type']) === "danger" ? "error" : (h($flash['type']) === "warning" ? "warning" : "success") ?>',
title: '<?= h($flash['message']) ?>',
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true
});
});
</script>
<?php endif; ?>
<?php endif; ?>