| Server IP : 172.67.187.206 / Your IP : 172.71.28.156 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
include("../session.php");
if ($role != 'user') {
header("Location: ../index.php");
exit;
}
include("../db.php");
// ดึงข้อมูลวิชาทั้งหมด
$res = mysqli_query($conn, "SELECT * FROM subjects ORDER BY curriculum_year DESC");
$subjects = [];
while ($row = mysqli_fetch_assoc($res)) {
$subjects[] = $row;
}
// ดึงข้อมูลผลการสอบของผู้ใช้
$user_id = $_SESSION['user_id'];
$exam_results = [];
$result = mysqli_query($conn, "SELECT * FROM exam_results WHERE user_id = $user_id");
while ($row = mysqli_fetch_assoc($result)) {
$exam_results[$row['subject_id']] = $row;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>หน้าหลัก - ผู้ใช้</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h3 class="text-center">ระบบข้อสอบออนไลน์ - หน้าหลักผู้ใช้</h3>
<p class="text-right">
ยินดีต้อนรับ, <strong><?php echo htmlspecialchars($u_name); ?></strong>
| <a href="../logout.php" class="btn btn-danger btn-sm">ออกจากระบบ</a>
</p>
<div class="panel panel-default">
<div class="panel-heading">วิชาทั้งหมดที่มีในระบบ</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th width="5%">#</th>
<th width="30%">ชื่อวิชา</th>
<th width="10%">หลักสูตรปี</th>
<th width="15%">เปอร์เซ็นต์ที่ต้องผ่าน</th>
<th width="10%">สถานะ</th>
<th width="15%">คะแนนที่ได้</th>
<th width="15%">การทำข้อสอบ</th>
</tr>
</thead>
<tbody>
<?php foreach ($subjects as $subject): ?>
<tr>
<td><?php echo $subject['id']; ?></td>
<td><?php echo htmlspecialchars($subject['name']); ?></td>
<td align="center"><?php echo $subject['curriculum_year']; ?></td>
<td align="center"><?php echo $subject['pass_percentage']; ?>%</td>
<td align="center">
<?php if (isset($exam_results[$subject['id']])): ?>
<?php if ($exam_results[$subject['id']]['passed']): ?>
<span class="label label-success">สอบผ่านแล้ว</span>
<?php else: ?>
<span class="label label-danger">สอบไม่ผ่าน</span>
<?php endif; ?>
<?php else: ?>
<span class="label label-default">ยังไม่ได้สอบ</span>
<?php endif; ?>
</td>
<td align="center">
<?php if (isset($exam_results[$subject['id']])): ?>
<?php echo $exam_results[$subject['id']]['score']; ?> คะแนน
(<?php echo $exam_results[$subject['id']]['percentage']; ?>%)
<?php else: ?>
-
<?php endif; ?>
</td>
<td align="center">
<?php if (!isset($exam_results[$subject['id']]) || !$exam_results[$subject['id']]['passed']): ?>
<a href="take_exam.php?exam=<?php echo base64_encode($subject['id']); ?>" class="btn btn-primary btn-sm">เริ่มทำข้อสอบ</a>
<?php else: ?>
<!-- <button class="btn btn-default btn-sm" disabled>ทำข้อสอบแล้ว</button> -->
<a href="generate_certificate.php?subject=<?php echo base64_encode($subject['id']); ?>" class="btn btn-success btn-sm" target="_blank">
<span class="glyphicon glyphicon-download-alt"></span> ดาวน์โหลดเกียรติบัตร
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>