[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: students.php
<?php /** * Students Management Page * This page allows teachers to add and manage students in their groups */ require_once '../config/config.php'; requireLogin('teacher'); $database = new Database(); $conn = $database->getConnection(); $teacher_id = $_SESSION['teacher_id']; $message = ''; $message_type = ''; // Handle form submissions if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['action'])) { switch ($_POST['action']) { case 'add': $group_id = $_POST['group_id']; $name = trim($_POST['name']); $parent_phone = trim($_POST['parent_phone']); $student_phone = trim($_POST['student_phone']) ?: null; if (empty($group_id) || empty($name) || empty($parent_phone)) { $message = 'يرجى إدخال جميع البيانات المطلوبة'; $message_type = 'danger'; } else { // Verify group belongs to teacher $verify_query = "SELECT id FROM groups WHERE id = :group_id AND teacher_id = :teacher_id"; $verify_stmt = $conn->prepare($verify_query); $verify_stmt->bindParam(':group_id', $group_id); $verify_stmt->bindParam(':teacher_id', $teacher_id); $verify_stmt->execute(); if ($verify_stmt->rowCount() == 0) { $message = 'المجموعة غير صحيحة'; $message_type = 'danger'; } else { // Generate unique student code do { $student_code = generateStudentCode(); $check_query = "SELECT COUNT(*) as count FROM students WHERE student_code = :code"; $check_stmt = $conn->prepare($check_query); $check_stmt->bindParam(':code', $student_code); $check_stmt->execute(); $exists = $check_stmt->fetch(PDO::FETCH_ASSOC)['count'] > 0; } while ($exists); $query = "INSERT INTO students (group_id, name, student_code, parent_phone, student_phone) VALUES (:group_id, :name, :student_code, :parent_phone, :student_phone)"; $stmt = $conn->prepare($query); $stmt->bindParam(':group_id', $group_id); $stmt->bindParam(':name', $name); $stmt->bindParam(':student_code', $student_code); $stmt->bindParam(':parent_phone', $parent_phone); $stmt->bindParam(':student_phone', $student_phone); if ($stmt->execute()) { $message = 'تم إضافة الطالب بنجاح - كود الطالب: ' . $student_code; $message_type = 'success'; } else { $message = 'حدث خطأ أثناء إضافة الطالب'; $message_type = 'danger'; } } } break; case 'edit': $id = $_POST['id']; $name = trim($_POST['name']); $parent_phone = trim($_POST['parent_phone']); $student_phone = trim($_POST['student_phone']) ?: null; if (empty($id) || empty($name) || empty($parent_phone)) { $message = 'يرجى إدخال جميع البيانات المطلوبة'; $message_type = 'danger'; } else { // Verify student belongs to teacher's group $verify_query = "SELECT s.id FROM students s JOIN groups g ON s.group_id = g.id WHERE s.id = :id AND g.teacher_id = :teacher_id"; $verify_stmt = $conn->prepare($verify_query); $verify_stmt->bindParam(':id', $id); $verify_stmt->bindParam(':teacher_id', $teacher_id); $verify_stmt->execute(); if ($verify_stmt->rowCount() == 0) { $message = 'الطالب غير صحيح'; $message_type = 'danger'; } else { $query = "UPDATE students SET name = :name, parent_phone = :parent_phone, student_phone = :student_phone WHERE id = :id"; $stmt = $conn->prepare($query); $stmt->bindParam(':name', $name); $stmt->bindParam(':parent_phone', $parent_phone); $stmt->bindParam(':student_phone', $student_phone); $stmt->bindParam(':id', $id); if ($stmt->execute()) { $message = 'تم تحديث بيانات الطالب بنجاح'; $message_type = 'success'; } else { $message = 'حدث خطأ أثناء تحديث بيانات الطالب'; $message_type = 'danger'; } } } break; case 'toggle_status': $id = $_POST['id']; $is_active = $_POST['is_active'] == '1' ? 0 : 1; // Verify student belongs to teacher's group $verify_query = "SELECT s.id FROM students s JOIN groups g ON s.group_id = g.id WHERE s.id = :id AND g.teacher_id = :teacher_id"; $verify_stmt = $conn->prepare($verify_query); $verify_stmt->bindParam(':id', $id); $verify_stmt->bindParam(':teacher_id', $teacher_id); $verify_stmt->execute(); if ($verify_stmt->rowCount() == 0) { $message = 'الطالب غير صحيح'; $message_type = 'danger'; } else { $query = "UPDATE students SET is_active = :is_active WHERE id = :id"; $stmt = $conn->prepare($query); $stmt->bindParam(':is_active', $is_active); $stmt->bindParam(':id', $id); if ($stmt->execute()) { $status_text = $is_active ? 'تم تفعيل الطالب' : 'تم إيقاف الطالب'; $message = $status_text; $message_type = 'success'; } else { $message = 'حدث خطأ أثناء تحديث حالة الطالب'; $message_type = 'danger'; } } break; case 'import': $group_id = $_POST['group_id']; $students_data = trim($_POST['students_data']); if (empty($group_id) || empty($students_data)) { $message = 'يرجى إدخال جميع البيانات المطلوبة'; $message_type = 'danger'; } else { // Verify group belongs to teacher $verify_query = "SELECT id FROM groups WHERE id = :group_id AND teacher_id = :teacher_id"; $verify_stmt = $conn->prepare($verify_query); $verify_stmt->bindParam(':group_id', $group_id); $verify_stmt->bindParam(':teacher_id', $teacher_id); $verify_stmt->execute(); if ($verify_stmt->rowCount() == 0) { $message = 'المجموعة غير صحيحة'; $message_type = 'danger'; } else { // Parse students data $lines = explode("\n", $students_data); $imported_count = 0; $errors = []; foreach ($lines as $line_num => $line) { $line = trim($line); if (empty($line)) continue; $parts = array_map('trim', explode('|', $line)); if (count($parts) < 2) { $errors[] = "السطر " . ($line_num + 1) . ": تنسيق غير صحيح"; continue; } $name = $parts[0]; $parent_phone = $parts[1]; $student_phone = isset($parts[2]) ? $parts[2] : null; if (empty($name) || empty($parent_phone)) { $errors[] = "السطر " . ($line_num + 1) . ": اسم الطالب ورقم هاتف ولي الأمر مطلوبان"; continue; } // Generate unique student code do { $student_code = generateStudentCode(); $check_query = "SELECT COUNT(*) as count FROM students WHERE student_code = :code"; $check_stmt = $conn->prepare($check_query); $check_stmt->bindParam(':code', $student_code); $check_stmt->execute(); $exists = $check_stmt->fetch(PDO::FETCH_ASSOC)['count'] > 0; } while ($exists); // Insert student $insert_query = "INSERT INTO students (group_id, name, student_code, parent_phone, student_phone) VALUES (:group_id, :name, :student_code, :parent_phone, :student_phone)"; $insert_stmt = $conn->prepare($insert_query); $insert_stmt->bindParam(':group_id', $group_id); $insert_stmt->bindParam(':name', $name); $insert_stmt->bindParam(':student_code', $student_code); $insert_stmt->bindParam(':parent_phone', $parent_phone); $insert_stmt->bindParam(':student_phone', $student_phone); if ($insert_stmt->execute()) { $imported_count++; } else { $errors[] = "السطر " . ($line_num + 1) . ": فشل في إضافة الطالب " . $name; } } $message = "تم استيراد {$imported_count} طالب بنجاح"; if (!empty($errors)) { $message .= "<br><br>أخطاء:<br>" . implode("<br>", $errors); } $message_type = 'success'; } } break; } } } // Get selected group ID from URL $selected_group_id = $_GET['group_id'] ?? null; // Get teacher's groups $groups_query = "SELECT g.id, g.name, CONCAT(st.name, ' - ', gr.name, ' - ', sub.name) as full_info FROM groups g JOIN grades gr ON g.grade_id = gr.id JOIN stages st ON gr.stage_id = st.id JOIN subjects sub ON g.subject_id = sub.id WHERE g.teacher_id = :teacher_id AND g.is_active = 1 ORDER BY g.name"; $groups_stmt = $conn->prepare($groups_query); $groups_stmt->bindParam(':teacher_id', $teacher_id); $groups_stmt->execute(); $groups = $groups_stmt->fetchAll(PDO::FETCH_ASSOC); // Get students for selected group $students = []; if ($selected_group_id) { $students_query = "SELECT s.*, (SELECT COUNT(*) FROM attendance a WHERE a.student_id = s.id AND a.is_present = 0) as absence_count FROM students s JOIN groups g ON s.group_id = g.id WHERE s.group_id = :group_id AND g.teacher_id = :teacher_id ORDER BY s.name"; $students_stmt = $conn->prepare($students_query); $students_stmt->bindParam(':group_id', $selected_group_id); $students_stmt->bindParam(':teacher_id', $teacher_id); $students_stmt->execute(); $students = $students_stmt->fetchAll(PDO::FETCH_ASSOC); } $page_title = 'إدارة الطلاب'; include '../includes/header.php'; ?> <div class="container-fluid"> <div class="row"> <!-- Sidebar --> <div class="col-lg-3 col-md-4 sidebar p-0"> <div class="d-flex flex-column h-100"> <div class="p-3 text-white"> <h4 class="mb-0"> <i class="fas fa-chalkboard-teacher me-2"></i> لوحة المعلم </h4> <small>مرحباً <?php echo $_SESSION['teacher_name']; ?></small> </div> <nav class="nav nav-pills flex-column p-3"> <a class="nav-link" href="dashboard.php"> <i class="fas fa-tachometer-alt me-2"></i>الرئيسية </a> <a class="nav-link" href="subjects_grades.php"> <i class="fas fa-book me-2"></i>المواد والصفوف </a> <a class="nav-link" href="groups.php"> <i class="fas fa-users me-2"></i>المجموعات </a> <a class="nav-link active" href="students.php"> <i class="fas fa-user-graduate me-2"></i>الطلاب </a> <a class="nav-link" href="attendance.php"> <i class="fas fa-clipboard-check me-2"></i>تسجيل الحضور </a> <a class="nav-link" href="makeup_sessions.php"> <i class="fas fa-redo me-2"></i>حصص التعويض </a> <a class="nav-link" href="reports.php"> <i class="fas fa-chart-bar me-2"></i>التقارير </a> <div class="mt-auto"> <a class="nav-link text-light" href="../logout.php"> <i class="fas fa-sign-out-alt me-2"></i>تسجيل الخروج </a> </div> </nav> </div> </div> <!-- Main Content --> <div class="col-lg-9 col-md-8 main-content p-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2>إدارة الطلاب</h2> <?php if ($selected_group_id): ?> <div> <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addStudentModal"> <i class="fas fa-plus me-2"></i>إضافة طالب جديد </button> <button class="btn btn-success ms-2" data-bs-toggle="modal" data-bs-target="#importStudentsModal"> <i class="fas fa-upload me-2"></i>استيراد طلاب </button> </div> <?php endif; ?> </div> <!-- Messages --> <?php if (!empty($message)): ?> <div class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert"> <i class="fas fa-<?php echo $message_type == 'success' ? 'check-circle' : 'exclamation-triangle'; ?> me-2"></i> <?php echo $message; ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <!-- Group Selection --> <div class="card mb-4"> <div class="card-header"> <h5 class="mb-0">اختيار المجموعة</h5> </div> <div class="card-body"> <?php if (empty($groups)): ?> <div class="alert alert-warning"> <i class="fas fa-exclamation-triangle me-2"></i> لا توجد مجموعات متاحة. يرجى إنشاء مجموعة أولاً. <a href="groups.php" class="btn btn-sm btn-warning ms-2"> <i class="fas fa-plus me-1"></i>إنشاء مجموعة </a> </div> <?php else: ?> <div class="row"> <?php foreach ($groups as $group): ?> <div class="col-md-6 col-lg-4 mb-3"> <div class="card group-card <?php echo $selected_group_id == $group['id'] ? 'border-primary' : ''; ?>"> <div class="card-body text-center"> <h6 class="card-title"><?php echo htmlspecialchars($group['name']); ?></h6> <small class="text-muted"><?php echo htmlspecialchars($group['full_info']); ?></small> <div class="mt-2"> <a href="students.php?group_id=<?php echo $group['id']; ?>" class="btn btn-sm btn-outline-primary"> اختيار المجموعة </a> </div> </div> </div> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> </div> <!-- Students List --> <?php if ($selected_group_id && !empty($students)): ?> <div class="card"> <div class="card-header"> <h5 class="mb-0">قائمة الطلاب</h5> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-striped"> <thead> <tr> <th>اسم الطالب</th> <th>كود الطالب</th> <th>هاتف ولي الأمر</th> <th>هاتف الطالب</th> <th>عدد الغيابات</th> <th>الحالة</th> <th>الإجراءات</th> </tr> </thead> <tbody> <?php foreach ($students as $student): ?> <tr <?php echo $student['absence_count'] > 3 ? 'class="table-warning"' : ''; ?>> <td> <strong><?php echo htmlspecialchars($student['name']); ?></strong> <?php if ($student['absence_count'] > 3): ?> <span class="badge bg-danger ms-2">يحتاج متابعة</span> <?php endif; ?> </td> <td> <span class="badge bg-info"><?php echo $student['student_code']; ?></span> </td> <td><?php echo htmlspecialchars($student['parent_phone']); ?></td> <td><?php echo $student['student_phone'] ? htmlspecialchars($student['student_phone']) : '-'; ?></td> <td> <span class="badge bg-<?php echo $student['absence_count'] > 3 ? 'danger' : 'secondary'; ?>"> <?php echo $student['absence_count']; ?> غياب </span> </td> <td> <?php if ($student['is_active']): ?> <span class="badge bg-success">نشط</span> <?php else: ?> <span class="badge bg-secondary">متوقف</span> <?php endif; ?> </td> <td> <div class="btn-group" role="group"> <button class="btn btn-sm btn-outline-warning" onclick="editStudent(<?php echo htmlspecialchars(json_encode($student)); ?>)" title="تعديل"> <i class="fas fa-edit"></i> </button> <form method="POST" style="display: inline;"> <input type="hidden" name="action" value="toggle_status"> <input type="hidden" name="id" value="<?php echo $student['id']; ?>"> <input type="hidden" name="is_active" value="<?php echo $student['is_active']; ?>"> <button type="submit" class="btn btn-sm btn-outline-<?php echo $student['is_active'] ? 'secondary' : 'success'; ?>" title="<?php echo $student['is_active'] ? 'إيقاف' : 'تفعيل'; ?>" onclick="return confirm('هل أنت متأكد من <?php echo $student['is_active'] ? 'إيقاف' : 'تفعيل'; ?> هذا الطالب؟')"> <i class="fas fa-<?php echo $student['is_active'] ? 'pause' : 'play'; ?>"></i> </button> </form> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php elseif ($selected_group_id): ?> <div class="card"> <div class="card-body text-center py-5"> <i class="fas fa-user-graduate fa-3x text-muted mb-3"></i> <h5>لا يوجد طلاب في هذه المجموعة</h5> <p class="text-muted">يرجى إضافة طلاب للمجموعة أولاً</p> <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addStudentModal"> <i class="fas fa-plus me-2"></i>إضافة طالب جديد </button> <button class="btn btn-success ms-2" data-bs-toggle="modal" data-bs-target="#importStudentsModal"> <i class="fas fa-upload me-2"></i>استيراد طلاب </button> </div> </div> <?php endif; ?> </div> </div> </div> <!-- Add Student Modal --> <div class="modal fade" id="addStudentModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">إضافة طالب جديد</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST" action=""> <div class="modal-body"> <input type="hidden" name="group_id" value="<?php echo $selected_group_id; ?>"> <input type="hidden" name="action" value="add"> <div class="mb-3"> <label for="studentName" class="form-label">اسم الطالب</label> <input type="text" class="form-control" id="studentName" name="name" required placeholder="مثال: أحمد محمد علي"> </div> <div class="mb-3"> <label for="parentPhone" class="form-label">رقم هاتف ولي الأمر</label> <input type="tel" class="form-control" id="parentPhone" name="parent_phone" required placeholder="مثال: 01234567890"> </div> <div class="mb-3"> <label for="studentPhone" class="form-label">رقم هاتف الطالب (اختياري)</label> <input type="tel" class="form-control" id="studentPhone" name="student_phone" placeholder="مثال: 01234567890"> </div> <div class="alert alert-info"> <i class="fas fa-info-circle me-2"></i> سيتم إنشاء كود طالب تلقائياً عند الإضافة </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-primary"> <i class="fas fa-save me-2"></i>إضافة الطالب </button> </div> </form> </div> </div> </div> <!-- Edit Student Modal --> <div class="modal fade" id="editStudentModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">تعديل بيانات الطالب</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST" action=""> <div class="modal-body"> <input type="hidden" id="editStudentId" name="id"> <input type="hidden" name="action" value="edit"> <div class="mb-3"> <label for="editStudentName" class="form-label">اسم الطالب</label> <input type="text" class="form-control" id="editStudentName" name="name" required> </div> <div class="mb-3"> <label for="editParentPhone" class="form-label">رقم هاتف ولي الأمر</label> <input type="tel" class="form-control" id="editParentPhone" name="parent_phone" required> </div> <div class="mb-3"> <label for="editStudentPhone" class="form-label">رقم هاتف الطالب (اختياري)</label> <input type="tel" class="form-control" id="editStudentPhone" name="student_phone"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-warning"> <i class="fas fa-save me-2"></i>حفظ التغييرات </button> </div> </form> </div> </div> </div> <!-- Import Students Modal --> <div class="modal fade" id="importStudentsModal" tabindex="-1"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">استيراد طلاب دفعة واحدة</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST" action=""> <div class="modal-body"> <input type="hidden" name="group_id" value="<?php echo $selected_group_id; ?>"> <input type="hidden" name="action" value="import"> <div class="alert alert-info"> <h6><i class="fas fa-info-circle me-2"></i>تعليمات الاستيراد:</h6> <p class="mb-2">أدخل بيانات الطلاب كل طالب في سطر منفصل بالتنسيق التالي:</p> <code>اسم الطالب | رقم هاتف ولي الأمر | رقم هاتف الطالب (اختياري)</code> <hr> <strong>مثال:</strong><br> <code>أحمد محمد علي | 01234567890 | 01987654321</code><br> <code>فاطمة أحمد | 01111111111</code><br> <code>محمد عبدالله | 01222222222 | 01333333333</code> </div> <div class="mb-3"> <label for="studentsData" class="form-label">بيانات الطلاب</label> <textarea class="form-control" id="studentsData" name="students_data" rows="10" placeholder="أدخل بيانات الطلاب هنا..." required></textarea> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-success"> <i class="fas fa-upload me-2"></i>استيراد الطلاب </button> </div> </form> </div> </div> </div> <style> .group-card { transition: all 0.3s ease; cursor: pointer; } .group-card:hover { transform: translateY(-2px); box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.1); } .table-warning { background-color: #fff3cd !important; } </style> <script> function editStudent(student) { document.getElementById('editStudentId').value = student.id; document.getElementById('editStudentName').value = student.name; document.getElementById('editParentPhone').value = student.parent_phone; document.getElementById('editStudentPhone').value = student.student_phone || ''; const modal = new bootstrap.Modal(document.getElementById('editStudentModal')); modal.show(); } </script> <?php include '../includes/footer.php'; ?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285