439 lines
28 KiB
PHP
439 lines
28 KiB
PHP
<?php
|
|
// admin_courses.php
|
|
require_once __DIR__ . '/includes/app.php';
|
|
require_once __DIR__ . '/includes/auth.php';
|
|
|
|
require_permission('courses', 'view');
|
|
|
|
$action = $_GET['action'] ?? 'list';
|
|
$id = (int)($_GET['id'] ?? 0);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$post_action = $_POST['action'] ?? $action;
|
|
$post_id = (int)($_POST['id'] ?? $id);
|
|
|
|
if ($post_action === 'delete' && $post_id > 0) {
|
|
require_permission('courses', 'delete');
|
|
$stmt = db()->prepare("DELETE FROM courses WHERE id = ?");
|
|
$stmt->execute([$post_id]);
|
|
header('Location: ' . app_url('admin.php', ['page' => 'courses']));
|
|
exit;
|
|
}
|
|
|
|
if ($post_action === 'close_all_registration') {
|
|
db()->query("UPDATE courses SET registration_open = 0");
|
|
header('Location: ' . app_url('admin.php', ['page' => 'courses']));
|
|
exit;
|
|
}
|
|
if ($post_action === 'open_all_registration') {
|
|
db()->query("UPDATE courses SET registration_open = 1");
|
|
header('Location: ' . app_url('admin.php', ['page' => 'courses']));
|
|
exit;
|
|
}
|
|
if ($post_action === 'reset_all_students') {
|
|
db()->query("TRUNCATE TABLE course_students");
|
|
header('Location: ' . app_url('admin.php', ['page' => 'courses']));
|
|
exit;
|
|
}
|
|
|
|
if ($post_action === 'edit' || $post_action === 'add') {
|
|
require_permission('courses', $post_action === 'add' ? 'add' : 'edit');
|
|
$name_en = $_POST['name_en'] ?? '';
|
|
$name_ar = $_POST['name_ar'] ?? '';
|
|
$desc_en = $_POST['description_en'] ?? '';
|
|
$desc_ar = $_POST['description_ar'] ?? '';
|
|
$status = $_POST['status'] ?? 'active';
|
|
$price = (float)($_POST['price'] ?? 0);
|
|
$max_students = (isset($_POST['max_students']) && $_POST['max_students'] !== '') ? (int)$_POST['max_students'] : null;
|
|
$registration_open = isset($_POST['registration_open']) ? 1 : 0;
|
|
|
|
$picture = null;
|
|
if ($post_action === 'edit' && $post_id > 0) {
|
|
$stmt = db()->prepare("SELECT picture FROM courses WHERE id = ?");
|
|
$stmt->execute([$post_id]);
|
|
$picture = $stmt->fetchColumn();
|
|
}
|
|
|
|
if (isset($_FILES['picture']) && $_FILES['picture']['error'] === UPLOAD_ERR_OK) {
|
|
$upload_dir = __DIR__ . '/assets/images/uploads/';
|
|
if (!is_dir($upload_dir)) {
|
|
mkdir($upload_dir, 0775, true);
|
|
}
|
|
$filename = time() . '_' . basename($_FILES['picture']['name']);
|
|
$target_file = $upload_dir . $filename;
|
|
if (move_uploaded_file($_FILES['picture']['tmp_name'], $target_file)) {
|
|
$picture = 'assets/images/uploads/' . $filename;
|
|
}
|
|
}
|
|
|
|
if ($post_action === 'edit' && $post_id > 0) {
|
|
$stmt = db()->prepare("UPDATE courses SET name_en=?, name_ar=?, description_en=?, description_ar=?, status=?, price=?, picture=?, max_students=?, registration_open=? WHERE id=?");
|
|
$stmt->execute([$name_en, $name_ar, $desc_en, $desc_ar, $status, $price, $picture, $max_students, $registration_open, $post_id]);
|
|
} else {
|
|
$stmt = db()->prepare("INSERT INTO courses (name_en, name_ar, description_en, description_ar, status, price, picture, max_students, registration_open) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
$stmt->execute([$name_en, $name_ar, $desc_en, $desc_ar, $status, $price, $picture, $max_students, $registration_open]);
|
|
}
|
|
header('Location: ' . app_url('admin.php', ['page' => 'courses']));
|
|
exit;
|
|
}
|
|
|
|
if ($post_action === 'manage_students') {
|
|
$course_id = (int)$_POST['course_id'];
|
|
$student_ids = $_POST['student_ids'] ?? [];
|
|
db()->prepare("DELETE FROM course_students WHERE course_id=?")->execute([$course_id]);
|
|
$insert_stmt = db()->prepare("INSERT INTO course_students (course_id, student_id) VALUES (?, ?)");
|
|
foreach ($student_ids as $sid) {
|
|
$insert_stmt->execute([$course_id, (int)$sid]);
|
|
}
|
|
header('Location: ' . app_url('admin.php', ['page' => 'courses']));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Fetch all students for assignment mapping
|
|
$all_students_stmt = db()->query("SELECT id, full_name, email FROM student_subscriptions ORDER BY full_name ASC");
|
|
$all_students = $all_students_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$course_students_stmt = db()->query("SELECT course_id, student_id FROM course_students");
|
|
$all_course_students = $course_students_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
$course_students_map = [];
|
|
foreach ($all_course_students as $cs) {
|
|
$course_students_map[$cs['course_id']][] = $cs['student_id'];
|
|
}
|
|
|
|
// list view
|
|
$search = $_GET['search'] ?? '';
|
|
$page_num = max(1, (int)($_GET['p'] ?? 1));
|
|
$limit = 10;
|
|
$offset = ($page_num - 1) * $limit;
|
|
|
|
$where = "";
|
|
$params = [];
|
|
if ($search !== '') {
|
|
$where = "WHERE name_en LIKE ? OR name_ar LIKE ?";
|
|
$params[] = "%$search%";
|
|
$params[] = "%$search%";
|
|
}
|
|
|
|
$total_stmt = db()->prepare("SELECT COUNT(*) FROM courses $where");
|
|
$total_stmt->execute($params);
|
|
$total = $total_stmt->fetchColumn();
|
|
$pages = ceil($total / $limit);
|
|
|
|
$stmt = db()->prepare("SELECT * FROM courses $where ORDER BY id DESC LIMIT $limit OFFSET $offset");
|
|
$stmt->execute($params);
|
|
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<div class="section-header mb-4 d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h1 class="section-title mb-2"><?= h(t('Courses', 'الدورات')) ?></h1>
|
|
</div>
|
|
<div class="d-flex flex-wrap gap-2 justify-content-end">
|
|
<?php if (has_permission('courses', 'delete')): ?>
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" class="m-0" onsubmit="return confirm('<?= h(t('Close registration for all courses?', 'هل أنت متأكد من إغلاق التسجيل لجميع الدورات؟')) ?>');">
|
|
<input type="hidden" name="action" value="close_all_registration">
|
|
<button type="submit" class="btn btn-outline-warning btn-sm"><?= h(t('Close All', 'إغلاق الكل')) ?></button>
|
|
</form>
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" class="m-0" onsubmit="return confirm('<?= h(t('Open registration for all courses?', 'هل أنت متأكد من فتح التسجيل لجميع الدورات؟')) ?>');">
|
|
<input type="hidden" name="action" value="open_all_registration">
|
|
<button type="submit" class="btn btn-outline-success btn-sm"><?= h(t('Open All', 'فتح الكل')) ?></button>
|
|
</form>
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" class="m-0" onsubmit="return confirm('<?= h(t('Are you absolutely sure you want to remove ALL students from ALL courses to start a new batch?', 'هل أنت متأكد تماماً أنك تريد إزالة جميع الطلاب من جميع الدورات لبدء دفعة جديدة؟')) ?>');">
|
|
<input type="hidden" name="action" value="reset_all_students">
|
|
<button type="submit" class="btn btn-outline-danger btn-sm"><?= h(t('Reset Batch', 'إعادة ضبط الدفعة')) ?></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addCourseModal" style="background-color: var(--accent); border-color: var(--accent);">+ <?= h(t('Add Course', 'إضافة دورة')) ?></button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel-card mb-4">
|
|
<form method="get" class="d-flex gap-2 align-items-center">
|
|
<input type="hidden" name="page" value="courses">
|
|
<input type="text" name="search" class="form-control w-auto" placeholder="<?= h(t('Search...', 'بحث...')) ?>" value="<?= h($search) ?>">
|
|
<button type="submit" class="btn btn-outline-secondary"><?= h(t('Filter', 'تصفية')) ?></button>
|
|
<?php if ($search): ?>
|
|
<a href="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" class="btn btn-link text-secondary text-decoration-none"><?= h(t('Clear', 'مسح')) ?></a>
|
|
<?php endif; ?>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="panel-card">
|
|
<div class="table-responsive">
|
|
<table class="table align-middle dashboard-table mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th><?= h(t('Name', 'الاسم')) ?></th>
|
|
<th><?= h(t('Price', 'السعر')) ?></th>
|
|
<th><?= h(t('Status', 'الحالة')) ?></th>
|
|
<th><?= h(t('Assigned', 'مخصص')) ?></th>
|
|
<th><?= h(t('Reg.', 'التسجيل')) ?></th>
|
|
<th><?= h(t('Description', 'الوصف')) ?></th>
|
|
<th class="text-end"><?= h(t('Actions', 'إجراءات')) ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach($items as $row):
|
|
$assigned_count = count($course_students_map[$row['id']] ?? []);
|
|
?>
|
|
<tr>
|
|
<td><?= h((string)$row['id']) ?></td>
|
|
<td>
|
|
<div class="d-flex align-items-center gap-3">
|
|
<?php if(!empty($row['picture'])): ?>
|
|
<img src="<?= h($row['picture']) ?>" alt="" class="rounded" style="width: 40px; height: 40px; object-fit: cover;">
|
|
<?php else: ?>
|
|
<div class="rounded bg-secondary text-white d-flex align-items-center justify-content-center" style="width: 40px; height: 40px;">
|
|
<svg width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M4 0h5.293A1 1 0 0 1 10 .293L13.707 4a1 1 0 0 1 .293.707V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm5.5 1.5v2a1 1 0 0 0 1 1h2l-3-3z"/></svg>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="fw-semibold"><?= h(current_lang() === 'ar' ? $row['name_ar'] : $row['name_en']) ?></div>
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-light text-dark border"><?= h(format_price((float)($row['price'] ?? 0))) ?></span>
|
|
</td>
|
|
<td>
|
|
<?php if (($row['status'] ?? 'active') === 'active'): ?>
|
|
<span class="badge bg-success"><?= h(t('Active', 'نشط')) ?></span>
|
|
<?php else: ?>
|
|
<span class="badge bg-secondary"><?= h(t('Inactive', 'غير نشط')) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-info text-dark"><?= $assigned_count ?></span>
|
|
<?php if ($row['max_students']): ?>
|
|
<span class="badge bg-secondary">/ <?= h($row['max_students']) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?php if ($row['registration_open']): ?>
|
|
<span class="badge bg-success"><?= h(t('Open', 'مفتوح')) ?></span>
|
|
<?php else: ?>
|
|
<span class="badge bg-danger"><?= h(t('Closed', 'مغلق')) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-truncate" style="max-width: 200px;">
|
|
<?= h(current_lang() === 'ar' ? $row['description_ar'] : $row['description_en']) ?>
|
|
</td>
|
|
<td class="text-end">
|
|
<button type="button" class="btn btn-sm btn-outline-info" data-bs-toggle="modal" data-bs-target="#manageStudentsModal<?= $row['id'] ?>" title="<?= h(t('Manage Students', 'إدارة الطلاب')) ?>">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-people" viewBox="0 0 16 16">
|
|
<path d="M15 14s1 0 1-1-1-4-5-4-5 3-5 4 1 1 1 1zm-7.978-1L7 12.996c.001-.264.167-1.03.76-1.72C8.312 10.629 9.282 10 11 10c1.717 0 2.687.63 3.24 1.276.593.69.758 1.457.76 1.72l-.008.002-.014.002zM11 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4m3-2a3 3 0 1 1-6 0 3 3 0 0 1 6 0M6.936 9.28a6 6 0 0 0-1.23-.247A7 7 0 0 0 5 9c-4 0-5 3-5 4q0 1 1 1h4.216A2.24 2.24 0 0 1 5 13c0-1.01.377-2.042 1.09-2.904.243-.294.526-.569.846-.816M4.92 10A5.5 5.5 0 0 0 4 13H1c0-.26.164-1.03.76-1.724.545-.636 1.492-1.256 3.16-1.275ZM1.5 5.5a3 3 0 1 1 6 0 3 3 0 0 1-6 0m3-2a2 2 0 1 0 0 4 2 2 0 0 0 0-4"/>
|
|
</svg>
|
|
</button>
|
|
<?php if (has_permission('courses', 'edit')): ?>
|
|
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#editCourseModal<?= $row['id'] ?>" title="<?= h(t('Edit', 'تعديل')) ?>">
|
|
<svg width="16" height="16" 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>
|
|
</button>
|
|
<?php endif; ?>
|
|
<?php if (has_permission('courses', 'delete')): ?>
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses', 'action'=>'delete', 'id'=>$row['id']])) ?>" class="d-inline" onsubmit="return confirm('<?= h(t('Are you sure?', 'هل أنت متأكد؟')) ?>');">
|
|
<button type="submit" class="btn btn-sm btn-outline-danger" title="<?= h(t('Delete', 'حذف')) ?>"><svg width="16" height="16" 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>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
|
|
<!-- Manage Students Modal for Row <?= $row['id'] ?> -->
|
|
<div class="modal fade" id="manageStudentsModal<?= $row['id'] ?>" tabindex="-1" aria-labelledby="manageStudentsModalLabel<?= $row['id'] ?>" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header border-0 bg-dark-blue">
|
|
<h5 class="modal-title section-title" id="manageStudentsModalLabel<?= $row['id'] ?>">
|
|
<?= h(t('Manage Students', 'إدارة الطلاب')) ?> - <?= h(current_lang() === 'ar' ? $row['name_ar'] : $row['name_en']) ?>
|
|
</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="manage_students">
|
|
<input type="hidden" name="course_id" value="<?= $row['id'] ?>">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= h(t('Select Students', 'اختر الطلاب')) ?></label>
|
|
<div class="list-group">
|
|
<?php
|
|
$assigned_to_this = $course_students_map[$row['id']] ?? [];
|
|
foreach ($all_students as $student):
|
|
$is_assigned = in_array($student['id'], $assigned_to_this);
|
|
?>
|
|
<label class="list-group-item d-flex gap-2 align-items-center">
|
|
<input class="form-check-input flex-shrink-0" type="checkbox" name="student_ids[]" value="<?= h($student['id']) ?>" <?= $is_assigned ? 'checked' : '' ?>>
|
|
<span>
|
|
<?= h($student['full_name']) ?>
|
|
<small class="d-block text-muted"><?= h($student['email']) ?></small>
|
|
</span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
<?php if(empty($all_students)): ?>
|
|
<div class="text-muted"><?= h(t('No students available.', 'لا يوجد طلاب متاحين.')) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-end gap-2 mt-4">
|
|
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal"><?= h(t('Cancel', 'إلغاء')) ?></button>
|
|
<button type="submit" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);"><?= h(t('Save Assignments', 'حفظ التعيينات')) ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Edit Modal for Row <?= $row['id'] ?> -->
|
|
<div class="modal fade" id="editCourseModal<?= $row['id'] ?>" tabindex="-1" aria-labelledby="editCourseModalLabel<?= $row['id'] ?>" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header border-0 bg-dark-blue">
|
|
<h5 class="modal-title section-title" id="editCourseModalLabel<?= $row['id'] ?>"><?= h(t('Edit Course', 'تعديل الدورة')) ?></h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="edit">
|
|
<input type="hidden" name="id" value="<?= $row['id'] ?>">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Name (EN)', 'الاسم (إنجليزي)')) ?></label>
|
|
<input type="text" name="name_en" class="form-control" value="<?= h($row['name_en']) ?>" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Name (AR)', 'الاسم (عربي)')) ?></label>
|
|
<input type="text" name="name_ar" class="form-control" value="<?= h($row['name_ar']) ?>" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Description (EN)', 'الوصف (إنجليزي)')) ?></label>
|
|
<textarea name="description_en" class="form-control"><?= h($row['description_en']) ?></textarea>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Description (AR)', 'الوصف (عربي)')) ?></label>
|
|
<textarea name="description_ar" class="form-control"><?= h($row['description_ar']) ?></textarea>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Price', 'السعر')) ?></label>
|
|
<input type="number" step="0.001" name="price" class="form-control" value="<?= h($row['price'] ?? 0) ?>">
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Max Students', 'الحد الأقصى للطلاب')) ?></label>
|
|
<input type="number" name="max_students" class="form-control" placeholder="<?= h(t('Empty = unlimited', 'فارغ = غير محدود')) ?>" value="<?= h($row['max_students']) ?>">
|
|
</div>
|
|
<div class="col-md-12 mb-3">
|
|
<label class="form-label"><?= h(t('Picture', 'صورة')) ?></label>
|
|
<input type="file" name="picture" class="form-control" accept="image/*">
|
|
<?php if(!empty($row['picture'])): ?>
|
|
<div class="mt-2"><img src="<?= h($row['picture']) ?>" alt="Course Image" class="img-thumbnail" style="max-height: 50px;"></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="col-12 mb-3">
|
|
<label class="form-label"><?= h(t('Status', 'الحالة')) ?></label>
|
|
<select name="status" class="form-select">
|
|
<option value="active" <?= ($row['status'] ?? 'active') === 'active' ? 'selected' : '' ?>><?= h(t('Active', 'نشط')) ?></option>
|
|
<option value="inactive" <?= ($row['status'] ?? 'active') === 'inactive' ? 'selected' : '' ?>><?= h(t('Inactive', 'غير نشط')) ?></option>
|
|
</select>
|
|
</div>
|
|
<div class="col-12 mb-3">
|
|
<div class="form-check form-switch">
|
|
<input class="form-check-input" type="checkbox" name="registration_open" id="regSwitch<?= $row['id'] ?>" value="1" <?= $row['registration_open'] ? 'checked' : '' ?>/>
|
|
<label class="form-check-label" for="regSwitch<?= $row['id'] ?>"><?= h(t('Registration Open', 'التسجيل مفتوح')) ?></label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex justify-content-end gap-2 mt-4">
|
|
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal"><?= h(t('Cancel', 'إلغاء')) ?></button>
|
|
<button type="submit" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);"><?= h(t('Save Changes', 'حفظ التغييرات')) ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- End Edit Modal -->
|
|
|
|
<?php endforeach; ?>
|
|
<?php if(!$items): ?>
|
|
<tr><td colspan="8" class="text-center text-secondary py-3"><?= h(t('No courses found.', 'لا توجد دورات.')) ?></td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($pages > 1): ?>
|
|
<nav class="mt-4">
|
|
<ul class="pagination justify-content-center">
|
|
<?php for($i=1; $i<=$pages; $i++): ?>
|
|
<li class="page-item <?= $i === $page_num ? 'active' : '' ?>">
|
|
<a class="page-link" href="<?= h(app_url('admin.php', ['page'=>'courses', 'p'=>$i, 'search'=>$search])) ?>"><?= $i ?></a>
|
|
</li>
|
|
<?php endfor; ?>
|
|
</ul>
|
|
</nav>
|
|
<?php endif; ?>
|
|
|
|
<!-- Add Course Modal -->
|
|
<div class="modal fade" id="addCourseModal" tabindex="-1" aria-labelledby="addCourseModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header border-0 bg-dark-blue">
|
|
<h5 class="modal-title section-title" id="addCourseModalLabel"><?= h(t('Add Course', 'إضافة دورة')) ?></h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'courses'])) ?>" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="add">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Name (EN)', 'الاسم (إنجليزي)')) ?></label>
|
|
<input type="text" name="name_en" class="form-control" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Name (AR)', 'الاسم (عربي)')) ?></label>
|
|
<input type="text" name="name_ar" class="form-control" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Description (EN)', 'الوصف (إنجليزي)')) ?></label>
|
|
<textarea name="description_en" class="form-control"></textarea>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Description (AR)', 'الوصف (عربي)')) ?></label>
|
|
<textarea name="description_ar" class="form-control"></textarea>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Price', 'السعر')) ?></label>
|
|
<input type="number" step="0.001" name="price" class="form-control" value="0.000">
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label"><?= h(t('Max Students', 'الحد الأقصى للطلاب')) ?></label>
|
|
<input type="number" name="max_students" class="form-control" placeholder="<?= h(t('Empty = unlimited', 'فارغ = غير محدود')) ?>">
|
|
</div>
|
|
<div class="col-md-12 mb-3">
|
|
<label class="form-label"><?= h(t('Picture', 'صورة')) ?></label>
|
|
<input type="file" name="picture" class="form-control" accept="image/*">
|
|
</div>
|
|
<div class="col-12 mb-3">
|
|
<label class="form-label"><?= h(t('Status', 'الحالة')) ?></label>
|
|
<select name="status" class="form-select">
|
|
<option value="active"><?= h(t('Active', 'نشط')) ?></option>
|
|
<option value="inactive"><?= h(t('Inactive', 'غير نشط')) ?></option>
|
|
</select>
|
|
</div>
|
|
<div class="col-12 mb-3">
|
|
<div class="form-check form-switch">
|
|
<input class="form-check-input" type="checkbox" name="registration_open" id="regSwitchAdd" value="1" checked>
|
|
<label class="form-check-label" for="regSwitchAdd"><?= h(t('Registration Open', 'التسجيل مفتوح')) ?></label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex justify-content-end gap-2 mt-4">
|
|
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal"><?= h(t('Cancel', 'إلغاء')) ?></button>
|
|
<button type="submit" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);"><?= h(t('Save', 'حفظ')) ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- End Add Modal -->
|