| Server IP : 104.21.80.248 / 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 : E:/Inetpub/www/training/admin - Copy/ |
Upload File : |
<?php
include("../session.php");
// ตรวจสอบสิทธิ์
if ($role != 'admin') {
header("Location: ../index.php");
exit;
}
include("../db.php");
// ตรวจสอบว่ามีการระบุ id
if (!isset($_GET['id'])) {
echo "ไม่ได้ระบุรหัสผลการสอบ";
exit;
}
$exam_id = intval($_GET['id']);
// ดึงข้อมูลผลการสอบ
$result = mysqli_query($conn, "SELECT e.*, s.name as subject_name, u.username, s.pass_percentage
FROM exam_results e
JOIN subjects s ON e.subject_id = s.id
JOIN users u ON e.user_id = u.id
WHERE e.id = $exam_id");
if (!$exam = mysqli_fetch_assoc($result)) {
echo "ไม่พบข้อมูลผลการสอบ";
exit;
}
// ดึงข้อมูลคำตอบของผู้ใช้
$user_id = $exam['user_id'];
$subject_id = $exam['subject_id'];
$test_date = $exam['test_date'];
$answers_sql = "SELECT ua.*, q.question, q.choice1, q.choice2, q.choice3, q.choice4, q.correct_choice, q.score
FROM user_answers ua
JOIN questions q ON ua.question_id = q.id
WHERE ua.user_id = $user_id
AND ua.subject_id = $subject_id
AND ua.id IN (
SELECT MAX(id) FROM user_answers
WHERE user_id = $user_id
AND subject_id = $subject_id
GROUP BY question_id
HAVING MAX(id) <= (
SELECT MAX(id) FROM user_answers
WHERE user_id = $user_id
AND subject_id = $subject_id
AND id IN (
SELECT MAX(id) FROM user_answers
WHERE user_id = $user_id
GROUP BY question_id
)
)
)
ORDER BY ua.id ASC";
$answers_result = mysqli_query($conn, $answers_sql);
?>
<!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">
<style>
.answer-detail {
margin-bottom: 30px;
border: 1px solid #ddd;
padding: 15px;
border-radius: 4px;
}
.answer-header {
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.correct-answer {
color: #5cb85c;
font-weight: bold;
}
.wrong-answer {
color: #d9534f;
font-weight: bold;
}
.choice-item {
margin-bottom: 5px;
padding: 8px 15px;
border-radius: 4px;
}
.user-selected {
background-color: #f5f5f5;
border: 1px solid #ddd;
}
.correct-choice {
background-color: #dff0d8;
border: 1px solid #d6e9c6;
}
.wrong-choice {
background-color: #f2dede;
border: 1px solid #ebccd1;
}
</style>
</head>
<body>
<div class="container">
<h3 class="text-center">รายละเอียดผลการสอบ</h3>
<p class="text-right">
<a href="exam_reports.php" class="btn btn-default btn-sm">← กลับหน้ารายงาน</a>
</p>
<!-- ข้อมูลสรุปผลการสอบ -->
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title">ข้อมูลการสอบ</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<dl class="dl-horizontal">
<dt>ผู้สอบ:</dt>
<dd><?php echo htmlspecialchars($exam['username']); ?></dd>
<dt>วิชา:</dt>
<dd><?php echo htmlspecialchars($exam['subject_name']); ?></dd>
<dt>วันที่สอบ:</dt>
<dd><?php echo date('d/m/Y H:i:s', strtotime($exam['test_date'])); ?></dd>
</dl>
</div>
<div class="col-md-6">
<dl class="dl-horizontal">
<dt>คะแนนที่ได้:</dt>
<dd><?php echo $exam['score']; ?></dd>
<dt>เปอร์เซ็นต์:</dt>
<dd><?php echo number_format($exam['percentage'], 2); ?>%</dd>
<dt>เกณฑ์ผ่าน:</dt>
<dd><?php echo $exam['pass_percentage']; ?>%</dd>
<dt>ผลการสอบ:</dt>
<dd>
<?php if ($exam['passed']): ?>
<span class="label label-success">ผ่าน</span>
<?php else: ?>
<span class="label label-danger">ไม่ผ่าน</span>
<?php endif; ?>
</dd>
</dl>
</div>
</div>
</div>
</div>
<!-- รายละเอียดคำตอบ -->
<h4>รายละเอียดคำตอบ</h4>
<?php
$question_number = 1;
if (mysqli_num_rows($answers_result) > 0):
while ($answer = mysqli_fetch_assoc($answers_result)):
?>
<div class="answer-detail">
<div class="answer-header">
<h4>
ข้อที่ <?php echo $question_number++; ?>:
<?php echo htmlspecialchars($answer['question']); ?>
<?php if ($answer['is_correct']): ?>
<span class="pull-right correct-answer"><i class="glyphicon glyphicon-ok"></i> ถูกต้อง</span>
<?php else: ?>
<span class="pull-right wrong-answer"><i class="glyphicon glyphicon-remove"></i> ไม่ถูกต้อง</span>
<?php endif; ?>
</h4>
</div>
<div class="choices">
<?php for ($i = 1; $i <= 4; $i++): ?>
<?php if (!empty($answer["choice$i"])): ?>
<?php
$class = '';
if ($answer['selected_choice'] == $i && $answer['is_correct']) {
$class = 'user-selected correct-choice';
} elseif ($answer['selected_choice'] == $i && !$answer['is_correct']) {
$class = 'user-selected wrong-choice';
} elseif ($answer['correct_choice'] == $i) {
$class = 'correct-choice';
}
?>
<div class="choice-item <?php echo $class; ?>">
<strong><?php echo $i; ?>.</strong> <?php echo htmlspecialchars($answer["choice$i"]); ?>
<?php if ($answer['selected_choice'] == $i): ?>
<span class="pull-right"><i class="glyphicon glyphicon-hand-left"></i> ผู้ใช้เลือก</span>
<?php endif; ?>
<?php if ($answer['correct_choice'] == $i): ?>
<span class="pull-right" style="margin-right: 10px;"><i class="glyphicon glyphicon-check"></i> คำตอบที่ถูกต้อง</span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endfor; ?>
<?php if ($answer['selected_choice'] === NULL): ?>
<div class="alert alert-warning">
<i class="glyphicon glyphicon-info-sign"></i> ผู้ใช้ไม่ได้เลือกคำตอบ
</div>
<?php endif; ?>
</div>
</div>
<?php
endwhile;
else:
?>
<div class="alert alert-info">
<i class="glyphicon glyphicon-info-sign"></i> ไม่พบข้อมูลคำตอบของผู้ใช้
</div>
<?php endif; ?>
</div>
</body>
</html>