387 lines
16 KiB
PHP
387 lines
16 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
function isLoggedIn() {
|
|
return isset($_SESSION['user_id']);
|
|
}
|
|
|
|
function isAdmin() {
|
|
return isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin';
|
|
}
|
|
|
|
function canView() {
|
|
return isAdmin() || (isset($_SESSION['can_view']) && $_SESSION['can_view'] == 1);
|
|
}
|
|
|
|
function canAdd() {
|
|
return isAdmin() || (isset($_SESSION['can_add']) && $_SESSION['can_add'] == 1);
|
|
}
|
|
|
|
function canEdit() {
|
|
return isAdmin() || (isset($_SESSION['can_edit']) && $_SESSION['can_edit'] == 1);
|
|
}
|
|
|
|
function canDelete() {
|
|
return isAdmin() || (isset($_SESSION['can_delete']) && $_SESSION['can_delete'] == 1);
|
|
}
|
|
|
|
function redirect($path) {
|
|
header("Location: $path");
|
|
exit;
|
|
}
|
|
|
|
// Allowed pages when not logged in
|
|
$allowed_pages = ['login.php', 'forgot_password.php'];
|
|
if (!isLoggedIn() && !in_array(basename($_SERVER['PHP_SELF']), $allowed_pages)) {
|
|
redirect('login.php');
|
|
}
|
|
|
|
// Fetch charity settings
|
|
$stmt = db()->query("SELECT * FROM charity_settings WHERE id = 1");
|
|
$charity = $stmt->fetch();
|
|
$charity_name = $charity['charity_name'] ?? 'بريد الجمعية';
|
|
$charity_logo = $charity['charity_logo'] ?? null;
|
|
$charity_favicon = $charity['charity_favicon'] ?? null;
|
|
|
|
// Fetch current user info if logged in
|
|
$current_user = null;
|
|
if (isLoggedIn()) {
|
|
$stmt = db()->prepare("SELECT full_name, profile_image, theme, can_view, can_add, can_edit, can_delete FROM users WHERE id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$current_user = $stmt->fetch();
|
|
|
|
// Update session permissions
|
|
$_SESSION['can_view'] = $current_user['can_view'];
|
|
$_SESSION['can_add'] = $current_user['can_add'];
|
|
$_SESSION['can_edit'] = $current_user['can_edit'];
|
|
$_SESSION['can_delete'] = $current_user['can_delete'];
|
|
}
|
|
$user_theme = $current_user['theme'] ?? 'light';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="ar" dir="rtl" data-theme="<?= htmlspecialchars($user_theme) ?>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= htmlspecialchars($charity_name) ?></title>
|
|
<?php if ($charity_favicon): ?>
|
|
<link rel="icon" type="image/x-icon" href="<?= $charity_favicon ?>?v=<?= time() ?>">
|
|
<?php endif; ?>
|
|
<!-- Bootstrap 5 RTL CSS -->
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css?v=<?php echo time(); ?>">
|
|
<!-- Google Fonts: Cairo -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<!-- Font Awesome -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css?v=<?php echo time(); ?>">
|
|
|
|
<!-- JS Libraries (Loaded in head to support inline onclick handlers) -->
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js?v=<?php echo time(); ?>"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script src="https://cdn.ckeditor.com/ckeditor5/36.0.1/classic/ckeditor.js?v=<?php echo time(); ?>"></script>
|
|
|
|
<style>
|
|
:root {
|
|
/* Light Theme (Default) */
|
|
--bg-color: #f8f9fa;
|
|
--text-color: #212529;
|
|
--sidebar-bg: #ffffff;
|
|
--card-bg: #ffffff;
|
|
--nav-link-color: #333333;
|
|
--nav-link-hover-bg: #f0f7ff;
|
|
--primary-color: #0d6efd;
|
|
--border-color: rgba(0, 0, 0, 0.075);
|
|
--muted-text: #6c757d;
|
|
--input-bg: #ffffff;
|
|
--input-border: #dee2e6;
|
|
}
|
|
|
|
[data-theme="dark"] {
|
|
--bg-color: #121212;
|
|
--text-color: #e0e0e0;
|
|
--sidebar-bg: #1e1e1e;
|
|
--card-bg: #1e1e1e;
|
|
--nav-link-color: #bbbbbb;
|
|
--nav-link-hover-bg: #2c2c2c;
|
|
--primary-color: #3788ff;
|
|
--border-color: rgba(255, 255, 255, 0.1);
|
|
--muted-text: #999999;
|
|
--input-bg: #2d2d2d;
|
|
--input-border: #444444;
|
|
}
|
|
|
|
[data-theme="midnight"] {
|
|
--bg-color: #0b0e14;
|
|
--text-color: #cbd5e0;
|
|
--sidebar-bg: #1a202c;
|
|
--card-bg: #1a202c;
|
|
--nav-link-color: #a0aec0;
|
|
--nav-link-hover-bg: #2d3748;
|
|
--primary-color: #63b3ed;
|
|
--border-color: rgba(255, 255, 255, 0.05);
|
|
--muted-text: #718096;
|
|
--input-bg: #2d3748;
|
|
--input-border: #4a5568;
|
|
}
|
|
|
|
[data-theme="forest"] {
|
|
--bg-color: #f0f4f0;
|
|
--text-color: #2d372d;
|
|
--sidebar-bg: #ffffff;
|
|
--card-bg: #ffffff;
|
|
--nav-link-color: #4a5d4a;
|
|
--nav-link-hover-bg: #e8f0e8;
|
|
--primary-color: #2d6a4f;
|
|
--border-color: rgba(0, 0, 0, 0.05);
|
|
--muted-text: #6b8e6b;
|
|
--input-bg: #ffffff;
|
|
--input-border: #ccd5cc;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Cairo', sans-serif;
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 100vh;
|
|
transition: background-color 0.3s ease, color 0.3s ease;
|
|
}
|
|
|
|
/* Bootstrap Overrides */
|
|
.bg-white { background-color: var(--card-bg) !important; }
|
|
.bg-light { background-color: var(--bg-color) !important; }
|
|
.text-dark { color: var(--text-color) !important; }
|
|
.text-muted { color: var(--muted-text) !important; }
|
|
.border-bottom { border-bottom: 1px solid var(--border-color) !important; }
|
|
.border-top { border-top: 1px solid var(--border-color) !important; }
|
|
.border { border: 1px solid var(--border-color) !important; }
|
|
.list-group-item { background-color: var(--card-bg); border-color: var(--border-color); color: var(--text-color); }
|
|
.form-control, .form-select { background-color: var(--input-bg); border-color: var(--input-border); color: var(--text-color); }
|
|
.form-control:focus, .form-select:focus { background-color: var(--input-bg); color: var(--text-color); border-color: var(--primary-color); }
|
|
.table { color: var(--text-color); border-color: var(--border-color); }
|
|
.table thead th { background-color: var(--bg-color); color: var(--text-color); }
|
|
.table-hover tbody tr:hover { background-color: var(--nav-link-hover-bg); }
|
|
|
|
.container-fluid.main-container {
|
|
flex: 1;
|
|
}
|
|
.sidebar {
|
|
min-height: 100vh;
|
|
background: var(--sidebar-bg);
|
|
box-shadow: 0 0.125rem 0.25rem var(--border-color);
|
|
padding-top: 1rem;
|
|
transition: background-color 0.3s ease;
|
|
}
|
|
.nav-link {
|
|
color: var(--nav-link-color);
|
|
font-weight: 600;
|
|
padding: 0.8rem 1.5rem;
|
|
transition: all 0.2s ease;
|
|
}
|
|
.nav-link:hover, .nav-link.active {
|
|
background-color: var(--nav-link-hover-bg);
|
|
color: var(--primary-color);
|
|
border-left: 4px solid var(--primary-color);
|
|
}
|
|
.card {
|
|
border: none;
|
|
box-shadow: 0 0.125rem 0.25rem var(--border-color);
|
|
border-radius: 10px;
|
|
background-color: var(--card-bg);
|
|
color: var(--text-color);
|
|
transition: background-color 0.3s ease;
|
|
}
|
|
.btn-primary {
|
|
background-color: var(--primary-color);
|
|
border: none;
|
|
}
|
|
.btn-primary:hover {
|
|
background-color: var(--primary-color);
|
|
filter: brightness(90%);
|
|
}
|
|
|
|
.status-received { background-color: #e9ecef; color: #495057; }
|
|
.status-in_progress { background-color: #cff4fc; color: #055160; }
|
|
.status-closed { background-color: #d1e7dd; color: #0f5132; }
|
|
|
|
.modal-content {
|
|
background-color: var(--card-bg);
|
|
color: var(--text-color);
|
|
}
|
|
.modal-header.bg-primary {
|
|
background-color: var(--primary-color) !important;
|
|
}
|
|
|
|
.user-profile-img {
|
|
width: 80px;
|
|
height: 80px;
|
|
border-radius: 50%;
|
|
object-fit: cover;
|
|
border: 2px solid var(--primary-color);
|
|
}
|
|
.charity-logo {
|
|
max-width: 100%;
|
|
max-height: 60px;
|
|
}
|
|
.navbar {
|
|
background-color: var(--sidebar-bg) !important;
|
|
border-color: var(--border-color) !important;
|
|
}
|
|
.navbar-brand {
|
|
color: var(--text-color) !important;
|
|
}
|
|
|
|
/* Theme Switcher Styles */
|
|
.theme-switcher {
|
|
padding: 1rem 1.5rem;
|
|
border-top: 1px solid var(--border-color);
|
|
margin-top: 1rem;
|
|
}
|
|
.theme-options {
|
|
display: flex;
|
|
gap: 10px;
|
|
justify-content: center;
|
|
margin-top: 10px;
|
|
}
|
|
.theme-btn {
|
|
width: 24px;
|
|
height: 24px;
|
|
border-radius: 50%;
|
|
border: 2px solid transparent;
|
|
cursor: pointer;
|
|
transition: transform 0.2s;
|
|
}
|
|
.theme-btn:hover {
|
|
transform: scale(1.2);
|
|
}
|
|
.theme-btn.active {
|
|
border-color: var(--primary-color);
|
|
}
|
|
.theme-btn-light { background-color: #f8f9fa; border: 1px solid #ddd; }
|
|
.theme-btn-dark { background-color: #121212; }
|
|
.theme-btn-midnight { background-color: #0b0e14; }
|
|
.theme-btn-forest { background-color: #2d6a4f; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container-fluid main-container">
|
|
<div class="row">
|
|
<?php if (isLoggedIn()): ?>
|
|
<!-- Sidebar -->
|
|
<nav class="col-md-3 col-lg-2 d-md-block sidebar">
|
|
<div class="position-sticky">
|
|
<div class="text-center mb-4">
|
|
<?php if ($charity_logo): ?>
|
|
<img src="<?= $charity_logo ?>?v=<?= time() ?>" alt="Logo" class="charity-logo mb-2">
|
|
<?php endif; ?>
|
|
<h5 class="fw-bold mt-2"><?= htmlspecialchars($charity_name) ?></h5>
|
|
</div>
|
|
|
|
<div class="user-info text-center mb-4 py-3 border-bottom border-top">
|
|
<?php if ($current_user['profile_image']): ?>
|
|
<img src="<?= $current_user['profile_image'] ?>?v=<?= time() ?>" alt="Profile" class="user-profile-img mb-2">
|
|
<?php else: ?>
|
|
<div class="user-profile-img bg-light mx-auto d-flex align-items-center justify-content-center mb-2">
|
|
<i class="fas fa-user text-secondary fa-2x"></i>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="small fw-bold"><?= htmlspecialchars($current_user['full_name'] ?? $_SESSION['username']) ?></div>
|
|
<div class="small text-muted">
|
|
<?php
|
|
if ($_SESSION['user_role'] === 'admin') echo 'مدير النظام';
|
|
elseif ($_SESSION['user_role'] === 'clerk') echo 'كاتب';
|
|
else echo 'موظف';
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= (basename($_SERVER['PHP_SELF']) == 'index.php' || basename($_SERVER['PHP_SELF']) == 'user_dashboard.php') ? 'active' : '' ?>" href="index.php">
|
|
<i class="fas fa-home me-2"></i> لوحة التحكم
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'inbound.php' ? 'active' : '' ?>" href="inbound.php">
|
|
<i class="fas fa-download me-2"></i> البريد الوارد
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'outbound.php' ? 'active' : '' ?>" href="outbound.php">
|
|
<i class="fas fa-upload me-2"></i> البريد الصادر
|
|
</a>
|
|
</li>
|
|
<?php if (isAdmin()): ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'overdue_report.php' ? 'active' : '' ?>" href="overdue_report.php">
|
|
<i class="fas fa-chart-line me-2"></i> تقرير التأخير
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'users.php' ? 'active' : '' ?>" href="users.php">
|
|
<i class="fas fa-users me-2"></i> إدارة المستخدمين
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'charity-settings.php' ? 'active' : '' ?>" href="charity-settings.php">
|
|
<i class="fas fa-cog me-2"></i> إعدادات الجمعية
|
|
</a>
|
|
</li>
|
|
<?php endif; ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'profile.php' ? 'active' : '' ?>" href="profile.php">
|
|
<i class="fas fa-user-circle me-2"></i> الملف الشخصي
|
|
</a>
|
|
</li>
|
|
|
|
<!-- Theme Switcher -->
|
|
<li class="theme-switcher">
|
|
<div class="small fw-bold mb-2 text-center">المظهر</div>
|
|
<div class="theme-options">
|
|
<div class="theme-btn theme-btn-light <?= $user_theme == 'light' ? 'active' : '' ?>" onclick="setTheme('light')" title="فاتح"></div>
|
|
<div class="theme-btn theme-btn-dark <?= $user_theme == 'dark' ? 'active' : '' ?>" onclick="setTheme('dark')" title="داكن"></div>
|
|
<div class="theme-btn theme-btn-midnight <?= $user_theme == 'midnight' ? 'active' : '' ?>" onclick="setTheme('midnight')" title="منتصف الليل"></div>
|
|
<div class="theme-btn theme-btn-forest <?= $user_theme == 'forest' ? 'active' : '' ?>" onclick="setTheme('forest')" title="غابة"></div>
|
|
</div>
|
|
</li>
|
|
|
|
<li class="nav-item mt-2">
|
|
<a class="nav-link text-danger" href="logout.php">
|
|
<i class="fas fa-sign-out-alt me-2"></i> تسجيل الخروج
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<script>
|
|
function setTheme(theme) {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
document.querySelectorAll('.theme-btn').forEach(btn => btn.classList.remove('active'));
|
|
document.querySelector('.theme-btn-' + theme).classList.add('active');
|
|
|
|
fetch('api/update_theme.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ theme: theme })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (!data.success) console.error('Failed to update theme preference');
|
|
});
|
|
}
|
|
</script>
|
|
<?php endif; ?>
|
|
|
|
<nav class="navbar navbar-expand-md navbar-light bg-white d-md-none border-bottom mb-3">
|
|
<div class="container-fluid">
|
|
<span class="navbar-brand">القائمة</span>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".sidebar" aria-controls="sidebar" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
</div>
|
|
</nav>
|
|
<main class="<?= isLoggedIn() ? 'col-md-9 ms-sm-auto col-lg-10' : 'col-12' ?> px-md-4 py-4">
|