Error: Student ID required.'); } $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('
Error: Student not found.
'); } $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) { ?> QR - <?php echo $student['full_name']; ?>

QR Code

Year |

QR - <?php echo htmlspecialchars($student['full_name']); ?>

Student QR Code

QR Code
QR code generation failed
Photo
Course
Department
Year
Year
School
Email
Contact
Status
Active Inactive
Generated
Last updated:
Quick Print Direct Download
= 3600)) { @unlink($file); } } } } // Run cleanup cleanupOldQRCodes($temp_dir); ?>