39038-vm/includes/layout.php
2026-03-08 02:54:06 +00:00

289 lines
20 KiB
PHP

<?php
require_once __DIR__ . '/app.php';
function render_header(string $title, string $active = ''): void
{
global $lang, $dir;
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
$toggleLang = $lang === 'ar' ? 'en' : 'ar';
$toggleLabel = $lang === 'ar' ? 'EN' : 'AR';
$appName = get_setting('company_name', t('app_name'));
$logoPath = get_setting('logo_path');
$faviconPath = get_setting('favicon_path');
?>
<!doctype html>
<html lang="<?= e($lang) ?>" dir="<?= e($dir) ?>">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?= e($title) ?> | <?= e($appName) ?></title>
<?php if ($faviconPath): ?>
<link rel="icon" href="<?= e($faviconPath) ?>">
<?php endif; ?>
<?php if ($projectDescription): ?>
<meta name="description" content="<?= e($projectDescription) ?>" />
<meta property="og:description" content="<?= e($projectDescription) ?>" />
<meta property="twitter:description" content="<?= e($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<meta property="og:image" content="<?= e($projectImageUrl) ?>" />
<meta property="twitter:image" content="<?= e($projectImageUrl) ?>" />
<?php endif; ?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<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=<?= time() ?>">
</head>
<body class="app-body">
<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom sticky-top shadow-sm py-3">
<div class="container">
<a class="navbar-brand fs-4 d-flex align-items-center" href="<?= e(url_with_lang('index.php')) ?>">
<?php if ($logoPath): ?>
<img src="<?= e($logoPath) ?>" alt="<?= e($appName) ?> Logo" height="32" class="me-2 rounded">
<?php else: ?>
<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" fill="currentColor" class="bi bi-box-seam me-1 text-primary" viewBox="0 0 16 16">
<path d="M8.186 1.113a.5.5 0 0 0-.372 0L1.846 3.5l2.404.961L10.404 2zm3.564 1.426L5.596 5 8 5.961 14.154 3.5zm3.25 1.7-6.5 2.6v7.922l6.5-2.6V4.24zM7.5 14.762V6.84L1 4.239v7.923zM7.443.184a1.5 1.5 0 0 1 1.114 0l7.129 2.852A.5.5 0 0 1 16 3.5v8.662a1 1 0 0 1-.629.928l-7.185 2.874a.5.5 0 0 1-.372 0L.63 13.09a1 1 0 0 1-.63-.928V3.5a.5.5 0 0 1 .314-.464z"/>
</svg>
<?php endif; ?>
<?= e($appName) ?>
</a>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#mainNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 fw-semibold">
<li class="nav-item">
<a class="nav-link <?= $active === 'home' ? 'active text-primary' : '' ?>" href="<?= e(url_with_lang('index.php')) ?>">
<?= e(t('nav_home')) ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $active === 'faq' ? 'active text-primary' : '' ?>" href="<?= e(url_with_lang('faq.php')) ?>">
FAQ
</a>
</li>
</ul>
<div class="d-flex align-items-center gap-3">
<div class="dropdown">
<?php if (isset($_SESSION['user_id'])): ?>
<a class="text-decoration-none text-muted fw-semibold dropdown-toggle" href="#" id="loginDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Account
</a>
<ul class="dropdown-menu dropdown-menu-end shadow-sm border-0 mt-3" aria-labelledby="loginDropdown" style="border-radius: 12px;">
<li>
<a class="dropdown-item py-2 <?= $active === 'profile' ? 'active' : '' ?>" href="<?= e(url_with_lang('profile.php')) ?>">
<i class="bi bi-person-circle text-primary me-2"></i>My Profile
</a>
</li>
<?php if (($_SESSION['user_role'] ?? '') === 'shipper'): ?>
<li>
<a class="dropdown-item py-2 <?= $active === 'shipper' ? 'active' : '' ?>" href="<?= e(url_with_lang('shipper_dashboard.php')) ?>">
<i class="bi bi-box-seam text-primary me-2"></i><?= e(t('nav_shipper')) ?>
</a>
</li>
<?php elseif (($_SESSION['user_role'] ?? '') === 'truck_owner'): ?>
<li>
<a class="dropdown-item py-2 <?= $active === 'owner' ? 'active' : '' ?>" href="<?= e(url_with_lang('truck_owner_dashboard.php')) ?>">
<i class="bi bi-truck text-primary me-2"></i><?= e(t('nav_owner')) ?>
</a>
</li>
<?php elseif (($_SESSION['user_role'] ?? '') === 'admin'): ?>
<li>
<a class="dropdown-item py-2 <?= $active === 'admin' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_dashboard.php')) ?>">
<i class="bi bi-speedometer2 text-primary me-2"></i><?= e(t('nav_admin')) ?>
</a>
</li>
<?php endif; ?>
<li><hr class="dropdown-divider"></li>
<li>
<a class="dropdown-item py-2 text-danger" href="<?= e(url_with_lang('logout.php')) ?>">
<i class="bi bi-box-arrow-right me-2"></i>Logout
</a>
</li>
</ul>
<?php else: ?>
<a class="text-decoration-none text-muted fw-semibold" href="<?= e(url_with_lang('login.php')) ?>">
Login
</a>
<?php endif; ?>
</div>
<a class="btn btn-sm btn-outline-dark rounded-pill px-3 fw-bold" href="<?= e(current_url_with_lang($toggleLang)) ?>">
<?= e($toggleLabel) ?>
</a>
<?php if (!isset($_SESSION['user_id'])): ?>
<a class="btn btn-primary btn-sm rounded-pill px-4 fw-bold shadow-sm d-none d-lg-block" href="<?= e(url_with_lang('register.php', ['role' => 'shipper'])) ?>">
Get Started
</a>
<?php endif; ?>
</div>
</div>
</div>
</nav>
<main class="container py-5">
<?php
}
function render_footer(): void
{
global $lang;
$appName = get_setting('company_name', t('app_name'));
$logoPath = get_setting('logo_path');
$companyEmail = get_setting('company_email', '');
$companyPhone = get_setting('company_phone', '');
$companyAddress = get_setting('company_address', '');
?>
</main>
<footer class="bg-white border-top py-5 mt-5">
<div class="container">
<div class="row g-4 mb-4">
<div class="col-md-4">
<div class="d-flex align-items-center mb-3">
<?php if ($logoPath): ?>
<img src="<?= e($logoPath) ?>" alt="<?= e($appName) ?> Logo" height="28" class="me-2 rounded">
<?php else: ?>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-box-seam me-2 text-primary" viewBox="0 0 16 16">
<path d="M8.186 1.113a.5.5 0 0 0-.372 0L1.846 3.5l2.404.961L10.404 2zm3.564 1.426L5.596 5 8 5.961 14.154 3.5zm3.25 1.7-6.5 2.6v7.922l6.5-2.6V4.24zM7.5 14.762V6.84L1 4.239v7.923zM7.443.184a1.5 1.5 0 0 1 1.114 0l7.129 2.852A.5.5 0 0 1 16 3.5v8.662a1 1 0 0 1-.629.928l-7.185 2.874a.5.5 0 0 1-.372 0L.63 13.09a1 1 0 0 1-.63-.928V3.5a.5.5 0 0 1 .314-.464z"/>
</svg>
<?php endif; ?>
<h5 class="fw-bold mb-0 text-dark"><?= e($appName) ?></h5>
</div>
<p class="text-muted small pe-md-4">
<?= e(t('motivation_phrase')) ?>
</p>
<?php if ($companyEmail || $companyPhone || $companyAddress): ?>
<div class="small text-muted mt-3">
<?php if ($companyAddress): ?>
<div class="mb-1"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" class="bi bi-geo-alt me-1" viewBox="0 0 16 16"><path d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A32 32 0 0 1 8 14.58a32 32 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10"/><path d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4m0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6"/></svg><?= e($companyAddress) ?></div>
<?php endif; ?>
<?php if ($companyPhone): ?>
<div class="mb-1"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" class="bi bi-telephone me-1" viewBox="0 0 16 16"><path d="M3.654 1.328a.678.678 0 0 0-1.015-.063L1.605 2.3c-.483.484-.661 1.169-.45 1.77a17.6 17.6 0 0 0 4.168 6.608 17.6 17.6 0 0 0 6.608 4.168c.601.211 1.286.033 1.77-.45l1.034-1.034a.678.678 0 0 0-.063-1.015l-2.307-1.794a.68.68 0 0 0-.58-.122l-2.19.547a1.75 1.75 0 0 1-1.657-.459L5.482 8.062a1.75 1.75 0 0 1-.46-1.657l.548-2.19a.68.68 0 0 0-.122-.58z"/></svg><a href="tel:<?= e($companyPhone) ?>" class="text-muted text-decoration-none"><?= e($companyPhone) ?></a></div>
<?php endif; ?>
<?php if ($companyEmail): ?>
<div class="mb-1"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" class="bi bi-envelope me-1" viewBox="0 0 16 16"><path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1zm13 2.383-4.708 2.825L15 11.105zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741M1 11.105l4.708-2.897L1 5.383z"/></svg><a href="mailto:<?= e($companyEmail) ?>" class="text-muted text-decoration-none"><?= e($companyEmail) ?></a></div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="col-md-2 offset-md-2">
<h6 class="fw-bold mb-3">Company</h6>
<ul class="list-unstyled text-muted small">
<li class="mb-2"><a href="#" class="text-decoration-none text-muted">About Us</a></li>
<li class="mb-2"><a href="#" class="text-decoration-none text-muted">Careers</a></li>
<li class="mb-2"><a href="#" class="text-decoration-none text-muted">Contact</a></li>
</ul>
</div>
<div class="col-md-2">
<h6 class="fw-bold mb-3">Resources</h6>
<ul class="list-unstyled text-muted small">
<li class="mb-2"><a href="<?= e(url_with_lang('faq.php')) ?>" class="text-decoration-none text-muted">Help Center / FAQ</a></li>
<li class="mb-2"><a href="<?= e(url_with_lang('terms.php')) ?>" class="text-decoration-none text-muted"><?= $lang === 'ar' ? 'شروط الخدمة' : 'Terms of Service' ?></a></li>
<li class="mb-2"><a href="<?= e(url_with_lang('privacy.php')) ?>" class="text-decoration-none text-muted"><?= $lang === 'ar' ? 'سياسة الخصوصية' : 'Privacy Policy' ?></a></li>
</ul>
</div>
<div class="col-md-2">
<h6 class="fw-bold mb-3">Language</h6>
<div class="d-flex gap-2">
<a href="<?= e(current_url_with_lang('en')) ?>" class="text-decoration-none <?= $lang === 'en' ? 'text-primary fw-bold' : 'text-muted' ?>">EN</a>
<span class="text-muted">|</span>
<a href="<?= e(current_url_with_lang('ar')) ?>" class="text-decoration-none <?= $lang === 'ar' ? 'text-primary fw-bold' : 'text-muted' ?>">AR</a>
</div>
</div>
</div>
<div class="d-flex flex-column flex-md-row justify-content-between align-items-center pt-4 border-top small text-muted">
<span>&copy; <?= date('Y') ?> <?= e($appName) ?>. All rights reserved.</span>
<span class="mt-2 mt-md-0"><?= e(t('footer_note')) ?></span>
</div>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="/assets/js/main.js?v=<?= time() ?>"></script>
</body>
</html>
<?php
}
function render_admin_sidebar(string $active = 'dashboard'): void
{
$settingsActive = in_array($active, ['company_profile', 'integrations']);
$locationsActive = in_array($active, ['countries', 'cities']);
$usersActive = in_array($active, ['shippers', 'truck_owners', 'register']);
$pagesActive = in_array($active, ['faqs', 'landing_pages']);
?>
<aside class="admin-sidebar panel p-4 shadow-sm border-0">
<h2 class="h5 fw-bold mb-4"><i class="bi bi-shield-lock me-2 text-primary"></i>Admin Panel</h2>
<nav class="nav flex-column gap-2">
<a class="admin-nav-link <?= $active === 'dashboard' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_dashboard.php')) ?>">
<i class="bi bi-speedometer2 me-2"></i>Dashboard
</a>
<a class="nav-link fw-bold text-muted text-uppercase mt-2 d-flex justify-content-between align-items-center p-2 rounded" style="cursor: pointer; font-size: 0.85rem;" data-bs-toggle="collapse" data-bs-target="#collapseSettings" aria-expanded="<?= $settingsActive ? 'true' : 'false' ?>">
<span><i class="bi bi-gear-fill me-2"></i>Settings</span>
<i class="bi bi-chevron-down small"></i>
</a>
<div class="collapse <?= $settingsActive ? 'show' : '' ?>" id="collapseSettings">
<div class="nav flex-column gap-1 ms-3 border-start ps-2 border-2">
<a class="admin-nav-link <?= $active === 'company_profile' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_company_profile.php')) ?>">
<i class="bi bi-building me-2"></i>Company Setting
</a>
<a class="admin-nav-link <?= $active === 'integrations' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_integrations.php')) ?>">
<i class="bi bi-plug me-2"></i>Integrations
</a>
</div>
</div>
<a class="nav-link fw-bold text-muted text-uppercase mt-2 d-flex justify-content-between align-items-center p-2 rounded" style="cursor: pointer; font-size: 0.85rem;" data-bs-toggle="collapse" data-bs-target="#collapseLocations" aria-expanded="<?= $locationsActive ? 'true' : 'false' ?>">
<span><i class="bi bi-geo-alt-fill me-2"></i>Locations</span>
<i class="bi bi-chevron-down small"></i>
</a>
<div class="collapse <?= $locationsActive ? 'show' : '' ?>" id="collapseLocations">
<div class="nav flex-column gap-1 ms-3 border-start ps-2 border-2">
<a class="admin-nav-link <?= $active === 'countries' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_countries.php')) ?>">
<i class="bi bi-globe-americas me-2"></i>Countries
</a>
<a class="admin-nav-link <?= $active === 'cities' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_cities.php')) ?>">
<i class="bi bi-pin-map me-2"></i>Cities
</a>
</div>
</div>
<a class="nav-link fw-bold text-muted text-uppercase mt-2 d-flex justify-content-between align-items-center p-2 rounded" style="cursor: pointer; font-size: 0.85rem;" data-bs-toggle="collapse" data-bs-target="#collapseUsers" aria-expanded="<?= $usersActive ? 'true' : 'false' ?>">
<span><i class="bi bi-people-fill me-2"></i>Users</span>
<i class="bi bi-chevron-down small"></i>
</a>
<div class="collapse <?= $usersActive ? 'show' : '' ?>" id="collapseUsers">
<div class="nav flex-column gap-1 ms-3 border-start ps-2 border-2">
<a class="admin-nav-link <?= $active === 'shippers' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_shippers.php')) ?>">
<i class="bi bi-box-seam me-2"></i>Shippers
</a>
<a class="admin-nav-link <?= $active === 'truck_owners' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_truck_owners.php')) ?>">
<i class="bi bi-truck me-2"></i>Truck Owners
</a>
<a class="admin-nav-link <?= $active === 'register' ? 'active' : '' ?>" href="<?= e(url_with_lang('register.php')) ?>">
<i class="bi bi-person-plus me-2"></i>User Registration
</a>
</div>
</div>
<a class="nav-link fw-bold text-muted text-uppercase mt-2 d-flex justify-content-between align-items-center p-2 rounded" style="cursor: pointer; font-size: 0.85rem;" data-bs-toggle="collapse" data-bs-target="#collapsePages" aria-expanded="<?= $pagesActive ? 'true' : 'false' ?>">
<span><i class="bi bi-file-earmark-text-fill me-2"></i>Pages</span>
<i class="bi bi-chevron-down small"></i>
</a>
<div class="collapse <?= $pagesActive ? 'show' : '' ?>" id="collapsePages">
<div class="nav flex-column gap-1 ms-3 border-start ps-2 border-2">
<a class="admin-nav-link <?= $active === 'faqs' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_faqs.php')) ?>">
<i class="bi bi-question-square me-2"></i>FAQs
</a>
<a class="admin-nav-link <?= $active === 'landing_pages' ? 'active' : '' ?>" href="<?= e(url_with_lang('admin_landing_pages.php')) ?>">
<i class="bi bi-layout-text-window me-2"></i>Landing Pages
</a>
</div>
</div>
</nav>
</aside>
<?php
}