0) { require_permission('teachers', 'delete'); $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') { require_permission('teachers', $post_action === 'add' ? 'add' : 'edit'); $name = $_POST['name'] ?? ''; $email = $_POST['email'] ?? ''; $phone = $_POST['phone'] ?? ''; $bio = $_POST['bio'] ?? ''; $status = $_POST['status'] ?? 'active'; $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=?, status=? WHERE id=?"); $stmt->execute([$name, $email, $phone, $bio, $photo_path, $final_password, $status, $post_id]); } else { $stmt = db()->prepare("INSERT INTO teachers (name, email, phone, bio, photo_path, password, status) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $email, $phone, $bio, $photo_path, $final_password, $status]); } 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); ?>
| = h(t('Photo', 'الصورة')) ?> | = h(t('Name', 'الاسم')) ?> | = h(t('Status', 'الحالة')) ?> | = h(t('Contact', 'جهة الاتصال')) ?> | = h(t('Actions', 'إجراءات')) ?> |
|---|---|---|---|---|
|
= h(strtoupper(substr($row['name'], 0, 1))) ?>
|
= h($row['name']) ?>
|
= h(t('Inactive', 'غير نشط')) ?> = h(t('Active', 'نشط')) ?> |
= h($row['email']) ?>
= h($row['phone']) ?>
|
|
| = h(t('No teachers found.', 'لا يوجد معلمون.')) ?> | ||||