update forms to modal
This commit is contained in:
parent
1c8373aa37
commit
22c2a878c1
@ -160,7 +160,7 @@ render_head(
|
||||
</div>
|
||||
<?php if (!$recent): ?>
|
||||
<div class="empty-state-inline"><?= h(t('No subscriptions recorded yet.', 'لم يتم تسجيل أي اشتراكات بعد.')) ?></div>
|
||||
<?php elseif ($page === 'classes'): ?>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table align-middle dashboard-table mb-0">
|
||||
<thead>
|
||||
@ -244,6 +244,8 @@ render_head(
|
||||
<?php require_once __DIR__ . '/admin_classes.php'; ?>
|
||||
<?php elseif ($page === 'subjects'): ?>
|
||||
<?php require_once __DIR__ . '/admin_subjects.php'; ?>
|
||||
<?php elseif ($page === 'teachers'): ?>
|
||||
<?php require_once __DIR__ . '/admin_teachers.php'; ?>
|
||||
<?php else: ?>
|
||||
<div class="section-header mb-4">
|
||||
<div>
|
||||
|
||||
@ -6,22 +6,27 @@ $action = $_GET['action'] ?? 'list';
|
||||
$id = (int)($_GET['id'] ?? 0);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($action === 'delete' && $id > 0) {
|
||||
// If modal is submitted, action is typically passed as a POST variable.
|
||||
// However, delete still uses the URL action. Let's support both.
|
||||
$post_action = $_POST['action'] ?? $action;
|
||||
$post_id = (int)($_POST['id'] ?? $id);
|
||||
|
||||
if ($post_action === 'delete' && $post_id > 0) {
|
||||
$stmt = db()->prepare("DELETE FROM classes WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$stmt->execute([$post_id]);
|
||||
header('Location: ' . app_url('admin.php', ['page' => 'classes']));
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'edit' || $action === 'add') {
|
||||
if ($post_action === 'edit' || $post_action === 'add') {
|
||||
$name_en = $_POST['name_en'] ?? '';
|
||||
$name_ar = $_POST['name_ar'] ?? '';
|
||||
$desc_en = $_POST['description_en'] ?? '';
|
||||
$desc_ar = $_POST['description_ar'] ?? '';
|
||||
|
||||
if ($action === 'edit' && $id > 0) {
|
||||
if ($post_action === 'edit' && $post_id > 0) {
|
||||
$stmt = db()->prepare("UPDATE classes SET name_en=?, name_ar=?, description_en=?, description_ar=? WHERE id=?");
|
||||
$stmt->execute([$name_en, $name_ar, $desc_en, $desc_ar, $id]);
|
||||
$stmt->execute([$name_en, $name_ar, $desc_en, $desc_ar, $post_id]);
|
||||
} else {
|
||||
$stmt = db()->prepare("INSERT INTO classes (name_en, name_ar, description_en, description_ar) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$name_en, $name_ar, $desc_en, $desc_ar]);
|
||||
@ -31,72 +36,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === 'edit' || $action === 'add'):
|
||||
$item = ['name_en'=>'', 'name_ar'=>'', 'description_en'=>'', 'description_ar'=>''];
|
||||
if ($action === 'edit' && $id > 0) {
|
||||
$stmt = db()->prepare("SELECT * FROM classes WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$item = $stmt->fetch(PDO::FETCH_ASSOC) ?: $item;
|
||||
}
|
||||
?>
|
||||
<div class="section-header mb-4">
|
||||
<div>
|
||||
<h1 class="section-title mb-2"><?= h($action === 'edit' ? t('Edit Class', 'تعديل الصف') : t('Add Class', 'إضافة صف')) ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-card" style="max-width: 600px;">
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'classes', 'action'=>$action, 'id'=>$id])) ?>">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name (EN)</label>
|
||||
<input type="text" name="name_en" class="form-control" value="<?= h($item['name_en']) ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name (AR)</label>
|
||||
<input type="text" name="name_ar" class="form-control" value="<?= h($item['name_ar']) ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description (EN)</label>
|
||||
<textarea name="description_en" class="form-control"><?= h($item['description_en']) ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description (AR)</label>
|
||||
<textarea name="description_ar" class="form-control"><?= h($item['description_ar']) ?></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);">
|
||||
<?= h(t('Save', 'حفظ')) ?>
|
||||
</button>
|
||||
<a href="<?= h(app_url('admin.php', ['page'=>'classes'])) ?>" class="btn btn-outline-secondary"><?= h(t('Cancel', 'إلغاء')) ?></a>
|
||||
</form>
|
||||
</div>
|
||||
// list view
|
||||
$search = $_GET['search'] ?? '';
|
||||
$page_num = max(1, (int)($_GET['p'] ?? 1));
|
||||
$limit = 10;
|
||||
$offset = ($page_num - 1) * $limit;
|
||||
|
||||
<?php else: // 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%";
|
||||
}
|
||||
|
||||
$where = "";
|
||||
$params = [];
|
||||
if ($search !== '') {
|
||||
$where = "WHERE name_en LIKE ? OR name_ar LIKE ?";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
$total_stmt = db()->prepare("SELECT COUNT(*) FROM classes $where");
|
||||
$total_stmt->execute($params);
|
||||
$total = $total_stmt->fetchColumn();
|
||||
$pages = ceil($total / $limit);
|
||||
|
||||
$total_stmt = db()->prepare("SELECT COUNT(*) FROM classes $where");
|
||||
$total_stmt->execute($params);
|
||||
$total = $total_stmt->fetchColumn();
|
||||
$pages = ceil($total / $limit);
|
||||
|
||||
$stmt = db()->prepare("SELECT * FROM classes $where ORDER BY id DESC LIMIT $limit OFFSET $offset");
|
||||
$stmt->execute($params);
|
||||
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt = db()->prepare("SELECT * FROM classes $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('Classes', 'الصفوف')) ?></h1>
|
||||
</div>
|
||||
<a href="<?= h(app_url('admin.php', ['page'=>'classes', 'action'=>'add'])) ?>" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);">+ <?= h(t('Add Class', 'إضافة صف')) ?></a>
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addClassModal" style="background-color: var(--accent); border-color: var(--accent);">+ <?= h(t('Add Class', 'إضافة صف')) ?></button>
|
||||
</div>
|
||||
|
||||
<div class="panel-card mb-4">
|
||||
@ -132,12 +99,54 @@ if ($action === 'edit' || $action === 'add'):
|
||||
<?= h(current_lang() === 'ar' ? $row['description_ar'] : $row['description_en']) ?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= h(app_url('admin.php', ['page'=>'classes', 'action'=>'edit', 'id'=>$row['id']])) ?>" class="btn btn-sm btn-outline-primary"><?= h(t('Edit', 'تعديل')) ?></a>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#editClassModal<?= $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>
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'classes', '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"><?= h(t('Delete', 'حذف')) ?></button>
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Edit Modal for Row <?= $row['id'] ?> -->
|
||||
<div class="modal fade" id="editClassModal<?= $row['id'] ?>" tabindex="-1" aria-labelledby="editClassModalLabel<?= $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 pb-0">
|
||||
<h5 class="modal-title section-title" id="editClassModalLabel<?= $row['id'] ?>"><?= h(t('Edit Class', 'تعديل الصف')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'classes'])) ?>">
|
||||
<input type="hidden" name="action" value="edit">
|
||||
<input type="hidden" name="id" value="<?= $row['id'] ?>">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name (EN)</label>
|
||||
<input type="text" name="name_en" class="form-control" value="<?= h($row['name_en']) ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name (AR)</label>
|
||||
<input type="text" name="name_ar" class="form-control" value="<?= h($row['name_ar']) ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description (EN)</label>
|
||||
<textarea name="description_en" class="form-control"><?= h($row['description_en']) ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description (AR)</label>
|
||||
<textarea name="description_ar" class="form-control"><?= h($row['description_ar']) ?></textarea>
|
||||
</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="4" class="text-center text-secondary py-3"><?= h(t('No classes found.', 'لا توجد صفوف.')) ?></td></tr>
|
||||
@ -159,4 +168,40 @@ if ($action === 'edit' || $action === 'add'):
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<!-- Add Class Modal -->
|
||||
<div class="modal fade" id="addClassModal" tabindex="-1" aria-labelledby="addClassModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header border-0 pb-0">
|
||||
<h5 class="modal-title section-title" id="addClassModalLabel"><?= h(t('Add Class', 'إضافة صف')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'classes'])) ?>">
|
||||
<input type="hidden" name="action" value="add">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name (EN)</label>
|
||||
<input type="text" name="name_en" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name (AR)</label>
|
||||
<input type="text" name="name_ar" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description (EN)</label>
|
||||
<textarea name="description_en" class="form-control"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description (AR)</label>
|
||||
<textarea name="description_ar" class="form-control"></textarea>
|
||||
</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 -->
|
||||
@ -10,167 +10,92 @@ $classes_stmt = db()->query("SELECT id, name_en, name_ar FROM classes ORDER BY i
|
||||
$all_classes = $classes_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($action === 'delete' && $id > 0) {
|
||||
$post_action = $_POST['action'] ?? $action;
|
||||
$post_id = (int)($_POST['id'] ?? $id);
|
||||
|
||||
if ($post_action === 'delete' && $post_id > 0) {
|
||||
$stmt = db()->prepare("DELETE FROM subjects WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$stmt->execute([$post_id]);
|
||||
header('Location: ' . app_url('admin.php', ['page' => 'subjects']));
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'edit' || $action === 'add') {
|
||||
$slug = $_POST['slug'] ?? '';
|
||||
if ($post_action === 'edit' || $post_action === 'add') {
|
||||
$class_id = !empty($_POST['class_id']) ? (int)$_POST['class_id'] : null;
|
||||
$title_en = $_POST['title_en'] ?? '';
|
||||
$title_ar = $_POST['title_ar'] ?? '';
|
||||
$summary_en = $_POST['summary_en'] ?? '';
|
||||
$summary_ar = $_POST['summary_ar'] ?? '';
|
||||
$teacher_en = $_POST['teacher_en'] ?? '';
|
||||
$teacher_ar = $_POST['teacher_ar'] ?? '';
|
||||
$meet_url = $_POST['meet_url'] ?? '';
|
||||
|
||||
if ($action === 'edit' && $id > 0) {
|
||||
$stmt = db()->prepare("UPDATE subjects SET slug=?, class_id=?, title_en=?, title_ar=?, summary_en=?, summary_ar=?, teacher_en=?, teacher_ar=?, meet_url=? WHERE id=?");
|
||||
$stmt->execute([$slug, $class_id, $title_en, $title_ar, $summary_en, $summary_ar, $teacher_en, $teacher_ar, $meet_url, $id]);
|
||||
if ($post_action === 'edit' && $post_id > 0) {
|
||||
$stmt = db()->prepare("UPDATE subjects SET class_id=?, title_en=?, title_ar=?, summary_en=?, summary_ar=? WHERE id=?");
|
||||
$stmt->execute([$class_id, $title_en, $title_ar, $summary_en, $summary_ar, $post_id]);
|
||||
} else {
|
||||
$stmt = db()->prepare("INSERT INTO subjects (slug, class_id, title_en, title_ar, summary_en, summary_ar, teacher_en, teacher_ar, meet_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$slug, $class_id, $title_en, $title_ar, $summary_en, $summary_ar, $teacher_en, $teacher_ar, $meet_url]);
|
||||
$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $title_en)));
|
||||
if (empty($slug)) $slug = 'subject';
|
||||
$slug .= '-' . substr(md5(uniqid()), 0, 5);
|
||||
|
||||
$stmt = db()->prepare("INSERT INTO subjects (slug, class_id, title_en, title_ar, summary_en, summary_ar) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$slug, $class_id, $title_en, $title_ar, $summary_en, $summary_ar]);
|
||||
}
|
||||
header('Location: ' . app_url('admin.php', ['page' => 'subjects']));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === 'edit' || $action === 'add'):
|
||||
$item = ['slug'=>'', 'class_id'=>null, 'title_en'=>'', 'title_ar'=>'', 'summary_en'=>'', 'summary_ar'=>'', 'teacher_en'=>'', 'teacher_ar'=>'', 'meet_url'=>''];
|
||||
if ($action === 'edit' && $id > 0) {
|
||||
$stmt = db()->prepare("SELECT * FROM subjects WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$item = $stmt->fetch(PDO::FETCH_ASSOC) ?: $item;
|
||||
}
|
||||
?>
|
||||
<div class="section-header mb-4">
|
||||
<div>
|
||||
<h1 class="section-title mb-2"><?= h($action === 'edit' ? t('Edit Subject', 'تعديل المادة') : t('Add Subject', 'إضافة مادة')) ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-card" style="max-width: 800px;">
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'subjects', 'action'=>$action, 'id'=>$id])) ?>">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Slug</label>
|
||||
<input type="text" name="slug" class="form-control" value="<?= h($item['slug']) ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= h(t('Class', 'الصف')) ?></label>
|
||||
<select name="class_id" class="form-control">
|
||||
<option value=""><?= h(t('-- Select Class --', '-- اختر الصف --')) ?></option>
|
||||
<?php foreach($all_classes as $c): ?>
|
||||
<option value="<?= $c['id'] ?>" <?= $item['class_id'] == $c['id'] ? 'selected' : '' ?>>
|
||||
<?= h(current_lang() === 'ar' ? $c['name_ar'] : $c['name_en']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
// list view
|
||||
$search = $_GET['search'] ?? '';
|
||||
$filter_class = $_GET['class_id'] ?? '';
|
||||
$page_num = max(1, (int)($_GET['p'] ?? 1));
|
||||
$limit = 10;
|
||||
$offset = ($page_num - 1) * $limit;
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Title (EN)</label>
|
||||
<input type="text" name="title_en" class="form-control" value="<?= h($item['title_en']) ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Title (AR)</label>
|
||||
<input type="text" name="title_ar" class="form-control" value="<?= h($item['title_ar']) ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
$where_clauses = [];
|
||||
$params = [];
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Summary (EN)</label>
|
||||
<textarea name="summary_en" class="form-control" rows="2"><?= h($item['summary_en']) ?></textarea>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Summary (AR)</label>
|
||||
<textarea name="summary_ar" class="form-control" rows="2"><?= h($item['summary_ar']) ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
if ($search !== '') {
|
||||
$where_clauses[] = "(s.title_en LIKE ? OR s.title_ar LIKE ?)";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
if ($filter_class !== '') {
|
||||
$where_clauses[] = "s.class_id = ?";
|
||||
$params[] = $filter_class;
|
||||
}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Teacher (EN)</label>
|
||||
<input type="text" name="teacher_en" class="form-control" value="<?= h($item['teacher_en']) ?>">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Teacher (AR)</label>
|
||||
<input type="text" name="teacher_ar" class="form-control" value="<?= h($item['teacher_ar']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
$where = "";
|
||||
if (count($where_clauses) > 0) {
|
||||
$where = "WHERE " . implode(" AND ", $where_clauses);
|
||||
}
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Meet URL</label>
|
||||
<input type="url" name="meet_url" class="form-control" value="<?= h($item['meet_url']) ?>">
|
||||
</div>
|
||||
$total_stmt = db()->prepare("SELECT COUNT(*) FROM subjects s $where");
|
||||
$total_stmt->execute($params);
|
||||
$total = $total_stmt->fetchColumn();
|
||||
$pages = ceil($total / $limit);
|
||||
|
||||
<button type="submit" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);">
|
||||
<?= h(t('Save', 'حفظ')) ?>
|
||||
</button>
|
||||
<a href="<?= h(app_url('admin.php', ['page'=>'subjects'])) ?>" class="btn btn-outline-secondary"><?= h(t('Cancel', 'إلغاء')) ?></a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php else: // list view
|
||||
$search = $_GET['search'] ?? '';
|
||||
$filter_class = $_GET['class_id'] ?? '';
|
||||
$page_num = max(1, (int)($_GET['p'] ?? 1));
|
||||
$limit = 10;
|
||||
$offset = ($page_num - 1) * $limit;
|
||||
|
||||
$where_clauses = [];
|
||||
$params = [];
|
||||
|
||||
if ($search !== '') {
|
||||
$where_clauses[] = "(s.title_en LIKE ? OR s.title_ar LIKE ?)";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
if ($filter_class !== '') {
|
||||
$where_clauses[] = "s.class_id = ?";
|
||||
$params[] = $filter_class;
|
||||
}
|
||||
|
||||
$where = "";
|
||||
if (count($where_clauses) > 0) {
|
||||
$where = "WHERE " . implode(" AND ", $where_clauses);
|
||||
}
|
||||
|
||||
$total_stmt = db()->prepare("SELECT COUNT(*) FROM subjects s $where");
|
||||
$total_stmt->execute($params);
|
||||
$total = $total_stmt->fetchColumn();
|
||||
$pages = ceil($total / $limit);
|
||||
|
||||
$stmt = db()->prepare("
|
||||
SELECT s.*, c.name_en AS class_name_en, c.name_ar AS class_name_ar
|
||||
FROM subjects s
|
||||
LEFT JOIN classes c ON s.class_id = c.id
|
||||
$where
|
||||
ORDER BY s.id DESC
|
||||
LIMIT $limit OFFSET $offset
|
||||
");
|
||||
$stmt->execute($params);
|
||||
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt = db()->prepare("
|
||||
SELECT s.*, c.name_en AS class_name_en, c.name_ar AS class_name_ar
|
||||
FROM subjects s
|
||||
LEFT JOIN classes c ON s.class_id = c.id
|
||||
$where
|
||||
ORDER BY s.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('Subjects', 'المواد')) ?></h1>
|
||||
</div>
|
||||
<a href="<?= h(app_url('admin.php', ['page'=>'subjects', 'action'=>'add'])) ?>" class="btn btn-primary" style="background-color: var(--accent); border-color: var(--accent);">+ <?= h(t('Add Subject', 'إضافة مادة')) ?></a>
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addSubjectModal" style="background-color: var(--accent); border-color: var(--accent);">+ <?= h(t('Add Subject', 'إضافة مادة')) ?></button>
|
||||
</div>
|
||||
|
||||
<div class="panel-card mb-4">
|
||||
<form method="get" class="d-flex gap-2 flex-wrap align-items-center">
|
||||
<input type="hidden" name="page" value="subjects">
|
||||
|
||||
<input type="text" name="search" class="form-control w-auto" placeholder="<?= h(t('Search title...', 'بحث في العنوان...')) ?>" value="<?= h($search) ?>">
|
||||
<input type="text" name="search" class="form-control w-auto" placeholder="<?= h(t('Search name...', 'بحث في الاسم...')) ?>" value="<?= h($search) ?>">
|
||||
|
||||
<select name="class_id" class="form-control w-auto">
|
||||
<option value=""><?= h(t('All Classes', 'جميع الصفوف')) ?></option>
|
||||
@ -194,9 +119,9 @@ if ($action === 'edit' || $action === 'add'):
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th><?= h(t('Subject', 'المادة')) ?></th>
|
||||
<th><?= h(t('Subject Name', 'اسم المادة')) ?></th>
|
||||
<th><?= h(t('Details', 'تفاصيل')) ?></th>
|
||||
<th><?= h(t('Class', 'الصف')) ?></th>
|
||||
<th><?= h(t('Teacher', 'المعلم')) ?></th>
|
||||
<th><?= h(t('Actions', 'إجراءات')) ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -206,7 +131,11 @@ if ($action === 'edit' || $action === 'add'):
|
||||
<td><?= h((string)$row['id']) ?></td>
|
||||
<td>
|
||||
<div class="fw-semibold"><?= h(current_lang() === 'ar' ? $row['title_ar'] : $row['title_en']) ?></div>
|
||||
<div class="small text-secondary"><?= h($row['slug']) ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="small text-secondary text-truncate" style="max-width: 250px;">
|
||||
<?= h(current_lang() === 'ar' ? $row['summary_ar'] : $row['summary_en']) ?>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($row['class_id']): ?>
|
||||
@ -218,15 +147,75 @@ if ($action === 'edit' || $action === 'add'):
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= h(current_lang() === 'ar' ? $row['teacher_ar'] : $row['teacher_en']) ?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= h(app_url('admin.php', ['page'=>'subjects', 'action'=>'edit', 'id'=>$row['id']])) ?>" class="btn btn-sm btn-outline-primary"><?= h(t('Edit', 'تعديل')) ?></a>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#editSubjectModal<?= $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>
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'subjects', '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"><?= h(t('Delete', 'حذف')) ?></button>
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Edit Subject Modal -->
|
||||
<div class="modal fade" id="editSubjectModal<?= $row['id'] ?>" tabindex="-1" aria-labelledby="editSubjectModalLabel<?= $row['id'] ?>" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header border-0 pb-0">
|
||||
<h5 class="modal-title section-title" id="editSubjectModalLabel<?= $row['id'] ?>"><?= h(t('Edit Subject', 'تعديل المادة')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'subjects'])) ?>">
|
||||
<input type="hidden" name="action" value="edit">
|
||||
<input type="hidden" name="id" value="<?= $row['id'] ?>">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 mb-3">
|
||||
<label class="form-label"><?= h(t('Class', 'الصف')) ?></label>
|
||||
<select name="class_id" class="form-control" required>
|
||||
<option value=""><?= h(t('-- Select Class --', '-- اختر الصف --')) ?></option>
|
||||
<?php foreach($all_classes as $c): ?>
|
||||
<option value="<?= $c['id'] ?>" <?= $row['class_id'] == $c['id'] ? 'selected' : '' ?>>
|
||||
<?= h(current_lang() === 'ar' ? $c['name_ar'] : $c['name_en']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= h(t('Name (English)', 'الاسم (بالانجليزية)')) ?></label>
|
||||
<input type="text" name="title_en" class="form-control" value="<?= h($row['title_en']) ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= h(t('Name (Arabic)', 'الاسم (بالعربية)')) ?></label>
|
||||
<input type="text" name="title_ar" class="form-control" value="<?= h($row['title_ar']) ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label"><?= h(t('Details (English)', 'تفاصيل (بالانجليزية)')) ?></label>
|
||||
<textarea name="summary_en" class="form-control" rows="3"><?= h($row['summary_en']) ?></textarea>
|
||||
</div>
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label"><?= h(t('Details (Arabic)', 'تفاصيل (بالعربية)')) ?></label>
|
||||
<textarea name="summary_ar" class="form-control" rows="3"><?= h($row['summary_ar']) ?></textarea>
|
||||
</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 Subject Modal -->
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php if(!$items): ?>
|
||||
<tr><td colspan="5" class="text-center text-secondary py-3"><?= h(t('No subjects found.', 'لا توجد مواد.')) ?></td></tr>
|
||||
@ -248,4 +237,61 @@ if ($action === 'edit' || $action === 'add'):
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<!-- Add Subject Modal -->
|
||||
<div class="modal fade" id="addSubjectModal" tabindex="-1" aria-labelledby="addSubjectModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header border-0 pb-0">
|
||||
<h5 class="modal-title section-title" id="addSubjectModalLabel"><?= h(t('Add Subject', 'إضافة مادة')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'subjects'])) ?>">
|
||||
<input type="hidden" name="action" value="add">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 mb-3">
|
||||
<label class="form-label"><?= h(t('Class', 'الصف')) ?></label>
|
||||
<select name="class_id" class="form-control" required>
|
||||
<option value=""><?= h(t('-- Select Class --', '-- اختر الصف --')) ?></option>
|
||||
<?php foreach($all_classes as $c): ?>
|
||||
<option value="<?= $c['id'] ?>">
|
||||
<?= h(current_lang() === 'ar' ? $c['name_ar'] : $c['name_en']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= h(t('Name (English)', 'الاسم (بالانجليزية)')) ?></label>
|
||||
<input type="text" name="title_en" class="form-control" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= h(t('Name (Arabic)', 'الاسم (بالعربية)')) ?></label>
|
||||
<input type="text" name="title_ar" class="form-control" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label"><?= h(t('Details (English)', 'تفاصيل (بالانجليزية)')) ?></label>
|
||||
<textarea name="summary_en" class="form-control" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="col-md-6 mb-4">
|
||||
<label class="form-label"><?= h(t('Details (Arabic)', 'تفاصيل (بالعربية)')) ?></label>
|
||||
<textarea name="summary_ar" class="form-control" rows="3"></textarea>
|
||||
</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 Subject Modal -->
|
||||
|
||||
282
admin_teachers.php
Normal file
282
admin_teachers.php
Normal file
@ -0,0 +1,282 @@
|
||||
<?php
|
||||
// admin_teachers.php
|
||||
require_once __DIR__ . '/includes/app.php';
|
||||
|
||||
$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) {
|
||||
$stmt = db()->prepare("DELETE FROM teachers WHERE id = ?");
|
||||
$stmt->execute([$post_id]);
|
||||
header('Location: ' . app_url('admin.php', ['page' => 'teachers']));
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($post_action === 'edit' || $post_action === 'add') {
|
||||
$name = $_POST['name'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
$phone = $_POST['phone'] ?? '';
|
||||
$bio = $_POST['bio'] ?? '';
|
||||
$raw_password = $_POST['password'] ?? '';
|
||||
$photo_path = '';
|
||||
$existing_password = '';
|
||||
|
||||
if ($post_action === 'edit' && $post_id > 0) {
|
||||
$stmt = db()->prepare("SELECT photo_path, password FROM teachers WHERE id = ?");
|
||||
$stmt->execute([$post_id]);
|
||||
$existing = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($existing) {
|
||||
$photo_path = $existing['photo_path'];
|
||||
$existing_password = $existing['password'];
|
||||
}
|
||||
}
|
||||
|
||||
$upload_dir = __DIR__ . '/assets/images/uploads/';
|
||||
if (!is_dir($upload_dir)) {
|
||||
mkdir($upload_dir, 0777, true);
|
||||
}
|
||||
|
||||
if (!empty($_FILES['photo']['tmp_name'])) {
|
||||
$filename = 'teacher_' . time() . '_' . basename($_FILES['photo']['name']);
|
||||
$target = $upload_dir . $filename;
|
||||
if (move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
|
||||
$photo_path = 'assets/images/uploads/' . $filename;
|
||||
}
|
||||
}
|
||||
|
||||
$final_password = '';
|
||||
if ($post_action === 'add') {
|
||||
$final_password = $raw_password ? password_hash($raw_password, PASSWORD_DEFAULT) : '';
|
||||
} else {
|
||||
if ($raw_password) {
|
||||
$final_password = password_hash($raw_password, PASSWORD_DEFAULT);
|
||||
} else {
|
||||
$final_password = $existing_password;
|
||||
}
|
||||
}
|
||||
|
||||
if ($post_action === 'edit' && $post_id > 0) {
|
||||
$stmt = db()->prepare("UPDATE teachers SET name=?, email=?, phone=?, bio=?, photo_path=?, password=? WHERE id=?");
|
||||
$stmt->execute([$name, $email, $phone, $bio, $photo_path, $final_password, $post_id]);
|
||||
} else {
|
||||
$stmt = db()->prepare("INSERT INTO teachers (name, email, phone, bio, photo_path, password) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $email, $phone, $bio, $photo_path, $final_password]);
|
||||
}
|
||||
header('Location: ' . app_url('admin.php', ['page' => 'teachers']));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 LIKE ? OR email LIKE ? OR phone LIKE ?";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
|
||||
$total_stmt = db()->prepare("SELECT COUNT(*) FROM teachers $where");
|
||||
$total_stmt->execute($params);
|
||||
$total = $total_stmt->fetchColumn();
|
||||
$pages = ceil($total / $limit);
|
||||
|
||||
$stmt = db()->prepare("SELECT * FROM teachers $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('Teachers', 'المعلمون')) ?></h1>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTeacherModal" style="background-color: var(--accent); border-color: var(--accent);">+ <?= h(t('Add Teacher', 'إضافة معلم')) ?></button>
|
||||
</div>
|
||||
|
||||
<div class="panel-card mb-4">
|
||||
<form method="get" class="d-flex gap-2 align-items-center">
|
||||
<input type="hidden" name="page" value="teachers">
|
||||
<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'=>'teachers'])) ?>" 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><?= h(t('Photo', 'الصورة')) ?></th>
|
||||
<th><?= h(t('Name', 'الاسم')) ?></th>
|
||||
<th><?= h(t('Contact', 'جهة الاتصال')) ?></th>
|
||||
<th><?= h(t('Actions', 'إجراءات')) ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($items as $row): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if(!empty($row['photo_path'])): ?>
|
||||
<img src="<?= h(asset_url($row['photo_path'])) ?>" alt="" style="width: 40px; height: 40px; border-radius: 50%; object-fit: cover;">
|
||||
<?php else: ?>
|
||||
<div class="bg-light text-secondary d-flex align-items-center justify-content-center" style="width: 40px; height: 40px; border-radius: 50%;">
|
||||
<?= h(strtoupper(substr($row['name'], 0, 1))) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="fw-semibold"><?= h($row['name']) ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<?php if (!empty($row['email'])): ?><div><small><?= h($row['email']) ?></small></div><?php endif; ?>
|
||||
<?php if (!empty($row['phone'])): ?><div><small><?= h($row['phone']) ?></small></div><?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#editTeacherModal<?= $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>
|
||||
<form method="post" action="<?= h(app_url('admin.php', ['page'=>'teachers', '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>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Edit Teacher Modal -->
|
||||
<div class="modal fade" id="editTeacherModal<?= $row['id'] ?>" tabindex="-1" aria-labelledby="editTeacherModalLabel<?= $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 pb-0">
|
||||
<h5 class="modal-title section-title" id="editTeacherModalLabel<?= $row['id'] ?>"><?= h(t('Edit Teacher', 'تعديل المعلم')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" enctype="multipart/form-data" action="<?= h(app_url('admin.php', ['page'=>'teachers'])) ?>">
|
||||
<input type="hidden" name="action" value="edit">
|
||||
<input type="hidden" name="id" value="<?= $row['id'] ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Name', 'الاسم')) ?></label>
|
||||
<input type="text" name="name" class="form-control" value="<?= h($row['name']) ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Email', 'البريد الإلكتروني')) ?></label>
|
||||
<input type="email" name="email" class="form-control" value="<?= h($row['email'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Phone', 'رقم الهاتف')) ?></label>
|
||||
<input type="tel" name="phone" class="form-control" value="<?= h($row['phone'] ?? '') ?>" dir="ltr">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">
|
||||
<?= h(t('Password', 'كلمة المرور')) ?>
|
||||
<small class="text-muted">(<?= h(t('Leave blank to keep current', 'اتركه فارغاً للاحتفاظ بكلمة المرور الحالية')) ?>)</small>
|
||||
</label>
|
||||
<input type="password" name="password" class="form-control" autocomplete="new-password">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Bio', 'نبذة')) ?></label>
|
||||
<textarea name="bio" class="form-control" rows="4"><?= h($row['bio'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label"><?= h(t('Photo', 'الصورة')) ?></label>
|
||||
<?php if (!empty($row['photo_path'])): ?>
|
||||
<div class="mb-2">
|
||||
<img src="<?= h(asset_url($row['photo_path'])) ?>" alt="Photo" style="height: 60px; border-radius: 4px; object-fit: cover;">
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<input type="file" name="photo" class="form-control" accept="image/*">
|
||||
</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 Teacher Modal -->
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php if(!$items): ?>
|
||||
<tr><td colspan="4" class="text-center text-secondary py-3"><?= h(t('No teachers 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'=>'teachers', 'p'=>$i, 'search'=>$search])) ?>"><?= $i ?></a>
|
||||
</li>
|
||||
<?php endfor; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Add Teacher Modal -->
|
||||
<div class="modal fade" id="addTeacherModal" tabindex="-1" aria-labelledby="addTeacherModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header border-0 pb-0">
|
||||
<h5 class="modal-title section-title" id="addTeacherModalLabel"><?= h(t('Add Teacher', 'إضافة معلم')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" enctype="multipart/form-data" action="<?= h(app_url('admin.php', ['page'=>'teachers'])) ?>">
|
||||
<input type="hidden" name="action" value="add">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Name', 'الاسم')) ?></label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Email', 'البريد الإلكتروني')) ?></label>
|
||||
<input type="email" name="email" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Phone', 'رقم الهاتف')) ?></label>
|
||||
<input type="tel" name="phone" class="form-control" dir="ltr">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Password', 'كلمة المرور')) ?></label>
|
||||
<input type="password" name="password" class="form-control" autocomplete="new-password" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(t('Bio', 'نبذة')) ?></label>
|
||||
<textarea name="bio" class="form-control" rows="4"></textarea>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label"><?= h(t('Photo', 'الصورة')) ?></label>
|
||||
<input type="file" name="photo" class="form-control" accept="image/*">
|
||||
</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 Teacher Modal -->
|
||||
Loading…
x
Reference in New Issue
Block a user