Initial commit

This commit is contained in:
2026-01-07 14:09:59 +08:00
commit 8a00aa71d5
939 changed files with 40616 additions and 0 deletions

View File

@@ -0,0 +1,356 @@
<?php
require_once '../includes/config.php';
// Check if user is logged in
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
header('Location: ../auth/login.php');
exit();
}
// Check if report data exists
if (!isset($_SESSION['report_data'])) {
header('Location: students_report.php');
exit();
}
$report_data = $_SESSION['report_data'];
$students = $report_data['students'] ?? [];
$filters = $report_data['filters'] ?? [];
unset($_SESSION['report_data']);
// Get report type
$type = $_GET['type'] ?? 'print';
// For PDF generation, you would use a library like TCPDF
if ($type === 'pdf') {
require_once '../vendor/autoload.php';
// TCPDF implementation would go here
// For now, we'll output HTML that can be printed as PDF
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="students_report_' . date('Y-m-d') . '.pdf"');
// In production, generate actual PDF
// $pdf = new TCPDF();
// $pdf->AddPage();
// $pdf->writeHTML($html);
// $pdf->Output();
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Report</title>
<style>
@media print {
.no-print { display: none !important; }
body { font-size: 12pt; }
.container { width: 100% !important; max-width: none !important; }
table { page-break-inside: auto; }
tr { page-break-inside: avoid; page-break-after: auto; }
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
}
.report-header {
text-align: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 2px solid #333;
}
.report-title {
font-size: 24px;
font-weight: bold;
margin-bottom: 5px;
}
.report-subtitle {
font-size: 16px;
color: #666;
}
.report-info {
margin-bottom: 20px;
padding: 15px;
background-color: #f8f9fa;
border-radius: 5px;
}
.info-row {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
.status-active {
color: green;
font-weight: bold;
}
.status-inactive {
color: red;
font-weight: bold;
}
.print-options {
margin-bottom: 20px;
padding: 15px;
background-color: #e9ecef;
border-radius: 5px;
}
.summary-box {
margin-top: 30px;
padding: 15px;
background-color: #f8f9fa;
border-left: 4px solid #007bff;
}
.footer {
margin-top: 50px;
padding-top: 20px;
border-top: 1px solid #ddd;
text-align: center;
font-size: 12px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<!-- Print Options -->
<div class="print-options no-print">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<button onclick="window.print()" class="btn" style="background-color: #007bff; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer;">
<i class="bi bi-printer"></i> Print Report
</button>
<button onclick="window.close()" class="btn" style="background-color: #6c757d; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; margin-left: 10px;">
Close
</button>
</div>
<div>
<button onclick="saveAsPDF()" class="btn" style="background-color: #dc3545; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer;">
<i class="bi bi-file-pdf"></i> Save as PDF
</button>
</div>
</div>
</div>
<!-- Report Header -->
<div class="report-header">
<div class="report-title">Student Report</div>
<div class="report-subtitle">Generated on <?php echo date('F j, Y, h:i A'); ?></div>
</div>
<!-- Report Info -->
<div class="report-info">
<div class="info-row">
<div><strong>Total Students:</strong> <?php echo count($students); ?></div>
<div><strong>Page:</strong> 1 of 1</div>
</div>
<div class="info-row">
<div>
<strong>Filters Applied:</strong>
<?php
$filter_text = [];
if ($filters['status'] !== 'all') {
$filter_text[] = 'Status: ' . ($filters['status'] == 1 ? 'Active' : 'Inactive');
}
if ($filters['year_level'] !== 'all') {
$filter_text[] = 'Year Level: ' . $filters['year_level'];
}
if ($filters['course'] !== 'all') {
$filter_text[] = 'Course Filtered';
}
if ($filters['date_from']) {
$filter_text[] = 'From: ' . date('M j, Y', strtotime($filters['date_from']));
}
if ($filters['date_to']) {
$filter_text[] = 'To: ' . date('M j, Y', strtotime($filters['date_to']));
}
echo empty($filter_text) ? 'No filters applied' : implode(', ', $filter_text);
?>
</div>
<div><strong>Generated By:</strong> <?php echo $_SESSION['full_name'] ?? 'Admin'; ?></div>
</div>
</div>
<!-- Students Table -->
<?php if (!empty($students)): ?>
<table>
<thead>
<tr>
<th>#</th>
<th>Student ID</th>
<th>Full Name</th>
<th>Gender</th>
<th>Year Level</th>
<th>Course</th>
<th>Email</th>
<th>Contact</th>
<th>Status</th>
<th>Date Registered</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
$active_count = 0;
$inactive_count = 0;
$year_counts = [1 => 0, 2 => 0, 3 => 0, 4 => 0];
foreach ($students as $student):
if ($student['status'] == 1) $active_count++;
else $inactive_count++;
$year_counts[$student['year_level']]++;
?>
<tr>
<td><?php echo $counter++; ?></td>
<td><?php echo $student['student_id']; ?></td>
<td><?php echo $student['full_name']; ?></td>
<td><?php echo $student['gender']; ?></td>
<td>Year <?php echo $student['year_level']; ?></td>
<td><?php echo $student['course_code'] ?? ''; ?></td>
<td><?php echo $student['email']; ?></td>
<td><?php echo $student['contact_number']; ?></td>
<td>
<?php if ($student['status'] == 1): ?>
<span class="status-active">Active</span>
<?php else: ?>
<span class="status-inactive">Inactive</span>
<?php endif; ?>
</td>
<td><?php echo date('M j, Y', strtotime($student['created_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Summary -->
<div class="summary-box">
<h4>Summary</h4>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px;">
<div>
<strong>Total Students:</strong> <?php echo count($students); ?>
</div>
<div>
<strong>Active:</strong> <?php echo $active_count; ?>
</div>
<div>
<strong>Inactive:</strong> <?php echo $inactive_count; ?>
</div>
<?php foreach ($year_counts as $year => $count): ?>
<div>
<strong>Year <?php echo $year; ?>:</strong> <?php echo $count; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php else: ?>
<div style="text-align: center; padding: 40px;">
<h4>No students found matching the selected criteria</h4>
<p>Try adjusting your filters.</p>
</div>
<?php endif; ?>
<!-- Footer -->
<div class="footer">
<div>Student Management System</div>
<div>Report generated electronically - <?php echo date('F j, Y, h:i:s A'); ?></div>
<div>Page 1 of 1</div>
</div>
</div>
<script>
function saveAsPDF() {
// In production, use a proper PDF generation library
// For now, we'll use browser's print to PDF
const originalTitle = document.title;
document.title = 'Student Report - <?php echo date('Y-m-d'); ?>';
window.print();
document.title = originalTitle;
}
function downloadCSV() {
// Create CSV content
let csvContent = "data:text/csv;charset=utf-8,";
// Headers
csvContent += "Student ID,Full Name,Gender,Year Level,Course,Email,Contact,Status,Date Registered\n";
// Data
<?php foreach ($students as $student): ?>
csvContent += "<?php
echo addslashes($student['student_id']) . ',' .
addslashes($student['full_name']) . ',' .
addslashes($student['gender']) . ',' .
'Year ' . $student['year_level'] . ',' .
addslashes(($student['course_code'] ?? '') . ' - ' . ($student['course_name'] ?? '')) . ',' .
addslashes($student['email']) . ',' .
addslashes($student['contact_number']) . ',' .
($student['status'] == 1 ? 'Active' : 'Inactive') . ',' .
date('Y-m-d', strtotime($student['created_at']));
?>\n";
<?php endforeach; ?>
// Create download link
const encodedUri = encodeURI(csvContent);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "students_<?php echo date('Y-m-d'); ?>.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// Auto-print if specified
<?php if ($type === 'print'): ?>
window.onload = function() {
setTimeout(function() {
window.print();
}, 500);
};
<?php endif; ?>
</script>
</body>
</html>

View File

@@ -0,0 +1,375 @@
<?php
require_once '../includes/config.php';
// Check if user is logged in and is admin
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true || $_SESSION['role'] !== 'admin') {
header('Location: ../auth/login.php');
exit();
}
$title = "Student Reports";
// Initialize variables
$message = '';
$message_type = '';
// Handle report generation
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['generate_report'])) {
$report_type = $_POST['report_type'] ?? 'all';
$status_filter = $_POST['status_filter'] ?? 'all';
$year_level_filter = $_POST['year_level_filter'] ?? 'all';
$course_filter = $_POST['course_filter'] ?? 'all';
$date_from = $_POST['date_from'] ?? '';
$date_to = $_POST['date_to'] ?? '';
// Build query based on filters
$sql = "SELECT s.*, g.name as gender, c.code as course_code, c.name as course_name,
d.code as department_code, d.name as department_name,
sc.code as school_code, sc.name as school_name
FROM students s
LEFT JOIN genders g ON s.gender_id = g.id
LEFT JOIN courses c ON s.course_id = c.id
LEFT JOIN departments d ON s.department_id = d.id
LEFT JOIN schools sc ON s.school_id = sc.id
WHERE 1=1";
if ($status_filter !== 'all') {
$sql .= " AND s.status = " . intval($status_filter);
}
if ($year_level_filter !== 'all') {
$sql .= " AND s.year_level = " . intval($year_level_filter);
}
if ($course_filter !== 'all') {
$sql .= " AND s.course_id = " . intval($course_filter);
}
if (!empty($date_from)) {
$sql .= " AND DATE(s.created_at) >= '" . escape($conn, $date_from) . "'";
}
if (!empty($date_to)) {
$sql .= " AND DATE(s.created_at) <= '" . escape($conn, $date_to) . "'";
}
$sql .= " ORDER BY s.created_at DESC";
$result = query($conn, $sql);
$students = [];
while ($row = mysqli_fetch_assoc($result)) {
$students[] = $row;
}
// Generate PDF
if ($report_type === 'pdf') {
require_once '../vendor/autoload.php'; // If using TCPDF or Dompdf
// For now, we'll create a simple HTML report that can be printed
// In production, you'd use a PDF library like TCPDF or Dompdf
$_SESSION['report_data'] = [
'students' => $students,
'filters' => [
'status' => $status_filter,
'year_level' => $year_level_filter,
'course' => $course_filter,
'date_from' => $date_from,
'date_to' => $date_to
]
];
header('Location: print_report.php?type=pdf');
exit();
}
// Generate Excel
elseif ($report_type === 'excel') {
require_once '../includes/PHPExcel.php'; // Or use PhpSpreadsheet
// Create Excel file
$filename = "students_report_" . date('Y-m-d_H-i-s') . ".xlsx";
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $filename . '"');
// For now, create CSV as fallback
outputCSV($students);
exit();
}
// Print view
elseif ($report_type === 'print') {
$_SESSION['report_data'] = [
'students' => $students,
'filters' => [
'status' => $status_filter,
'year_level' => $year_level_filter,
'course' => $course_filter,
'date_from' => $date_from,
'date_to' => $date_to
]
];
header('Location: print_report.php');
exit();
}
}
// Get courses for filter dropdown
$courses = [];
$result = query($conn, "SELECT id, code, name FROM courses WHERE status = 1 ORDER BY code");
while ($row = mysqli_fetch_assoc($result)) {
$courses[] = $row;
}
// Get departments
$departments = [];
$result = query($conn, "SELECT id, code, name FROM departments WHERE status = 1 ORDER BY code");
while ($row = mysqli_fetch_assoc($result)) {
$departments[] = $row;
}
function outputCSV($data) {
$output = fopen('php://output', 'w');
// Header row
fputcsv($output, [
'Student ID', 'Full Name', 'Gender', 'Year Level', 'Course',
'Department', 'Email', 'Contact Number', 'Status', 'Date Created'
]);
// Data rows
foreach ($data as $student) {
fputcsv($output, [
$student['student_id'],
$student['full_name'],
$student['gender'],
'Year ' . $student['year_level'],
$student['course_code'] . ' - ' . $student['course_name'],
$student['department_name'],
$student['email'],
$student['contact_number'],
$student['status'] == 1 ? 'Active' : 'Inactive',
date('Y-m-d', strtotime($student['created_at']))
]);
}
fclose($output);
}
include '../includes/header.php';
?>
<!-- Page Header -->
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1 class="h3 mb-2">Student Reports</h1>
<p class="text-muted">Generate and export student reports in various formats.</p>
</div>
<div>
<a href="manage_students.php" class="btn btn-outline-secondary">
<i class="bi bi-arrow-left me-2"></i> Back to Students
</a>
</div>
</div>
<!-- Message Alert -->
<?php if ($message): ?>
<div class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show">
<?php echo $message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<!-- Report Filters Card -->
<div class="card shadow mb-4">
<div class="card-header">
<h6 class="m-0 font-weight-bold">
<i class="bi bi-filter me-2"></i> Report Filters
</h6>
</div>
<div class="card-body">
<form method="POST" action="">
<div class="row">
<div class="col-md-3 mb-3">
<label class="form-label">Report Type</label>
<select class="form-select" name="report_type" required>
<option value="print">Print Preview</option>
<option value="pdf">PDF Document</option>
<option value="excel">Excel Spreadsheet</option>
</select>
</div>
<div class="col-md-3 mb-3">
<label class="form-label">Status</label>
<select class="form-select" name="status_filter">
<option value="all">All Status</option>
<option value="1">Active Only</option>
<option value="0">Inactive Only</option>
</select>
</div>
<div class="col-md-3 mb-3">
<label class="form-label">Year Level</label>
<select class="form-select" name="year_level_filter">
<option value="all">All Year Levels</option>
<?php for ($i = 1; $i <= 4; $i++): ?>
<option value="<?php echo $i; ?>">Year <?php echo $i; ?></option>
<?php endfor; ?>
</select>
</div>
<div class="col-md-3 mb-3">
<label class="form-label">Course</label>
<select class="form-select" name="course_filter">
<option value="all">All Courses</option>
<?php foreach ($courses as $course): ?>
<option value="<?php echo $course['id']; ?>">
<?php echo $course['code']; ?> - <?php echo $course['name']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Date From</label>
<input type="date" class="form-control" name="date_from">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Date To</label>
<input type="date" class="form-control" name="date_to">
</div>
<div class="col-12">
<div class="d-flex justify-content-end gap-2">
<button type="reset" class="btn btn-secondary">
<i class="bi bi-arrow-clockwise me-1"></i> Reset Filters
</button>
<button type="submit" name="generate_report" class="btn btn-primary">
<i class="bi bi-file-earmark-text me-1"></i> Generate Report
</button>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- Quick Export Options -->
<div class="row mb-4">
<div class="col-md-4">
<div class="card h-100">
<div class="card-body text-center">
<i class="bi bi-printer text-primary mb-3" style="font-size: 3rem;"></i>
<h5>Quick Print</h5>
<p class="text-muted">Generate a printable student list</p>
<form method="POST" action="">
<input type="hidden" name="report_type" value="print">
<input type="hidden" name="status_filter" value="all">
<button type="submit" name="generate_report" class="btn btn-outline-primary">
<i class="bi bi-printer me-1"></i> Print All Students
</button>
</form>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card h-100">
<div class="card-body text-center">
<i class="bi bi-file-excel text-success mb-3" style="font-size: 3rem;"></i>
<h5>Export Excel</h5>
<p class="text-muted">Download as Excel spreadsheet</p>
<form method="POST" action="">
<input type="hidden" name="report_type" value="excel">
<input type="hidden" name="status_filter" value="all">
<button type="submit" name="generate_report" class="btn btn-outline-success">
<i class="bi bi-download me-1"></i> Export to Excel
</button>
</form>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card h-100">
<div class="card-body text-center">
<i class="bi bi-file-pdf text-danger mb-3" style="font-size: 3rem;"></i>
<h5>PDF Report</h5>
<p class="text-muted">Generate detailed PDF report</p>
<form method="POST" action="">
<input type="hidden" name="report_type" value="pdf">
<input type="hidden" name="status_filter" value="all">
<button type="submit" name="generate_report" class="btn btn-outline-danger">
<i class="bi bi-file-earmark-pdf me-1"></i> Generate PDF
</button>
</form>
</div>
</div>
</div>
</div>
<?php
$page_scripts = '
<script>
$(document).ready(function() {
// Set today as default date for "Date To"
const today = new Date().toISOString().split("T")[0];
$("input[name=\'date_to\']").val(today);
// Set 30 days ago as default for "Date From"
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
$("input[name=\'date_from\']").val(thirtyDaysAgo.toISOString().split("T")[0]);
// Form validation
$("form").submit(function() {
const dateFrom = $("input[name=\'date_from\']").val();
const dateTo = $("input[name=\'date_to\']").val();
if (dateFrom && dateTo && new Date(dateFrom) > new Date(dateTo)) {
showNotification("Date From cannot be after Date To", "danger");
return false;
}
showLoader("Generating report...");
return true;
});
});
// Quick export functions
function exportActiveStudents() {
showConfirm("Export all active students to Excel?", function(confirmed) {
if (confirmed) {
const form = document.createElement("form");
form.method = "POST";
form.action = "";
const typeInput = document.createElement("input");
typeInput.type = "hidden";
typeInput.name = "report_type";
typeInput.value = "excel";
form.appendChild(typeInput);
const statusInput = document.createElement("input");
statusInput.type = "hidden";
statusInput.name = "status_filter";
statusInput.value = "1";
form.appendChild(statusInput);
document.body.appendChild(form);
form.submit();
}
});
}
function printStudentCards() {
showConfirm("Generate printable student ID cards?", function(confirmed) {
if (confirmed) {
window.open("student_cards.php", "_blank");
}
});
}
</script>
';
include '../includes/footer.php';
?>