| Server IP : 104.21.80.248 / Your IP : 172.71.28.155 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/training/user/ |
Upload File : |
<?php
function thainumDigit($num) {
return str_replace(
array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'),
array("๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙"),
$num
);
}
include '../db.php';
include '../pdf1.84/fpdf.php';
// Start session if not already started
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Retrieve and decode the user ID from the URL
$encoded_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
$user_id = base64_decode($encoded_id);
// Fetch user information from the database
$user_query = mysqli_query($conn, "SELECT u_name FROM users WHERE id = $user_id");
$user = mysqli_fetch_assoc($user_query);
// Check if user exists
if (empty($user) || empty($user['u_name'])) {
echo "ไม่พบข้อมูลชื่อผู้ใช้";
exit;
}
$user_name = $user['u_name'];
// Verify eligibility for Gold Certificate (passed all 2568 curriculum subjects)
$result = mysqli_query($conn, "
SELECT COUNT(s.id) as total_2568,
SUM(CASE WHEN er.passed = 1 THEN 1 ELSE 0 END) as passed_2568
FROM subjects s
LEFT JOIN exam_results er ON s.id = er.subject_id AND er.user_id = $user_id
WHERE s.curriculum_year = '2568'
");
$row = mysqli_fetch_assoc($result);
$total_2568 = $row['total_2568'];
$passed_2568 = $row['passed_2568'];
if ($passed_2568 < $total_2568 || $total_2568 == 0) {
echo "คุณไม่มีสิทธิ์รับเกียรติบัตรทอง";
exit;
}
// Generate certificate number
$cert_id = date('Y') . sprintf('%04d', $user_id);
// Create PDF
$pdf = new FPDF('L', 'mm', 'A4');
$pdf->SetAutoPageBreak(false);
$pdf->AddPage();
$pdf->AddFont('sarabun', '', 'THSarabun.php');
$pdf->AddFont('sarabunb', '', 'THSarabunB.php');
$pdf->Image('img/gol.png', 0, 0, 297, 210);
// Display user name
$pdf->SetXY(49, 53);
$pdf->SetFont('sarabunb', '', 48);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(200, 84, iconv('utf-8', 'cp874', $user_name), 0, 1, 'C');
// Display certificate number
$pdf->SetXY(200, 13);
$pdf->SetFont('sarabun', '', 18);
$pdf->SetTextColor(0, 0, 0);
//$pdf->Cell(65, 40, iconv('utf-8', 'cp874', 'เลขที่ สพม.รบ. ' . thainumDigit($cert_id) . '/๒๕๖๘'), 0, 1, 'R');
$pdf->Output();
?>