| Server IP : 172.67.187.206 / 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/admin - Copy/ |
Upload File : |
<?php
include("../session.php");
// ตรวจสอบสิทธิ์
if ($role != 'admin') {
header("Location: ../index.php");
exit;
}
include("../db.php");
// ตัวกรอง
$filter_subject = isset($_GET['subject_id']) ? intval($_GET['subject_id']) : 0;
$filter_user = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
$filter_status = isset($_GET['status']) ? $_GET['status'] : '';
$filter_date_start = isset($_GET['date_start']) ? $_GET['date_start'] : '';
$filter_date_end = isset($_GET['date_end']) ? $_GET['date_end'] : '';
// สร้าง SQL พื้นฐาน
$sql = "SELECT e.*, s.name as subject_name, u.username,
(SELECT COUNT(*) FROM questions WHERE subject_id = e.subject_id) as total_questions
FROM exam_results e
JOIN subjects s ON e.subject_id = s.id
JOIN users u ON e.user_id = u.id
WHERE 1=1";
// เพิ่มเงื่อนไขการกรอง
if ($filter_subject > 0) {
$sql .= " AND e.subject_id = $filter_subject";
}
if ($filter_user > 0) {
$sql .= " AND e.user_id = $filter_user";
}
if ($filter_status !== '') {
$status = intval($filter_status);
$sql .= " AND e.passed = $status";
}
if (!empty($filter_date_start)) {
$date_start = mysqli_real_escape_string($conn, $filter_date_start);
$sql .= " AND DATE(e.test_date) >= '$date_start'";
}
if (!empty($filter_date_end)) {
$date_end = mysqli_real_escape_string($conn, $filter_date_end);
$sql .= " AND DATE(e.test_date) <= '$date_end'";
}
// เรียงลำดับ
$sql .= " ORDER BY e.test_date DESC";
// ดึงข้อมูลผลการสอบ
$result = mysqli_query($conn, $sql);
// ดึงข้อมูลวิชาทั้งหมดสำหรับตัวกรอง
$subjects = mysqli_query($conn, "SELECT * FROM subjects ORDER BY name ASC");
// ดึงข้อมูลผู้ใช้ทั้งหมดสำหรับตัวกรอง
$users = mysqli_query($conn, "SELECT * FROM users ORDER BY username ASC");
// สรุปข้อมูล
$summary = array(
'total' => 0,
'passed' => 0,
'failed' => 0,
'average_score' => 0,
'average_percentage' => 0
);
// คำนวณข้อมูลสรุป
$total_score = 0;
$total_percentage = 0;
$exam_count = mysqli_num_rows($result);
if ($exam_count > 0) {
$summary['total'] = $exam_count;
// คำนวณค่าสรุปโดยการวนลูปข้อมูลทั้งหมด
mysqli_data_seek($result, 0); // รีเซ็ตตัวชี้ตำแหน่งข้อมูล
while ($row = mysqli_fetch_assoc($result)) {
if ($row['passed'] == 1) {
$summary['passed']++;
} else {
$summary['failed']++;
}
$total_score += $row['score'];
$total_percentage += $row['percentage'];
}
$summary['average_score'] = $total_score / $exam_count;
$summary['average_percentage'] = $total_percentage / $exam_count;
// รีเซ็ตตัวชี้ตำแหน่งข้อมูลอีกครั้งสำหรับการแสดงผลในตาราง
mysqli_data_seek($result, 0);
}
?>
<!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>
.filter-panel {
margin-bottom: 20px;
padding: 15px;
background-color: #f5f5f5;
border-radius: 4px;
}
.summary-panel {
margin-bottom: 20px;
}
.summary-item {
text-align: center;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 10px;
}
.summary-number {
font-size: 24px;
font-weight: bold;
}
.passed-color {
color: #5cb85c;
}
.failed-color {
color: #d9534f;
}
</style>
</head>
<body>
<div class="container">
<h3 class="text-center">รายงานผลการสอบ</h3>
<p class="text-right">
<a href="dashboard.php" class="btn btn-default btn-sm">← กลับหน้าหลัก</a>
</p>
<!-- ส่วนกรองข้อมูล -->
<div class="filter-panel">
<form method="get" class="form-horizontal">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="col-sm-4 control-label">วิชา:</label>
<div class="col-sm-8">
<select name="subject_id" class="form-control">
<option value="0">ทั้งหมด</option>
<?php while ($subject = mysqli_fetch_assoc($subjects)): ?>
<option value="<?php echo $subject['id']; ?>" <?php echo $filter_subject == $subject['id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($subject['name']); ?>
</option>
<?php endwhile; ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">ผู้ใช้:</label>
<div class="col-sm-8">
<select name="user_id" class="form-control">
<option value="0">ทั้งหมด</option>
<?php while ($user = mysqli_fetch_assoc($users)): ?>
<option value="<?php echo $user['id']; ?>" <?php echo $filter_user == $user['id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($user['username']); ?>
</option>
<?php endwhile; ?>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-sm-4 control-label">สถานะ:</label>
<div class="col-sm-8">
<select name="status" class="form-control">
<option value="">ทั้งหมด</option>
<option value="1" <?php echo $filter_status === '1' ? 'selected' : ''; ?>>ผ่าน</option>
<option value="0" <?php echo $filter_status === '0' ? 'selected' : ''; ?>>ไม่ผ่าน</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">ช่วงวันที่:</label>
<div class="col-sm-4">
<input type="date" name="date_start" class="form-control" value="<?php echo $filter_date_start; ?>">
</div>
<div class="col-sm-4">
<input type="date" name="date_end" class="form-control" value="<?php echo $filter_date_end; ?>">
</div>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">กรองข้อมูล</button>
<a href="exam_reports.php" class="btn btn-default">ล้างตัวกรอง</a>
</div>
</form>
</div>
<!-- ส่วนสรุปข้อมูล -->
<div class="summary-panel">
<div class="row">
<div class="col-md-3">
<div class="summary-item">
<div>จำนวนการสอบทั้งหมด</div>
<div class="summary-number"><?php echo $summary['total']; ?></div>
</div>
</div>
<div class="col-md-3">
<div class="summary-item">
<div>ผ่าน</div>
<div class="summary-number passed-color"><?php echo $summary['passed']; ?></div>
<div><?php echo $summary['total'] > 0 ? number_format(($summary['passed'] / $summary['total']) * 100, 2) : 0; ?>%</div>
</div>
</div>
<div class="col-md-3">
<div class="summary-item">
<div>ไม่ผ่าน</div>
<div class="summary-number failed-color"><?php echo $summary['failed']; ?></div>
<div><?php echo $summary['total'] > 0 ? number_format(($summary['failed'] / $summary['total']) * 100, 2) : 0; ?>%</div>
</div>
</div>
<div class="col-md-3">
<div class="summary-item">
<div>คะแนนเฉลี่ย</div>
<div class="summary-number"><?php echo number_format($summary['average_percentage'], 2); ?>%</div>
</div>
</div>
</div>
</div>
<!-- ตารางข้อมูลผลการสอบ -->
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>ผู้ใช้</th>
<th>วิชา</th>
<th>คะแนน</th>
<th>เปอร์เซ็นต์</th>
<th>สถานะ</th>
<th>วันที่สอบ</th>
<th>รายละเอียด</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
if (mysqli_num_rows($result) > 0):
while ($row = mysqli_fetch_assoc($result)):
?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo htmlspecialchars($row['username']); ?></td>
<td><?php echo htmlspecialchars($row['subject_name']); ?></td>
<td><?php echo $row['score']; ?> / <?php echo $row['total_questions']; ?></td>
<td><?php echo number_format($row['percentage'], 2); ?>%</td>
<td>
<?php if ($row['passed']): ?>
<span class="label label-success">ผ่าน</span>
<?php else: ?>
<span class="label label-danger">ไม่ผ่าน</span>
<?php endif; ?>
</td>
<td><?php echo date('d/m/Y H:i:s', strtotime($row['test_date'])); ?></td>
<td>
<a href="exam_detail.php?id=<?php echo $row['id']; ?>" class="btn btn-info btn-xs">รายละเอียด</a>
</td>
</tr>
<?php
endwhile;
else:
?>
<tr>
<td colspan="8" class="text-center">ไม่พบข้อมูลผลการสอบ</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</body>
</html>