[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: reports.php
<?php /** * Reports Page * This page allows teachers to generate comprehensive student and group reports */ require_once '../config/config.php'; requireLogin('teacher'); $database = new Database(); $conn = $database->getConnection(); $teacher_id = $_SESSION['teacher_id']; // 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 = []; $selected_group_id = $_GET['group_id'] ?? null; if ($selected_group_id) { $students_query = "SELECT s.id, s.name, s.student_code FROM students s JOIN groups g ON s.group_id = g.id WHERE s.group_id = :group_id AND g.teacher_id = :teacher_id AND s.is_active = 1 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); } // Generate report if requested $report_data = null; $report_type = $_GET['report_type'] ?? null; $student_id = $_GET['student_id'] ?? null; $date_from = $_GET['date_from'] ?? date('Y-m-01'); $date_to = $_GET['date_to'] ?? date('Y-m-t'); if ($report_type && ($selected_group_id || $student_id)) { if ($report_type === 'student' && $student_id) { // Student individual report $student_query = "SELECT s.*, g.name as group_name, CONCAT(st.name, ' - ', gr.name, ' - ', sub.name) as full_info FROM students s JOIN groups g ON s.group_id = g.id 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 s.id = :student_id"; $student_stmt = $conn->prepare($student_query); $student_stmt->bindParam(':student_id', $student_id); $student_stmt->execute(); $student_info = $student_stmt->fetch(PDO::FETCH_ASSOC); if ($student_info) { // Get attendance data $attendance_query = "SELECT COUNT(*) as total_sessions, SUM(CASE WHEN is_present = 1 THEN 1 ELSE 0 END) as present_sessions, SUM(CASE WHEN is_present = 0 THEN 1 ELSE 0 END) as absent_sessions, AVG(CASE WHEN has_test = 1 AND test_total_score > 0 THEN (student_test_score / test_total_score * 100) END) as test_average FROM attendance WHERE student_id = :student_id AND session_date BETWEEN :date_from AND :date_to"; $attendance_stmt = $conn->prepare($attendance_query); $attendance_stmt->bindParam(':student_id', $student_id); $attendance_stmt->bindParam(':date_from', $date_from); $attendance_stmt->bindParam(':date_to', $date_to); $attendance_stmt->execute(); $attendance_stats = $attendance_stmt->fetch(PDO::FETCH_ASSOC); // Get homework level distribution $homework_query = "SELECT homework_level, COUNT(*) as count FROM attendance WHERE student_id = :student_id AND homework_level IS NOT NULL AND session_date BETWEEN :date_from AND :date_to GROUP BY homework_level"; $homework_stmt = $conn->prepare($homework_query); $homework_stmt->bindParam(':student_id', $student_id); $homework_stmt->bindParam(':date_from', $date_from); $homework_stmt->bindParam(':date_to', $date_to); $homework_stmt->execute(); $homework_stats = $homework_stmt->fetchAll(PDO::FETCH_ASSOC); // Get makeup sessions $makeup_query = "SELECT COUNT(*) as makeup_count FROM makeup_sessions WHERE student_id = :student_id AND session_date BETWEEN :date_from AND :date_to"; $makeup_stmt = $conn->prepare($makeup_query); $makeup_stmt->bindParam(':student_id', $student_id); $makeup_stmt->bindParam(':date_from', $date_from); $makeup_stmt->bindParam(':date_to', $date_to); $makeup_stmt->execute(); $makeup_stats = $makeup_stmt->fetch(PDO::FETCH_ASSOC); // Get recent attendance details $details_query = "SELECT session_date, session_time, is_present, homework_level, has_test, test_total_score, student_test_score, teacher_notes FROM attendance WHERE student_id = :student_id AND session_date BETWEEN :date_from AND :date_to ORDER BY session_date DESC, session_time DESC"; $details_stmt = $conn->prepare($details_query); $details_stmt->bindParam(':student_id', $student_id); $details_stmt->bindParam(':date_from', $date_from); $details_stmt->bindParam(':date_to', $date_to); $details_stmt->execute(); $attendance_details = $details_stmt->fetchAll(PDO::FETCH_ASSOC); $report_data = [ 'type' => 'student', 'student' => $student_info, 'attendance' => $attendance_stats, 'homework' => $homework_stats, 'makeup' => $makeup_stats, 'details' => $attendance_details ]; } } elseif ($report_type === 'group' && $selected_group_id) { // Group report $group_query = "SELECT g.name as group_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.id = :group_id AND g.teacher_id = :teacher_id"; $group_stmt = $conn->prepare($group_query); $group_stmt->bindParam(':group_id', $selected_group_id); $group_stmt->bindParam(':teacher_id', $teacher_id); $group_stmt->execute(); $group_info = $group_stmt->fetch(PDO::FETCH_ASSOC); if ($group_info) { // Get group statistics $group_stats_query = "SELECT s.id, s.name, s.student_code, COUNT(a.id) as total_sessions, SUM(CASE WHEN a.is_present = 1 THEN 1 ELSE 0 END) as present_sessions, SUM(CASE WHEN a.is_present = 0 THEN 1 ELSE 0 END) as absent_sessions, AVG(CASE WHEN a.has_test = 1 AND a.test_total_score > 0 THEN (a.student_test_score / a.test_total_score * 100) END) as test_average, (SELECT COUNT(*) FROM makeup_sessions ms WHERE ms.student_id = s.id AND ms.session_date BETWEEN :date_from AND :date_to) as makeup_count FROM students s LEFT JOIN attendance a ON s.id = a.student_id AND a.session_date BETWEEN :date_from2 AND :date_to2 WHERE s.group_id = :group_id AND s.is_active = 1 GROUP BY s.id ORDER BY s.name"; $group_stats_stmt = $conn->prepare($group_stats_query); $group_stats_stmt->bindParam(':group_id', $selected_group_id); $group_stats_stmt->bindParam(':date_from', $date_from); $group_stats_stmt->bindParam(':date_to', $date_to); $group_stats_stmt->bindParam(':date_from2', $date_from); $group_stats_stmt->bindParam(':date_to2', $date_to); $group_stats_stmt->execute(); $group_students = $group_stats_stmt->fetchAll(PDO::FETCH_ASSOC); $report_data = [ 'type' => 'group', 'group' => $group_info, 'students' => $group_students ]; } } } $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" 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 active" 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> </div> <!-- Report Filters --> <div class="card mb-4"> <div class="card-header"> <h5 class="mb-0">إعدادات التقرير</h5> </div> <div class="card-body"> <form method="GET" action="reports.php"> <div class="row"> <div class="col-md-3 mb-3"> <label for="reportType" class="form-label">نوع التقرير</label> <select class="form-select" id="reportType" name="report_type" onchange="toggleReportFields()" required> <option value="">اختر نوع التقرير</option> <option value="student" <?php echo $report_type === 'student' ? 'selected' : ''; ?>>تقرير طالب</option> <option value="group" <?php echo $report_type === 'group' ? 'selected' : ''; ?>>تقرير مجموعة</option> </select> </div> <div class="col-md-3 mb-3"> <label for="groupSelect" class="form-label">المجموعة</label> <select class="form-select" id="groupSelect" name="group_id" onchange="loadStudents()" required> <option value="">اختر المجموعة</option> <?php foreach ($groups as $group): ?> <option value="<?php echo $group['id']; ?>" <?php echo $selected_group_id == $group['id'] ? 'selected' : ''; ?>> <?php echo htmlspecialchars($group['name']); ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-3 mb-3" id="studentField" style="display: none;"> <label for="studentSelect" class="form-label">الطالب</label> <select class="form-select" id="studentSelect" name="student_id"> <option value="">اختر الطالب</option> <?php foreach ($students as $student): ?> <option value="<?php echo $student['id']; ?>" <?php echo $student_id == $student['id'] ? 'selected' : ''; ?>> <?php echo htmlspecialchars($student['name']); ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-3 mb-3"> <label for="dateFrom" class="form-label">من تاريخ</label> <input type="date" class="form-control" id="dateFrom" name="date_from" value="<?php echo $date_from; ?>" required> </div> <div class="col-md-3 mb-3"> <label for="dateTo" class="form-label">إلى تاريخ</label> <input type="date" class="form-control" id="dateTo" name="date_to" value="<?php echo $date_to; ?>" required> </div> <div class="col-md-3 mb-3 d-flex align-items-end"> <button type="submit" class="btn btn-primary w-100"> <i class="fas fa-chart-bar me-2"></i>إنشاء التقرير </button> </div> </div> </form> </div> </div> <!-- Report Results --> <?php if ($report_data): ?> <?php if ($report_data['type'] === 'student'): ?> <!-- Student Report --> <div class="card mb-4"> <div class="card-header d-flex justify-content-between align-items-center"> <h5 class="mb-0">تقرير الطالب</h5> <button class="btn btn-sm btn-outline-primary" onclick="window.print()"> <i class="fas fa-print me-1"></i>طباعة </button> </div> <div class="card-body"> <!-- Student Info --> <div class="row mb-4"> <div class="col-md-6"> <h6 class="text-primary">معلومات الطالب</h6> <p><strong>الاسم:</strong> <?php echo htmlspecialchars($report_data['student']['name']); ?></p> <p><strong>كود الطالب:</strong> <?php echo $report_data['student']['student_code']; ?></p> <p><strong>المجموعة:</strong> <?php echo htmlspecialchars($report_data['student']['group_name']); ?></p> </div> <div class="col-md-6"> <h6 class="text-primary">فترة التقرير</h6> <p><strong>من:</strong> <?php echo date('Y/m/d', strtotime($date_from)); ?></p> <p><strong>إلى:</strong> <?php echo date('Y/m/d', strtotime($date_to)); ?></p> </div> </div> <!-- Statistics --> <div class="row mb-4"> <div class="col-md-3"> <div class="card bg-primary text-white"> <div class="card-body text-center"> <h3><?php echo $report_data['attendance']['total_sessions'] ?: 0; ?></h3> <p class="mb-0">إجمالي الحصص</p> </div> </div> </div> <div class="col-md-3"> <div class="card bg-success text-white"> <div class="card-body text-center"> <h3><?php echo $report_data['attendance']['present_sessions'] ?: 0; ?></h3> <p class="mb-0">حصص الحضور</p> </div> </div> </div> <div class="col-md-3"> <div class="card bg-danger text-white"> <div class="card-body text-center"> <h3><?php echo $report_data['attendance']['absent_sessions'] ?: 0; ?></h3> <p class="mb-0">حصص الغياب</p> </div> </div> </div> <div class="col-md-3"> <div class="card bg-info text-white"> <div class="card-body text-center"> <h3><?php echo $report_data['makeup']['makeup_count'] ?: 0; ?></h3> <p class="mb-0">حصص التعويض</p> </div> </div> </div> </div> <!-- Test Average --> <?php if ($report_data['attendance']['test_average']): ?> <div class="row mb-4"> <div class="col-md-6"> <div class="card"> <div class="card-header"> <h6 class="mb-0">متوسط الدرجات</h6> </div> <div class="card-body text-center"> <h2 class="text-primary"><?php echo number_format($report_data['attendance']['test_average'], 1); ?>%</h2> </div> </div> </div> <div class="col-md-6"> <div class="card"> <div class="card-header"> <h6 class="mb-0">نسبة الحضور</h6> </div> <div class="card-body text-center"> <?php $attendance_percentage = $report_data['attendance']['total_sessions'] > 0 ? ($report_data['attendance']['present_sessions'] / $report_data['attendance']['total_sessions']) * 100 : 0; ?> <h2 class="text-success"><?php echo number_format($attendance_percentage, 1); ?>%</h2> </div> </div> </div> </div> <?php endif; ?> <!-- Homework Distribution --> <?php if (!empty($report_data['homework'])): ?> <div class="card mb-4"> <div class="card-header"> <h6 class="mb-0">توزيع مستويات الواجبات</h6> </div> <div class="card-body"> <div class="row"> <?php foreach ($report_data['homework'] as $homework): ?> <div class="col-md-2 text-center"> <span class="badge bg-primary p-2"><?php echo $homework['count']; ?></span> <p class="small mt-1"><?php echo $homework['homework_level']; ?></p> </div> <?php endforeach; ?> </div> </div> </div> <?php endif; ?> <!-- Attendance Details --> <?php if (!empty($report_data['details'])): ?> <div class="card"> <div class="card-header"> <h6 class="mb-0">تفاصيل الحضور</h6> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-sm"> <thead> <tr> <th>التاريخ</th> <th>الوقت</th> <th>الحضور</th> <th>الواجب</th> <th>الاختبار</th> <th>ملاحظات</th> </tr> </thead> <tbody> <?php foreach ($report_data['details'] as $detail): ?> <tr> <td><?php echo date('Y/m/d', strtotime($detail['session_date'])); ?></td> <td><?php echo date('g:i A', strtotime($detail['session_time'])); ?></td> <td> <span class="badge bg-<?php echo $detail['is_present'] ? 'success' : 'danger'; ?>"> <?php echo $detail['is_present'] ? 'حاضر' : 'غائب'; ?> </span> </td> <td><?php echo $detail['homework_level'] ?: '-'; ?></td> <td> <?php if ($detail['has_test']): ?> <?php echo $detail['student_test_score']; ?>/<?php echo $detail['test_total_score']; ?> <?php else: ?> - <?php endif; ?> </td> <td><?php echo $detail['teacher_notes'] ? htmlspecialchars($detail['teacher_notes']) : '-'; ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php endif; ?> </div> </div> <?php elseif ($report_data['type'] === 'group'): ?> <!-- Group Report --> <div class="card"> <div class="card-header d-flex justify-content-between align-items-center"> <h5 class="mb-0">تقرير المجموعة</h5> <button class="btn btn-sm btn-outline-primary" onclick="window.print()"> <i class="fas fa-print me-1"></i>طباعة </button> </div> <div class="card-body"> <!-- Group Info --> <div class="row mb-4"> <div class="col-md-6"> <h6 class="text-primary">معلومات المجموعة</h6> <p><strong>اسم المجموعة:</strong> <?php echo htmlspecialchars($report_data['group']['group_name']); ?></p> <p><strong>التفاصيل:</strong> <?php echo htmlspecialchars($report_data['group']['full_info']); ?></p> </div> <div class="col-md-6"> <h6 class="text-primary">فترة التقرير</h6> <p><strong>من:</strong> <?php echo date('Y/m/d', strtotime($date_from)); ?></p> <p><strong>إلى:</strong> <?php echo date('Y/m/d', strtotime($date_to)); ?></p> </div> </div> <!-- Students Statistics --> <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> <th>حصص التعويض</th> </tr> </thead> <tbody> <?php foreach ($report_data['students'] as $student): ?> <tr> <td><?php echo htmlspecialchars($student['name']); ?></td> <td><span class="badge bg-info"><?php echo $student['student_code']; ?></span></td> <td><?php echo $student['total_sessions'] ?: 0; ?></td> <td><span class="badge bg-success"><?php echo $student['present_sessions'] ?: 0; ?></span></td> <td><span class="badge bg-danger"><?php echo $student['absent_sessions'] ?: 0; ?></span></td> <td> <?php $attendance_rate = $student['total_sessions'] > 0 ? ($student['present_sessions'] / $student['total_sessions']) * 100 : 0; ?> <span class="badge bg-<?php echo $attendance_rate >= 80 ? 'success' : ($attendance_rate >= 60 ? 'warning' : 'danger'); ?>"> <?php echo number_format($attendance_rate, 1); ?>% </span> </td> <td> <?php if ($student['test_average']): ?> <span class="badge bg-primary"><?php echo number_format($student['test_average'], 1); ?>%</span> <?php else: ?> - <?php endif; ?> </td> <td><span class="badge bg-info"><?php echo $student['makeup_count'] ?: 0; ?></span></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php endif; ?> <?php endif; ?> </div> </div> </div> <script> function toggleReportFields() { const reportType = document.getElementById('reportType').value; const studentField = document.getElementById('studentField'); const studentSelect = document.getElementById('studentSelect'); if (reportType === 'student') { studentField.style.display = 'block'; studentSelect.required = true; } else { studentField.style.display = 'none'; studentSelect.required = false; } } function loadStudents() { const groupId = document.getElementById('groupSelect').value; if (groupId) { // Reload page with selected group to get students const url = new URL(window.location); url.searchParams.set('group_id', groupId); url.searchParams.delete('report_type'); url.searchParams.delete('student_id'); window.location.href = url.toString(); } } // Initialize report fields document.addEventListener('DOMContentLoaded', function() { toggleReportFields(); // Set default date range to current month const dateFrom = document.getElementById('dateFrom'); const dateTo = document.getElementById('dateTo'); if (!dateFrom.value) { const now = new Date(); const firstDay = new Date(now.getFullYear(), now.getMonth(), 1); const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0); dateFrom.value = firstDay.toISOString().split('T')[0]; dateTo.value = lastDay.toISOString().split('T')[0]; } }); </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.86 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