V1rus Private
User / IP
:
216.73.217.108
Host / Server
:
190.92.174.125 / aerosofthealthcare.com
System
:
Linux s3739.bom1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64
Cmd
|
Upload
|
Mass Deface
|
Create
|
Sym
:
/
home
/
aerosoft
/
www
/
exam
/
Viewing: generate_certificate - Copy.php
<?php session_start(); include 'config.php'; // Check authentication if (!isset($_SESSION['student_id']) && !isset($_SESSION['admin_id'])) { header("Location: login.php"); exit(); } $exam_id = $_GET['exam_id'] ?? null; if (!$exam_id) { // Show detailed error message echo '<div class="container mt-5"> <div class="alert alert-danger"> <h4>No Exam ID Provided</h4> <p>The certificate generation requires a valid exam ID. This could be because:</p> <ul> <li>The link was clicked incorrectly</li> <li>The exam doesn\'t exist</li> <li>You don\'t have permission to access this certificate</li> </ul> <p><strong>Exam ID received:</strong> ' . (isset($_GET['exam_id']) ? htmlspecialchars($_GET['exam_id']) : 'None') . '</p> <a href="student_dashboard.php" class="btn btn-primary">Return to Dashboard</a> </div> </div>'; exit(); } // Validate exam_id is numeric if (!is_numeric($exam_id)) { die("Invalid exam ID format. Exam ID must be a number."); } try { // Determine user type and build query accordingly if (isset($_SESSION['admin_id'])) { // Admin can view any certificate $stmt = $pdo->prepare("SELECT e.*, c.name as category_name, s.name as student_name, s.email, cert.certificate_code, cert.issued_date, cert.expiry_date FROM exams e JOIN categories c ON e.category_id = c.id JOIN students s ON e.student_id = s.id LEFT JOIN certificates cert ON cert.exam_id = e.id WHERE e.id = ?"); $stmt->execute([$exam_id]); } else { // Students can only view their own certificates $student_id = $_SESSION['student_id']; $stmt = $pdo->prepare("SELECT e.*, c.name as category_name, s.name as student_name, s.email, cert.certificate_code, cert.issued_date, cert.expiry_date FROM exams e JOIN categories c ON e.category_id = c.id JOIN students s ON e.student_id = s.id LEFT JOIN certificates cert ON cert.exam_id = e.id WHERE e.id = ? AND e.student_id = ?"); $stmt->execute([$exam_id, $student_id]); } $data = $stmt->fetch(); if (!$data) { echo '<div class="container mt-5"> <div class="alert alert-warning"> <h4>Exam Not Found</h4> <p>The requested exam could not be found or you don\'t have permission to access it.</p> <p><strong>Exam ID:</strong> ' . htmlspecialchars($exam_id) . '</p> <a href="student_dashboard.php" class="btn btn-primary">Return to Dashboard</a> </div> </div>'; exit(); } // Check if exam is passed if ($data['status'] !== 'passed') { echo '<div class="container mt-5"> <div class="alert alert-info"> <h4>Certificate Not Available</h4> <p>Certificates are only available for passed exams. Your exam status: <strong>' . htmlspecialchars($data['status']) . '</strong></p> <p>Score: ' . $data['percentage'] . '% (Required: ' . $data['passing_marks'] . '%)</p> <a href="exam_landing.php?category_id=' . $data['category_id'] . '" class="btn btn-warning">Retake Exam</a> <a href="student_dashboard.php" class="btn btn-primary">Return to Dashboard</a> </div> </div>'; exit(); } // Create certificate if it doesn't exist if (empty($data['certificate_code'])) { $certificate_code = 'CERT-' . strtoupper(uniqid()); $expiry_date = date('Y-m-d', strtotime('+1 year')); $issued_date = date('Y-m-d H:i:s'); $stmt = $pdo->prepare("INSERT INTO certificates (student_id, exam_id, certificate_code, issued_date, expiry_date) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$data['student_id'], $exam_id, $certificate_code, $issued_date, $expiry_date]); // Refresh data if (isset($_SESSION['admin_id'])) { $stmt = $pdo->prepare("SELECT e.*, c.name as category_name, s.name as student_name, cert.certificate_code, cert.issued_date, cert.expiry_date FROM exams e JOIN categories c ON e.category_id = c.id JOIN students s ON e.student_id = s.id JOIN certificates cert ON cert.exam_id = e.id WHERE e.id = ?"); $stmt->execute([$exam_id]); } else { $student_id = $_SESSION['student_id']; $stmt = $pdo->prepare("SELECT e.*, c.name as category_name, s.name as student_name, cert.certificate_code, cert.issued_date, cert.expiry_date FROM exams e JOIN categories c ON e.category_id = c.id JOIN students s ON e.student_id = s.id JOIN certificates cert ON cert.exam_id = e.id WHERE e.id = ? AND e.student_id = ?"); $stmt->execute([$exam_id, $student_id]); } $data = $stmt->fetch(); } // Check if TCPDF is available if (!file_exists('tcpdf/tcpdf.php')) { // Fallback: Show HTML certificate showHtmlCertificate($data); exit(); } // Generate PDF certificate require_once('tcpdf/tcpdf.php'); generatePdfCertificate($data); } catch (Exception $e) { echo '<div class="container mt-5"> <div class="alert alert-danger"> <h4>Error Generating Certificate</h4> <p><strong>Error:</strong> ' . htmlspecialchars($e->getMessage()) . '</p> <p>Please contact administrator if this problem persists.</p> <a href="student_dashboard.php" class="btn btn-primary">Return to Dashboard</a> </div> </div>'; } function generatePdfCertificate($data) { // Create PDF $pdf = new TCPDF('L', 'mm', 'A4', true, 'UTF-8', false); // Set document information $pdf->SetCreator('CertiPro System'); $pdf->SetAuthor('CertiPro'); $pdf->SetTitle('Certificate - ' . $data['category_name']); $pdf->SetSubject('Professional Certification'); // Remove header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // Set margins $pdf->SetMargins(15, 15, 15); $pdf->AddPage(); // Add content $html = ' <style> .certificate { text-align: center; color: #333; font-family: helvetica; } .title { font-size: 28px; font-weight: bold; color: #2c3e50; margin-bottom: 30px; text-decoration: underline; } .subtitle { font-size: 18px; color: #7f8c8d; margin-bottom: 40px; } .student-name { font-size: 32px; font-weight: bold; color: #e74c3c; margin: 30px 0; padding: 10px; border: 2px solid #3498db; border-radius: 10px; background: #f8f9fa; } .course-name { font-size: 24px; color: #3498db; margin: 20px 0; font-weight: bold; } .details { font-size: 16px; color: #555; margin: 20px 0; line-height: 1.6; } .signature { margin-top: 60px; } .signature-table { width: 100%; margin-top: 40px; } .footer { margin-top: 40px; font-size: 12px; color: #95a5a6; } </style> <div class="certificate"> <div class="title">CERTIFICATE OF COMPLETION</div> <div class="subtitle">This is to certify that</div> <div class="student-name">' . htmlspecialchars($data['student_name']) . '</div> <div class="details"> has successfully completed the <strong class="course-name">' . htmlspecialchars($data['category_name']) . '</strong> course<br> with a final score of <strong>' . $data['percentage'] . '%</strong><br> on ' . date('F j, Y', strtotime($data['issued_date'])) . ' </div> <table class="signature-table"> <tr> <td style="width: 50%; text-align: center;"> <div style="border-top: 2px solid #333; width: 200px; margin: 0 auto; padding-top: 10px;"> <strong>Arjun Singh</strong><br> Senior Instructor </div> </td> <td style="width: 50%; text-align: center;"> <div style="border-top: 2px solid #333; width: 200px; margin: 0 auto; padding-top: 10px;"> <strong>Sunil Kumar</strong><br> Program Director </div> </td> </tr> </table> <div class="footer"> Certificate ID: ' . $data['certificate_code'] . ' | Issued: ' . date('M j, Y', strtotime($data['issued_date'])) . ' | Valid Until: ' . date('M j, Y', strtotime($data['expiry_date'])) . ' </div> </div>'; $pdf->writeHTML($html, true, false, true, false, ''); $pdf->Output('certificate_' . $data['certificate_code'] . '.pdf', 'D'); } function showHtmlCertificate($data) { ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Certificate - <?php echo htmlspecialchars($data['category_name']); ?></title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; } .certificate-container { background: white; border: 10px solid #2c3e50; border-radius: 15px; padding: 40px; max-width: 800px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); position: relative; } .certificate-container::before { content: ''; position: absolute; top: 20px; left: 20px; right: 20px; bottom: 20px; border: 2px solid #3498db; border-radius: 10px; pointer-events: none; } .certificate-title { font-size: 2.5rem; font-weight: bold; color: #2c3e50; text-align: center; margin-bottom: 30px; text-decoration: underline; } .certificate-subtitle { font-size: 1.2rem; color: #7f8c8d; text-align: center; margin-bottom: 40px; } .student-name { font-size: 2.2rem; font-weight: bold; color: #e74c3c; text-align: center; margin: 30px 0; padding: 20px; border: 3px solid #3498db; border-radius: 10px; background: #f8f9fa; } .course-name { font-size: 1.8rem; color: #3498db; text-align: center; margin: 20px 0; font-weight: bold; } .certificate-details { font-size: 1.1rem; color: #555; text-align: center; margin: 30px 0; line-height: 1.6; } .signature-area { margin-top: 60px; } .signature-line { border-top: 2px solid #333; width: 250px; margin: 0 auto; padding-top: 10px; } .certificate-footer { margin-top: 40px; font-size: 0.9rem; color: #95a5a6; text-align: center; } @media print { body { background: white !important; padding: 0; } .no-print { display: none; } .certificate-container { border: none; box-shadow: none; padding: 20px; } } </style> </head> <body> <div class="certificate-container"> <div class="certificate-title">CERTIFICATE OF COMPLETION</div> <div class="certificate-subtitle">This is to certify that</div> <div class="student-name"><?php echo htmlspecialchars($data['student_name']); ?></div> <div class="certificate-details"> has successfully completed the <span class="course-name"><?php echo htmlspecialchars($data['category_name']); ?></span><br> with a final score of <strong><?php echo $data['percentage']; ?>%</strong><br> on <?php echo date('F j, Y', strtotime($data['issued_date'])); ?> </div> <div class="signature-area"> <div class="row"> <div class="col-md-6 text-center"> <div class="signature-line"> <strong>Arjun Singh</strong><br> Senior Instructor </div> </div> <div class="col-md-6 text-center"> <div class="signature-line"> <strong>Sunil Kumar</strong><br> Program Director </div> </div> </div> </div> <div class="certificate-footer"> Certificate ID: <?php echo $data['certificate_code']; ?><br> Issued: <?php echo date('M j, Y', strtotime($data['issued_date'])); ?> | Valid Until: <?php echo date('M j, Y', strtotime($data['expiry_date'])); ?> </div> </div> <div class="no-print text-center mt-4"> <button onclick="window.print()" class="btn btn-primary me-2"> <i class="fas fa-print"></i> Print Certificate </button> <a href="student_dashboard.php" class="btn btn-secondary"> <i class="fas fa-arrow-left"></i> Back to Dashboard </a> <div class="mt-3"> <small class="text-white"> <i class="fas fa-info-circle"></i> For PDF version, install TCPDF library in the tcpdf folder </small> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/js/all.min.js"></script> </body> </html> <?php } ?>
Coded With 💗 by
HanzOFC