File: /home/muratemr/theotto.tr/includes/admin_layout.php
<?php
/**
* includes/admin_layout.php
*/
if (!defined('IN_ADMIN')) define('IN_ADMIN', true);
require_once __DIR__ . '/db.php';
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/csrf.php';
require_login();
// Dinamik BASE_URL: proje hangi dizinde olursa olsun çalışır
if (!defined('BASE_URL')) {
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$docRoot = rtrim(str_replace('\\','/', $_SERVER['DOCUMENT_ROOT'] ?? ''), '/');
$projDir = rtrim(str_replace('\\','/', dirname(__DIR__)), '/');
$subPath = str_replace($docRoot, '', $projDir);
define('BASE_URL', $scheme . '://' . $host . rtrim($subPath, '/'));
}
$_user = current_user();
$_restaurant_name = get_setting('restaurant_name', 'Restoran');
$_page_title = $page_title ?? 'Yönetim Paneli';
$_active_menu = $active_menu ?? '';
$_menu = [
'main' => [
['key' => 'dashboard', 'label' => 'Dashboard', 'icon' => 'bi-speedometer2', 'href' => 'dashboard.php'],
['key' => 'reservations', 'label' => 'Rezervasyonlar', 'icon' => 'bi-calendar-check','href' => 'reservations.php'],
['key' => 'customers', 'label' => 'Müşteriler', 'icon' => 'bi-people', 'href' => 'customers.php'],
['key' => 'customer_tags','label' => 'Müşteri Etiketleri', 'icon' => 'bi-tags', 'href' => 'customer_tags.php'],
],
'ops' => [
['key' => 'suppliers', 'label' => 'Tedarikçiler', 'icon' => 'bi-truck', 'href' => 'suppliers.php'],
['key' => 'daily_orders', 'label' => 'Günlük Siparişler', 'icon' => 'bi-cart3', 'href' => 'daily_orders.php'],
['key' => 'staff', 'label' => 'Personel Takip', 'icon' => 'bi-person-badge', 'href' => 'staff.php'],
],
'sys' => [
['key' => 'settings', 'label' => 'Site Ayarları', 'icon' => 'bi-gear', 'href' => 'settings.php'],
['key' => 'messages', 'label' => 'Mesaj Ayarları', 'icon' => 'bi-chat-dots', 'href' => 'messages.php'],
['key' => 'users', 'label' => 'Kullanıcılar', 'icon' => 'bi-person-gear', 'href' => 'users.php'],
],
];
function render_menu_item(array $item, string $active): string
{
if (!has_permission($item['key'])) return '';
$isActive = $item['key'] === $active ? ' active' : '';
$href = BASE_URL . '/admin/' . $item['href'];
return '<a href="' . htmlspecialchars($href, ENT_QUOTES) . '" class="nav-link' . $isActive . '">'
. '<i class="bi ' . htmlspecialchars($item['icon'], ENT_QUOTES) . '"></i> '
. htmlspecialchars($item['label'], ENT_QUOTES)
. '</a>';
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="<?= htmlspecialchars(csrf_token(), ENT_QUOTES) ?>">
<title><?= htmlspecialchars($_page_title, ENT_QUOTES) ?> - <?= htmlspecialchars($_restaurant_name, ENT_QUOTES) ?></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="<?= BASE_URL ?>/assets/css/style.css">
</head>
<body>
<div class="sidebar-overlay" id="sidebarOverlay"></div>
<div class="admin-wrapper">
<!-- ===== SIDEBAR ===== -->
<nav class="sidebar" id="sidebar">
<div class="sidebar-logo">
<div class="logo-icon"><i class="bi bi-shop"></i></div>
<div>
<div class="logo-text"><?= htmlspecialchars($_restaurant_name, ENT_QUOTES) ?></div>
<div class="logo-sub">Yönetim Paneli</div>
</div>
</div>
<div class="sidebar-nav">
<div class="nav-section-title">Ana Menü</div>
<?php foreach ($_menu['main'] as $item): echo render_menu_item($item, $_active_menu); endforeach; ?>
<div class="nav-section-title">Operasyon</div>
<?php foreach ($_menu['ops'] as $item): echo render_menu_item($item, $_active_menu); endforeach; ?>
<div class="nav-section-title">Sistem</div>
<?php foreach ($_menu['sys'] as $item): echo render_menu_item($item, $_active_menu); endforeach; ?>
</div>
<div class="sidebar-footer">
<div class="d-flex align-items-center gap-2 mb-2">
<i class="bi bi-person-circle" style="font-size:18px;color:var(--gold)"></i>
<div>
<div style="font-size:12px;color:var(--text-secondary);line-height:1.2"><?= htmlspecialchars($_user['full_name'], ENT_QUOTES) ?></div>
<div style="font-size:11px;color:var(--text-muted)"><?= htmlspecialchars(ucfirst($_user['role']), ENT_QUOTES) ?></div>
</div>
</div>
<div class="d-flex gap-2">
<a href="<?= BASE_URL ?>/admin/profile.php" class="btn btn-sm btn-outline-secondary w-50 py-1 fs-12">
<i class="bi bi-person me-1"></i>Profil
</a>
<a href="<?= BASE_URL ?>/admin/logout.php" class="btn btn-sm btn-outline-danger w-50 py-1 fs-12">
<i class="bi bi-box-arrow-left me-1"></i>Çıkış
</a>
</div>
</div>
</nav>
<!-- ===== MAIN ===== -->
<div class="main-content">
<div class="topbar">
<button class="btn-sidebar-toggle" id="sidebarToggle">
<i class="bi bi-list"></i>
</button>
<div class="topbar-title"><?= htmlspecialchars($_page_title, ENT_QUOTES) ?></div>
<a href="<?= BASE_URL ?>/" target="_blank" class="btn btn-sm btn-outline-secondary fs-12" title="Siteyi görüntüle">
<i class="bi bi-box-arrow-up-right"></i>
</a>
</div>
<div class="content-area">