0) { require_permission('students', 'delete'); $stmt = db()->prepare("DELETE FROM student_subscriptions WHERE id = ?"); $stmt->execute([$post_id]); header('Location: ' . app_url('admin.php', ['page' => 'students'])); exit; } if ($post_action === 'edit' || $post_action === 'add') { require_permission('students', $post_action === 'add' ? 'add' : 'edit'); $full_name = $_POST['full_name'] ?? ''; $email = $_POST['email'] ?? ''; $whatsapp = $_POST['whatsapp'] ?? ''; $plan_key = $_POST['plan_key'] ?? ''; $payment_status = $_POST['payment_status'] ?? 'active'; $status = $_POST['status'] ?? 'active'; $civil_id = $_POST['civil_id'] ?? ''; $picture = null; if ($post_action === 'edit' && $post_id > 0) { $stmt = db()->prepare("SELECT picture FROM student_subscriptions 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 student_subscriptions SET full_name=?, email=?, whatsapp=?, plan_key=?, payment_status=?, status=?, civil_id=?, picture=? WHERE id=?"); $stmt->execute([$full_name, $email, $whatsapp, $plan_key, $payment_status, $status, $civil_id, $picture, $post_id]); } else { $stmt = db()->prepare("INSERT INTO student_subscriptions (full_name, email, whatsapp, plan_key, payment_status, status, civil_id, picture) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$full_name, $email, $whatsapp, $plan_key, $payment_status, $status, $civil_id, $picture]); } header('Location: ' . app_url('admin.php', ['page' => 'students'])); 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 full_name LIKE ? OR email LIKE ? OR whatsapp LIKE ?"; $params = ["%$search%", "%$search%", "%$search%"]; } $count_stmt = db()->prepare("SELECT COUNT(*) FROM student_subscriptions $where"); $count_stmt->execute($params); $total_items = $count_stmt->fetchColumn(); $total_pages = ceil($total_items / $limit); $stmt = db()->prepare("SELECT * FROM student_subscriptions $where ORDER BY id DESC LIMIT $limit OFFSET $offset"); $stmt->execute($params); $items = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>
| = h(t('Name', 'الاسم')) ?> | = h(t('Status', 'الحالة')) ?> | = h(t('Email', 'البريد الإلكتروني')) ?> | = h(t('WhatsApp', 'واتساب')) ?> | = h(t('Plan', 'الخطة')) ?> | = h(t('Payment', 'الدفع')) ?> | = h(t('Actions', 'إجراءات')) ?> |
|---|---|---|---|---|---|---|
|
= h($row['full_name']) ?>
|
= h(t('Active', 'نشط')) ?> = h(t('Inactive', 'غير نشط')) ?> | = h($row['email']) ?> | = h($row['whatsapp']) ?> | = h($row['plan_key']) ?> | = h(t('Active', 'نشط')) ?> = h($row['payment_status']) ?> | |
| = h(t('No students found.', 'لم يتم العثور على طلاب.')) ?> | ||||||