272 lines
13 KiB
PHP
272 lines
13 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
if (!isAdmin()) { redirect('user_dashboard.php'); }
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$is_admin = isAdmin();
|
|
|
|
// Stats
|
|
$total_inbound = db()->query("SELECT COUNT(*) FROM mailbox WHERE type = 'inbound'")->fetchColumn();
|
|
$total_outbound = db()->query("SELECT COUNT(*) FROM mailbox WHERE type = 'outbound'")->fetchColumn();
|
|
|
|
// Fetch statuses for badge and count
|
|
$statuses_data = db()->query("SELECT * FROM mailbox_statuses")->fetchAll(PDO::FETCH_UNIQUE);
|
|
|
|
// For the "In Progress" stat card, we might need a specific status or just a sum of non-closed statuses.
|
|
$in_progress_id = null;
|
|
foreach ($statuses_data as $id => $s) {
|
|
if ($s['name'] == 'in_progress') {
|
|
$in_progress_id = $id;
|
|
break;
|
|
}
|
|
}
|
|
$in_progress_count = 0;
|
|
if ($in_progress_id) {
|
|
$stmt = db()->prepare("SELECT COUNT(*) FROM mailbox WHERE status_id = ?");
|
|
$stmt->execute([$in_progress_id]);
|
|
$in_progress_count = $stmt->fetchColumn();
|
|
}
|
|
|
|
// My Assignments
|
|
$my_assignments = db()->prepare("SELECT m.*, s.name as status_name, s.color as status_color
|
|
FROM mailbox m
|
|
LEFT JOIN mailbox_statuses s ON m.status_id = s.id
|
|
WHERE m.assigned_to = ?
|
|
ORDER BY m.created_at DESC LIMIT 5");
|
|
$my_assignments->execute([$user_id]);
|
|
$my_assignments = $my_assignments->fetchAll();
|
|
|
|
// Recent Mail (Global for Admin/Clerk, otherwise limited)
|
|
$recent_mail_query = "SELECT m.*, s.name as status_name, s.color as status_color, u.full_name as assigned_to_name
|
|
FROM mailbox m
|
|
LEFT JOIN mailbox_statuses s ON m.status_id = s.id
|
|
LEFT JOIN users u ON m.assigned_to = u.id";
|
|
if (!$is_admin && $_SESSION['user_role'] !== 'clerk') {
|
|
$recent_mail_query .= " WHERE m.assigned_to = ? OR m.created_by = ?";
|
|
$recent_stmt = db()->prepare($recent_mail_query . " ORDER BY m.created_at DESC LIMIT 10");
|
|
$recent_stmt->execute([$user_id, $user_id]);
|
|
} else {
|
|
$recent_stmt = db()->prepare($recent_mail_query . " ORDER BY m.created_at DESC LIMIT 10");
|
|
$recent_stmt->execute();
|
|
}
|
|
$recent_mail = $recent_stmt->fetchAll();
|
|
|
|
function getStatusBadge($mail) {
|
|
$status_name = $mail['status_name'] ?? 'غير معروف';
|
|
$status_color = $mail['status_color'] ?? '#6c757d';
|
|
|
|
// Translation for default statuses
|
|
$display_name = $status_name;
|
|
if ($status_name == 'received') $display_name = 'تم الاستلام';
|
|
if ($status_name == 'in_progress') $display_name = 'قيد المعالجة';
|
|
if ($status_name == 'closed') $display_name = 'مكتمل';
|
|
|
|
return '<span class="badge" style="background-color: ' . $status_color . ';">' . htmlspecialchars($display_name) . '</span>';
|
|
}
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
|
<h1 class="h2">لوحة التحكم</h1>
|
|
<div class="btn-toolbar mb-2 mb-md-0">
|
|
<div class="btn-group me-2">
|
|
<?php if (isAdmin()): ?><a href="charity-settings.php" class="btn btn-sm btn-outline-dark"><i class="fas fa-cog me-1"></i> الإعدادات</a><?php endif; ?>
|
|
<a href="inbound.php?action=add" class="btn btn-sm btn-outline-primary">إضافة بريد وارد</a>
|
|
<a href="outbound.php" class="btn btn-sm btn-outline-secondary">إضافة بريد صادر</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Overdue Alert -->
|
|
<?php
|
|
$overdue_count = db()->query("SELECT COUNT(*) FROM mailbox WHERE due_date < CURDATE() AND status != 'closed'")->fetchColumn();
|
|
if ($overdue_count > 0):
|
|
?>
|
|
<div class="row mb-4">
|
|
<div class="col-12">
|
|
<div class="alert alert-danger shadow-sm border-0 d-flex align-items-center justify-content-between mb-0">
|
|
<div>
|
|
<i class="fas fa-exclamation-triangle fs-4 me-3"></i>
|
|
<span class="fw-bold">هناك <?= $overdue_count ?> مهام متأخرة تتطلب انتباهك!</span>
|
|
</div>
|
|
<?php if (isAdmin()): ?>
|
|
<a href="overdue_report.php" class="btn btn-danger btn-sm">عرض التقرير</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Stats Cards -->
|
|
<div class="row g-4 mb-4">
|
|
<div class="col-md-3">
|
|
<div class="card h-100 p-3 shadow-sm border-0 border-start border-primary border-4">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<div>
|
|
<h6 class="text-muted mb-1">البريد الوارد</h6>
|
|
<h3 class="fw-bold mb-0"><?= $total_inbound ?></h3>
|
|
</div>
|
|
<div class="bg-primary bg-opacity-10 p-3 rounded-circle">
|
|
<i class="fas fa-download text-primary fs-4"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card h-100 p-3 shadow-sm border-0 border-start border-success border-4">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<div>
|
|
<h6 class="text-muted mb-1">البريد الصادر</h6>
|
|
<h3 class="fw-bold mb-0"><?= $total_outbound ?></h3>
|
|
</div>
|
|
<div class="bg-success bg-opacity-10 p-3 rounded-circle">
|
|
<i class="fas fa-upload text-success fs-4"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card h-100 p-3 shadow-sm border-0 border-start border-info border-4">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<div>
|
|
<h6 class="text-muted mb-1">قيد المعالجة</h6>
|
|
<h3 class="fw-bold mb-0"><?= $in_progress_count ?></h3>
|
|
</div>
|
|
<div class="bg-info bg-opacity-10 p-3 rounded-circle">
|
|
<i class="fas fa-clock text-info fs-4"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card h-100 p-3 shadow-sm border-0 border-start border-warning border-4">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<div>
|
|
<h6 class="text-muted mb-1">المستخدمين</h6>
|
|
<h3 class="fw-bold mb-0"><?= db()->query("SELECT COUNT(*) FROM users")->fetchColumn() ?></h3>
|
|
</div>
|
|
<div class="bg-warning bg-opacity-10 p-3 rounded-circle">
|
|
<i class="fas fa-users text-warning fs-4"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (!empty($my_assignments)): ?>
|
|
<!-- My Assignments Section -->
|
|
<div class="card shadow-sm border-0 mb-4 bg-primary bg-opacity-10 border-top border-primary border-3">
|
|
<div class="card-header bg-transparent py-3 border-0">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0 fw-bold text-primary"><i class="fas fa-tasks me-2"></i> مهامي الحالية</h5>
|
|
<span class="badge bg-primary rounded-pill"><?= count($my_assignments) ?></span>
|
|
</div>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<tbody>
|
|
<?php foreach ($my_assignments as $mail): ?>
|
|
<tr style="cursor: pointer;" onclick="window.location='view_mail.php?id=<?= $mail['id'] ?>'">
|
|
<td class="ps-4" width="120">
|
|
<small class="text-muted d-block">رقم القيد</small>
|
|
<span class="fw-bold text-primary"><?= $mail['ref_no'] ?></span>
|
|
</td>
|
|
<td>
|
|
<small class="text-muted d-block">الموضوع</small>
|
|
<span class="fw-bold"><?= htmlspecialchars($mail['subject']) ?></span>
|
|
</td>
|
|
<td>
|
|
<small class="text-muted d-block">الموعد النهائي</small>
|
|
<?php if ($mail['due_date']): ?>
|
|
<span class="<?= (strtotime($mail['due_date']) < time() && $mail['status_name'] != 'closed') ? 'text-danger fw-bold' : '' ?>">
|
|
<?= $mail['due_date'] ?>
|
|
</span>
|
|
<?php else: ?>
|
|
<span class="text-muted">-</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-center">
|
|
<small class="text-muted d-block mb-1">الحالة</small>
|
|
<?= getStatusBadge($mail) ?>
|
|
</td>
|
|
<td class="pe-4 text-end">
|
|
<i class="fas fa-chevron-left text-primary"></i>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Recent Mail -->
|
|
<div class="card shadow-sm border-0 mb-4">
|
|
<div class="card-header bg-white py-3">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0 fw-bold"><?= $is_admin ? 'آخر المراسلات المسجلة' : 'آخر المراسلات' ?></h5>
|
|
<a href="inbound.php" class="btn btn-sm btn-link text-decoration-none">عرض الكل</a>
|
|
</div>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="ps-4">رقم القيد</th>
|
|
<th>النوع</th>
|
|
<th>الموضوع</th>
|
|
<th>الموعد النهائي</th>
|
|
<th>المرسل/المستلم</th>
|
|
<th>المسؤول</th>
|
|
<th>الحالة</th>
|
|
<th class="pe-4 text-center">التاريخ</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if ($recent_mail): ?>
|
|
<?php foreach ($recent_mail as $mail): ?>
|
|
<tr style="cursor: pointer;" onclick="window.location='view_mail.php?id=<?= $mail['id'] ?>'">
|
|
<td class="ps-4 fw-bold text-primary"><?= $mail['ref_no'] ?></td>
|
|
<td>
|
|
<?php if ($mail['type'] == 'inbound'): ?>
|
|
<span class="text-primary"><i class="fas fa-arrow-down me-1"></i> وارد</span>
|
|
<?php else: ?>
|
|
<span class="text-success"><i class="fas fa-arrow-up me-1"></i> صادر</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?= htmlspecialchars($mail['subject']) ?></td>
|
|
<td>
|
|
<?php if ($mail['due_date']): ?>
|
|
<small class="<?= (strtotime($mail['due_date']) < time() && $mail['status_name'] != 'closed') ? 'text-danger fw-bold' : 'text-muted' ?>">
|
|
<?= $mail['due_date'] ?>
|
|
</small>
|
|
<?php else: ?>
|
|
<small class="text-muted">-</small>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?= htmlspecialchars($mail['sender'] ?: $mail['recipient']) ?></td>
|
|
<td>
|
|
<?php if ($mail['assigned_to_name']): ?>
|
|
<small><i class="fas fa-user-tag me-1 text-muted"></i> <?= htmlspecialchars($mail['assigned_to_name']) ?></small>
|
|
<?php else: ?>
|
|
<small class="text-muted">غير معين</small>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?= getStatusBadge($mail) ?></td>
|
|
<td class="pe-4 text-center"><?= date('Y-m-d', strtotime($mail['date_registered'])) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<tr>
|
|
<td colspan="8" class="text-center py-4 text-muted">لا يوجد بريد مسجل حالياً</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|