39669-vm/applications.php
2026-04-16 17:50:08 +00:00

152 lines
8.1 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/app.php';
// Handle POST actions (e.g. Delete)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'delete') {
$id = (int)($_POST['id'] ?? 0);
if ($id > 0) {
$stmt = db()->prepare('DELETE FROM center_applications WHERE id = ?');
$stmt->execute([$id]);
set_flash('success', 'تم حذف الطلب بنجاح.');
}
header('Location: applications.php');
exit;
}
}
// Read list
$search = clean_text($_GET['search'] ?? '', 255);
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT) ?: 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$query = 'SELECT * FROM center_applications';
$countQuery = 'SELECT COUNT(*) FROM center_applications';
$params = [];
if ($search !== '') {
$where = ' WHERE center_name LIKE ? OR city LIKE ? OR director_name LIKE ?';
$query .= $where;
$countQuery .= $where;
$params[] = "%$search%";
$params[] = "%$search%";
$params[] = "%$search%";
}
$stmtCount = db()->prepare($countQuery);
$stmtCount->execute($params);
$totalItems = (int)$stmtCount->fetchColumn();
$query .= ' ORDER BY id DESC LIMIT ' . $limit . ' OFFSET ' . $offset;
$stmt = db()->prepare($query);
$stmt->execute($params);
$applications = $stmt->fetchAll();
$flash = consume_flash();
render_page_start('إدارة الطلبات', 'applications', 'قائمة بطلبات فتح المراكز');
render_flash($flash);
?>
<section class="py-4 py-lg-5">
<div class="container-xxl">
<div class="row g-4 align-items-start">
<div class="col-lg-3">
<?php require __DIR__ . '/includes/sidebar.php'; ?>
</div>
<div class="col-lg-9">
<div class="app-card mb-4">
<div class="d-flex justify-content-between align-items-center mb-4 flex-wrap gap-3">
<div class="section-title mb-0">إدارة طلبات فتح المراكز</div>
<a class="btn btn-primary" href="center_application.php">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/>
</svg>
إضافة طلب
</a>
</div>
<!-- Search Bar -->
<?php render_search_bar($search, "ابحث باسم المركز، المدينة، أو المسؤول...", "applications.php", $_GET); ?>
<div class="table-responsive">
<table class="table app-table align-middle">
<thead>
<tr>
<th>المرجع</th>
<th>المركز</th>
<th>المدينة</th>
<th>المسؤول</th>
<th>الفترة</th>
<th>الحالة</th>
<th>الإجراءات</th>
</tr>
</thead>
<tbody>
<?php if (count($applications) === 0): ?>
<tr>
<td colspan="7" class="text-center py-4 text-muted">لا توجد طلبات مسجلة أو لم يتم العثور على نتائج.</td>
</tr>
<?php else: ?>
<?php foreach ($applications as $application): ?>
<tr>
<td><a class="table-link" href="application_detail.php?id=<?= e((string) $application['id']) ?>">#<?= e((string) $application['id']) ?></a></td>
<td>
<div class="fw-semibold"><?= e((string) $application['center_name']) ?></div>
<div class="text-muted small">سعة متوقعة: <?= e((string) $application['expected_students']) ?> طالب</div>
</td>
<td><?= e((string) $application['city']) ?></td>
<td>
<div><?= e((string) $application['director_name']) ?></div>
<div class="text-muted small"><?= e((string) $application['phone']) ?></div>
</td>
<td>
<div><?= e((string) $application['start_date']) ?></div>
<div class="text-muted small">حتى <?= e((string) $application['end_date']) ?></div>
</td>
<td><?= status_badge((string) $application['status']) ?></td>
<td>
<div class="d-flex gap-2">
<!-- View/Edit btn -->
<?php if ((string) $application['status'] === 'approved'): ?>
<a href="approved_school.php?id=<?= e((string) $application['id']) ?>" class="btn btn-sm btn-outline-secondary" title="صفحة المركز">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M10.5 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0z"/>
<path d="M0 8s3-5.5 8-5.5S16 8 16 8s-3 5.5-8 5.5S0 8 0 8zm8 3.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"/>
</svg>
</a>
<?php else: ?>
<a href="application_detail.php?id=<?= e((string) $application['id']) ?>" class="btn btn-sm btn-outline-secondary" title="تعديل">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
</svg>
</a>
<?php endif; ?>
<!-- Delete btn -->
<form method="POST" action="applications.php" onsubmit="return confirm('هل أنت متأكد من حذف هذا الطلب؟');">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?= e((string)$application['id']) ?>">
<button type="submit" class="btn btn-sm btn-outline-danger" title="حذف">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
</svg>
</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<?php render_pagination($totalItems, $limit, $page, $_GET); ?>
</div>
</div>
</div>
</div>
</section>
<?php render_page_end(); ?>