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,18 @@
<?php
// cleanup_qrcodes.php
$temp_dir = '../temp_qrcodes/';
if (file_exists($temp_dir)) {
$files = glob($temp_dir . '*.png');
$now = time();
foreach ($files as $file) {
if (is_file($file)) {
// Delete files older than 1 hour
if ($now - filemtime($file) >= 3600) {
@unlink($file);
}
}
}
}
?>

593
src-backup/qr/generate.php Normal file
View File

@@ -0,0 +1,593 @@
<?php
// generate.php - Compact Version
require_once '../includes/config.php';
// Check if student ID is provided
if (!isset($_GET['id']) || empty($_GET['id'])) {
die('<div style="padding:15px;color:red;font-size:14px;">Error: Student ID required.</div>');
}
$student_id = intval($_GET['id']);
// Get student data
$sql = "SELECT s.*, c.code as course_code, c.name as course_name,
d.name as department_name, sc.name as school_name
FROM students s
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 s.id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 'i', $student_id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (!$result || mysqli_num_rows($result) == 0) {
die('<div style="padding:15px;color:red;font-size:14px;">Error: Student not found.</div>');
}
$student = mysqli_fetch_assoc($result);
mysqli_stmt_close($stmt);
// Check if download or print is requested
$download = isset($_GET['download']) && $_GET['download'] == '1';
$print = isset($_GET['print']) && $_GET['print'] == '1';
$auto_print = isset($_GET['autoPrint']) && $_GET['autoPrint'] == '1';
// QR code content
$qr_data = [
'ID' => $student['student_id'],
'Name' => $student['full_name'],
'Course' => $student['course_code'],
'Dept' => $student['department_name'],
'Year' => 'Year ' . $student['year_level'],
'Code' => $student['qr_code']
];
$qr_text = "";
foreach ($qr_data as $key => $value) {
$qr_text .= "$key: $value\n";
}
// Create temp directory
$temp_dir = '../temp_qrcodes/';
if (!file_exists($temp_dir)) {
mkdir($temp_dir, 0777, true);
}
// Generate QR code
$filename = 'qr_' . $student['student_id'] . '_' . time() . '.png';
$filepath = $temp_dir . $filename;
$qr_size = isset($_GET['size']) ? intval($_GET['size']) : 250;
// Generate QR code from Google Charts
$encoded_text = urlencode(trim($qr_text));
$qr_url = "https://chart.googleapis.com/chart?chs={$qr_size}x{$qr_size}&cht=qr&chl={$encoded_text}&choe=UTF-8";
$image_data = @file_get_contents($qr_url);
if ($image_data === false) {
// Fallback
$qr_url = "https://api.qrserver.com/v1/create-qr-code/?size={$qr_size}x{$qr_size}&data=" . urlencode($qr_text);
$image_data = @file_get_contents($qr_url);
}
if ($image_data !== false) {
file_put_contents($filepath, $image_data);
}
// If download requested
if ($download) {
if (file_exists($filepath)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="QR_' . $student['student_id'] . '.png"');
header('Content-Length: ' . filesize($filepath));
readfile($filepath);
cleanupOldQRCodes($temp_dir);
exit();
}
}
// If print requested
if ($print || $auto_print) {
?>
<!DOCTYPE html>
<html>
<head>
<title>QR - <?php echo $student['full_name']; ?></title>
<style>
@media print { body { margin: 10px; } }
body { font-family: Arial, sans-serif; font-size: 12px; }
.container { max-width: 400px; margin: 0 auto; }
.header { text-align: center; margin-bottom: 15px; }
.qr-img { width: 250px; height: 250px; margin: 0 auto; display: block; }
.info { margin: 15px 0; }
.footer { text-align: center; margin-top: 10px; font-size: 10px; color: #666; }
</style>
<script>window.onload = function() { window.print(); setTimeout(() => window.close(), 500); }</script>
</head>
<body>
<div class="container">
<div class="header">
<h3 style="margin:0;"><?php echo htmlspecialchars($student['full_name']); ?></h3>
<p style="margin:5px 0;"><?php echo htmlspecialchars($student['student_id']); ?></p>
</div>
<?php if (file_exists($filepath)): ?>
<img src="<?php echo $filepath; ?>" class="qr-img" alt="QR Code">
<?php else: ?>
<div style="border:1px solid #ccc; padding:15px;">
<pre><?php echo htmlspecialchars($qr_text); ?></pre>
</div>
<?php endif; ?>
<div class="info">
<p><strong><?php echo htmlspecialchars($student['course_code']); ?></strong></p>
<p>Year <?php echo $student['year_level']; ?> | <?php echo date('m/d/Y'); ?></p>
</div>
</div>
</body>
</html>
<?php
cleanupOldQRCodes($temp_dir);
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QR - <?php echo htmlspecialchars($student['full_name']); ?></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f8f9fa;
padding: 20px;
font-size: 14px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
border-radius: 10px;
box-shadow: 0 3px 15px rgba(0,0,0,0.08);
overflow: hidden;
}
.header {
background:#166b0e;
color: white;
padding: 15px 20px;
}
.header h1 {
font-size: 1.5rem;
margin: 0;
}
.content {
padding: 20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 768px) {
.content {
grid-template-columns: 1fr;
}
}
.qr-card {
text-align: center;
padding: 15px;
background: #f8f9fa;
border-radius: 8px;
}
.qr-img {
max-width: 250px;
width: 100%;
height: auto;
border-radius: 5px;
margin: 0 auto 15px;
}
.qr-code {
font-family: 'Courier New', monospace;
font-size: 12px;
background: white;
padding: 8px;
border-radius: 5px;
word-break: break-all;
margin: 10px 0;
}
.info-card {
padding: 15px;
}
.student-header {
display: flex;
align-items: center;
gap: 15px;
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid #dee2e6;
}
.avatar {
width: 60px;
height: 60px;
border-radius: 50%;
object-fit: cover;
border: 3px solid #4361ee;
}
.avatar-placeholder {
width: 60px;
height: 60px;
border-radius: 50%;
background: #166b0e;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid #cfee43;
}
.avatar-placeholder i {
color: white;
font-size: 24px;
}
.student-name {
font-weight: 600;
font-size: 1.1rem;
margin: 0;
}
.student-id {
color: #4361ee;
font-weight: 500;
margin: 0;
font-size: 0.9rem;
}
.info-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 10px;
}
.info-item {
padding: 8px;
background: #f8f9fa;
border-radius: 5px;
}
.info-label {
font-size: 11px;
color: #6c757d;
text-transform: uppercase;
font-weight: 600;
margin-bottom: 3px;
}
.info-value {
font-size: 13px;
font-weight: 500;
}
.status-badge {
display: inline-block;
padding: 3px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
}
.active { background: #d1fae5; color: #065f46; }
.inactive { background: #fee2e2; color: #991b1b; }
.actions {
padding: 15px 20px;
background: #f8f9fa;
border-top: 1px solid #dee2e6;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 8px 15px;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 500;
text-decoration: none;
}
.btn-primary { background: #4361ee; color: white; }
.btn-success { background: #10b981; color: white; }
.btn-secondary { background: #6c757d; color: white; }
.btn:hover {
opacity: 0.9;
text-decoration: none;
color: white;
}
.size-controls {
display: flex;
gap: 5px;
margin-top: 10px;
justify-content: center;
}
.size-btn {
padding: 4px 10px;
border: 1px solid #4361ee;
background: white;
color: #4361ee;
border-radius: 4px;
font-size: 11px;
cursor: pointer;
}
.size-btn.active {
background: #4361ee;
color: white;
}
.timestamp {
text-align: center;
color: #6c757d;
font-size: 12px;
margin-top: 15px;
padding-top: 10px;
border-top: 1px solid #dee2e6;
}
.print-only {
display: none;
}
@media print {
body {
background: white !important;
padding: 0 !important;
}
.container {
box-shadow: none !important;
border: 1px solid #ddd !important;
}
.actions, .size-controls {
display: none !important;
}
.print-only {
display: block;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1><i class="bi bi-qr-code-scan me-2"></i>Student QR Code</h1>
</div>
<div class="content">
<!-- QR Code Section -->
<div class="qr-card">
<?php if (file_exists($filepath)): ?>
<img src="<?php echo $filepath; ?>" class="qr-img" alt="QR Code" id="qrImage">
<?php else: ?>
<div style="padding:15px; background:#f8d7da; border-radius:5px; color:#721c24;">
<i class="bi bi-exclamation-triangle me-2"></i>
QR code generation failed
<div style="margin-top:10px; font-size:12px;">
<pre><?php echo htmlspecialchars($qr_text); ?></pre>
</div>
</div>
<?php endif; ?>
<div class="qr-code">
<?php echo htmlspecialchars($student['qr_code']); ?>
</div>
<div class="size-controls">
<button class="size-btn <?php echo $qr_size == 200 ? 'active' : ''; ?>"
onclick="changeSize(200)">200px</button>
<button class="size-btn <?php echo $qr_size == 250 ? 'active' : ''; ?>"
onclick="changeSize(250)">250px</button>
<button class="size-btn <?php echo $qr_size == 300 ? 'active' : ''; ?>"
onclick="changeSize(300)">300px</button>
</div>
</div>
<!-- Student Info Section -->
<div class="info-card">
<div class="student-header">
<?php if (!empty($student['picture_path'])): ?>
<img src="../<?php echo htmlspecialchars($student['picture_path']); ?>"
alt="Photo" class="avatar">
<?php else: ?>
<div class="avatar-placeholder">
<i class="bi bi-person"></i>
</div>
<?php endif; ?>
<div>
<div class="student-name"><?php echo htmlspecialchars($student['full_name']); ?></div>
<div class="student-id"><?php echo htmlspecialchars($student['student_id']); ?></div>
</div>
</div>
<div class="info-grid">
<div class="info-item">
<div class="info-label">Course</div>
<div class="info-value"><?php echo htmlspecialchars($student['course_code']); ?></div>
</div>
<div class="info-item">
<div class="info-label">Department</div>
<div class="info-value"><?php echo htmlspecialchars($student['department_name']); ?></div>
</div>
<div class="info-item">
<div class="info-label">Year</div>
<div class="info-value">Year <?php echo $student['year_level']; ?></div>
</div>
<div class="info-item">
<div class="info-label">School</div>
<div class="info-value"><?php echo htmlspecialchars($student['school_name']); ?></div>
</div>
<div class="info-item">
<div class="info-label">Email</div>
<div class="info-value">
<?php echo htmlspecialchars($student['email'] ?: '-'); ?>
</div>
</div>
<div class="info-item">
<div class="info-label">Contact</div>
<div class="info-value">
<?php echo htmlspecialchars($student['contact_number'] ?: '-'); ?>
</div>
</div>
<div class="info-item">
<div class="info-label">Status</div>
<div class="info-value">
<?php if ($student['status'] == 1): ?>
<span class="status-badge active">
<i class="bi bi-check-circle me-1"></i>Active
</span>
<?php else: ?>
<span class="status-badge inactive">
<i class="bi bi-x-circle me-1"></i>Inactive
</span>
<?php endif; ?>
</div>
</div>
<div class="info-item">
<div class="info-label">Generated</div>
<div class="info-value"><?php echo date('m/d/Y h:i A'); ?></div>
</div>
</div>
<div class="timestamp">
<i class="bi bi-clock me-1"></i>
Last updated: <?php echo date('m/d/Y', strtotime($student['updated_at'])); ?>
</div>
</div>
</div>
<div class="actions">
<button class="btn btn-primary" onclick="window.print()">
<i class="bi bi-printer me-1"></i>Print
</button>
<button class="btn btn-success" onclick="downloadQR()">
<i class="bi bi-download me-1"></i>Download
</button>
<a href="?id=<?php echo $student_id; ?>&print=1" target="_blank" class="btn btn-primary">
<i class="bi bi-printer-fill me-1"></i>Quick Print
</a>
<a href="?id=<?php echo $student_id; ?>&download=1" class="btn btn-success">
<i class="bi bi-file-arrow-down me-1"></i>Direct Download
</a>
<button class="btn btn-secondary" onclick="window.close()">
<i class="bi bi-x-circle me-1"></i>Close
</button>
</div>
</div>
<script>
// Change QR size
function changeSize(size) {
const url = new URL(window.location.href);
url.searchParams.set('size', size);
window.location.href = url.toString();
}
// Download QR code
function downloadQR() {
<?php if (file_exists($filepath)): ?>
const link = document.createElement('a');
link.href = '<?php echo $filepath; ?>';
link.download = 'QR_<?php echo $student['student_id']; ?>.png';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Show notification
const notification = document.createElement('div');
notification.style.cssText = 'position:fixed; top:20px; right:20px; background:#10b981; color:white; padding:10px 15px; border-radius:5px; z-index:9999;';
notification.innerHTML = '<i class="bi bi-check-circle me-2"></i>Download started';
document.body.appendChild(notification);
setTimeout(() => notification.remove(), 2000);
<?php endif; ?>
}
// Keyboard shortcuts
document.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
e.preventDefault();
window.print();
}
if ((e.ctrlKey || e.metaKey) && e.key === 'd') {
e.preventDefault();
downloadQR();
}
if (e.key === 'Escape') {
window.close();
}
});
// Auto-print if requested
<?php if ($auto_print): ?>
window.onload = function() {
setTimeout(() => window.print(), 500);
};
<?php endif; ?>
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php
// Cleanup function
function cleanupOldQRCodes($dir) {
if (file_exists($dir)) {
$files = glob($dir . '*.png');
$now = time();
foreach ($files as $file) {
if (is_file($file) && ($now - filemtime($file) >= 3600)) {
@unlink($file);
}
}
}
}
// Run cleanup
cleanupOldQRCodes($temp_dir);
?>

194
src-backup/qr/print.php Normal file
View File

@@ -0,0 +1,194 @@
<?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();
}
// Get student ID from URL
$student_id = $_GET['id'] ?? 0;
if (!$student_id) {
die('Student ID is required');
}
// Get student information
$sql = "SELECT s.*, c.code as course_code, d.name as department_name
FROM students s
LEFT JOIN courses c ON s.course_id = c.id
LEFT JOIN departments d ON s.department_id = d.id
WHERE s.id = $student_id AND s.status = 1";
$result = query($conn, $sql);
if (!$result || mysqli_num_rows($result) === 0) {
die('Student not found');
}
$student = mysqli_fetch_assoc($result);
// Get the latest QR code file
$qr_files = glob('generated/student_' . $student['student_id'] . '_*.png');
$qr_filepath = !empty($qr_files) ? end($qr_files) : '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Print QR Code - <?php echo $student['full_name']; ?></title>
<style>
@media print {
@page {
margin: 0.5in;
size: letter portrait;
}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
}
.print-container {
text-align: center;
padding: 20px;
}
.school-header {
margin-bottom: 20px;
}
.school-header h2 {
color: #3498db;
margin-bottom: 5px;
}
.school-header h3 {
color: #666;
margin-top: 0;
}
.qr-code-container {
margin: 30px 0;
padding: 20px;
border: 1px solid #ddd;
display: inline-block;
background: white;
}
.qr-code-image {
width: 300px;
height: 300px;
}
.student-info {
margin: 20px 0;
padding: 15px;
border: 1px solid #eee;
display: inline-block;
text-align: left;
}
.student-info h4 {
margin-top: 0;
color: #333;
}
.footer {
margin-top: 40px;
font-size: 12px;
color: #666;
border-top: 1px solid #ddd;
padding-top: 10px;
}
}
@media screen {
body {
background: #f8f9fa;
padding: 20px;
}
.print-container {
max-width: 800px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.print-actions {
text-align: center;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #dee2e6;
}
}
</style>
</head>
<body>
<?php if (!isset($_GET['auto'])): ?>
<div class="print-actions">
<button onclick="window.print()" class="btn btn-primary" style="padding: 10px 20px; font-size: 16px;">
<i class="bi bi-printer"></i> Print Now
</button>
<button onclick="window.close()" class="btn btn-secondary" style="padding: 10px 20px; font-size: 16px;">
<i class="bi bi-x-circle"></i> Close
</button>
</div>
<?php endif; ?>
<div class="print-container">
<!-- School Header -->
<div class="school-header">
<h2><?php echo SITE_NAME; ?></h2>
<h3>Student QR Code</h3>
</div>
<!-- QR Code -->
<div class="qr-code-container">
<?php if ($qr_filepath && file_exists($qr_filepath)): ?>
<img src="<?php echo $qr_filepath; ?>" alt="QR Code" class="qr-code-image">
<?php else: ?>
<div style="width: 300px; height: 300px; background: #f0f0f0; display: flex; align-items: center; justify-content: center;">
<p>QR Code not generated</p>
</div>
<?php endif; ?>
</div>
<!-- Student Information -->
<div class="student-info">
<h4><?php echo $student['full_name']; ?></h4>
<table style="border-collapse: collapse;">
<tr>
<td style="padding: 5px 10px 5px 0;"><strong>Student ID:</strong></td>
<td style="padding: 5px 0;"><?php echo $student['student_id']; ?></td>
</tr>
<tr>
<td style="padding: 5px 10px 5px 0;"><strong>Year Level:</strong></td>
<td style="padding: 5px 0;">Year <?php echo $student['year_level']; ?></td>
</tr>
<tr>
<td style="padding: 5px 10px 5px 0;"><strong>Course:</strong></td>
<td style="padding: 5px 0;"><?php echo $student['course_code']; ?></td>
</tr>
<tr>
<td style="padding: 5px 10px 5px 0;"><strong>Department:</strong></td>
<td style="padding: 5px 0;"><?php echo $student['department_name']; ?></td>
</tr>
</table>
</div>
<!-- Footer -->
<div class="footer">
<p>Generated on: <?php echo date('F j, Y'); ?></p>
<p>© <?php echo date('Y'); ?> <?php echo SITE_NAME; ?> - QR Attendance System</p>
<p><small>Present this QR code at attendance stations for scanning</small></p>
</div>
</div>
<?php if (isset($_GET['auto'])): ?>
<script>
window.onload = function() {
window.print();
setTimeout(function() {
window.close();
}, 1000);
}
</script>
<?php endif; ?>
</body>
</html>

View File

@@ -0,0 +1,22 @@
<?php
// simple_cleanup.php
$temp_dir = '../temp_qrcodes/';
if (file_exists($temp_dir)) {
$files = glob($temp_dir . '*.png');
$deleted = 0;
foreach ($files as $file) {
// Delete files older than 1 hour
if (time() - filemtime($file) > 3600) {
if (unlink($file)) {
$deleted++;
}
}
}
echo "Deleted $deleted old QR code files.";
} else {
echo "QR directory not found.";
}
?>

View File

@@ -0,0 +1,3 @@
<?php
phpinfo();
?>