| 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 : E:/Inetpub/www/training/group/ |
Upload File : |
<?php
include("../session.php");
include("../db.php");
// ตรวจสอบสิทธิ์
if ($role != 'group') {
header("Location: ../index.php");
exit;
}
// ดำเนินการลบวิชา (ถ้ามี)
if (isset($_GET['del'])) {
$id = intval($_GET['del']);
mysqli_query($conn, "DELETE FROM subjects WHERE id = $id AND group_id = $user_id");
header("Location: subjects.php");
exit;
}
// ดำเนินการลบลิงค์เนื้อหา
if (isset($_GET['del_link'])) {
$link_id = intval($_GET['del_link']);
mysqli_query($conn, "DELETE FROM subject_content_links WHERE id = $link_id");
header("Location: subjects.php");
exit;
}
// จัดการการเพิ่มลิงค์เนื้อหา
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_content_link'])) {
$subject_id = $_POST['subject_id'];
$link_title = $_POST['link_title'];
$link_url = $_POST['link_url'];
if (!empty($link_title) && !empty($link_url)) {
$stmt = $conn->prepare("INSERT INTO subject_content_links (subject_id, link_title, link_url) VALUES (?, ?, ?)");
$stmt->bind_param("iss", $subject_id, $link_title, $link_url);
$stmt->execute();
$stmt->close();
header("Location: subjects.php");
exit;
}
}
// จัดการการแก้ไขลิงค์เนื้อหา
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit_content_link'])) {
$link_id = $_POST['link_id'];
$link_title = $_POST['link_title'];
$link_url = $_POST['link_url'];
if (!empty($link_title) && !empty($link_url)) {
$stmt = $conn->prepare("UPDATE subject_content_links SET link_title = ?, link_url = ? WHERE id = ?");
$stmt->bind_param("ssi", $link_title, $link_url, $link_id);
$stmt->execute();
$stmt->close();
header("Location: subjects.php");
exit;
}
}
// ดึงข้อมูลวิชาของกลุ่มนี้เท่านั้น
$result = mysqli_query($conn, "SELECT * FROM subjects WHERE group_id = $user_id ORDER BY curriculum_year DESC");
$subjects = [];
while ($row = mysqli_fetch_assoc($result)) {
// ดึงลิงค์เนื้อหาของแต่ละวิชา
$subject_id = $row['id'];
$links_query = $conn->query("SELECT * FROM subject_content_links WHERE subject_id = $subject_id");
$row['content_links'] = [];
while ($link = $links_query->fetch_assoc()) {
$row['content_links'][] = $link;
}
$subjects[] = $row;
}
?>
<!DOCTYPE html>
<html lang mene="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>จัดการวิชา</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
:root {
--primary-color: #4e73df;
--secondary-color: #858796;
--success-color: #1cc88a;
--danger-color: #e74a3b;
--warning-color: #f6c23e;
--light-bg: #f8f9fc;
}
body {
background-color: var(--light-bg);
font-family: 'Prompt', sans-serif;
padding-top: 56px;
}
.main-navbar {
background: linear-gradient(90deg, var(--primary-color) 0%, #224abe 100%);
padding: 0.5rem 1rem;
}
.main-navbar .navbar-brand {
color: white;
font-weight: 600;
}
.main-navbar .nav-link {
color: rgba(255, 255, 255, 0.8);
padding: 0.75rem 1rem;
border-radius: 0.375rem;
transition: all 0.3s;
margin: 0 0.25rem;
}
.main-navbar .nav-link:hover,
.main-navbar .nav-link.active {
color: white;
background-color: rgba(255, 255, 255, 0.1);
}
.main-navbar .nav-link i {
margin-right: 0.5rem;
}
.card {
border: none;
border-radius: 0.5rem;
box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.1);
margin-bottom: 1.5rem;
}
.card-header {
background-color: #f8f9fc;
border-bottom: 1px solid #e3e6f0;
padding: 1rem 1.25rem;
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-success {
background-color: var(--success-color);
border-color: var(--success-color);
}
.btn-danger {
background-color: var(--danger-color);
border-color: var(--danger-color);
}
.btn-warning {
background-color: var(--warning-color);
border-color: var(--warning-color);
}
.user-dropdown .dropdown-toggle::after {
display: none;
}
.user-dropdown .dropdown-toggle {
display: flex;
align-items: center;
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
}
.user-dropdown .dropdown-toggle:hover {
color: white;
}
.user-dropdown .dropdown-menu {
margin-top: 0.5rem;
border: none;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}
.table {
border-radius: 0.5rem;
overflow: hidden;
}
.content-links-list {
margin-top: 0.5rem;
}
.content-links-list li {
margin-bottom: 0.25rem;
display: flex;
align-items: center;
}
.content-links-list .link-actions {
margin-left: 0.5rem;
}
@media (max-width: 992px) {
.navbar-collapse {
background-color: var Patents(--primary-color);
padding: 1rem;
border-radius: 0.5rem;
margin-top: 0.5rem;
}
}
</style>
<!-- Font from Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap" rel="stylesheet">
</head>
<body>
<!-- Main Navbar -->
<nav class="navbar navbar-expand-lg fixed-top main-navbar">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-laptop-code me-2"></i>
ระบบข้อสอบออนไลน์
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">
<i class="fas fa-tachometer-alt"></i>
ภาพรวม
</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#">
<i class="fas fa-book"></i>
จัดการวิชา
</a>
</li>
</ul>
<div class="user-dropdown dropdown">
<a href="#" class="dropdown-toggle" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
<div>
<div class="fw-bold text-white"><?php echo htmlspecialchars($u_name); ?></div>
</div>
<i class="fas fa-chevron-down ms-2"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end shadow">
<li><a class="dropdown-item" href="../logout.php"><i class="fas fa-sign-out-alt me-2"></i> ออกจากระบบ</a></li>
</ul>
</div>
</div>
</div>
</nav>
<!-- Main Content -->
<div class="container-fluid px-4 mt-4">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h6 class="m-0 fw-bold">จัดการวิชา - <?php echo htmlspecialchars($group_name); ?></h6>
<div>
<a href="dashboard.php" class="btn btn-sm btn-secondary me-2"><i class="fas fa-arrow-left me-1"></i> กลับหน้าหลัก</a>
<a href="subject_form.php" class="btn btn-sm btn-primary"><i class="fas fa-plus me-1"></i> เพิ่มวิชา</a>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover align-middle">
<thead class="table-light">
<tr>
<th width="5%" class="text-center">ที่</th>
<th width="35%">ชื่อวิชา</th>
<th width="15%" class="text-center">หลักสูตรปี</th>
<th width="10%" class="text-center">เกณฑ์ผ่าน</th>
<th width="35%" class="text-center">จัดการ</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($subjects as $subject):
?>
<tr>
<td class="text-center"><?php echo $i++; ?></td>
<td>
<div class="fw-bold"><?php echo htmlspecialchars($subject['name']); ?></div>
<?php if (!empty($subject['content_links'])): ?>
<ul class="content-links-list small">
<?php foreach ($subject['content_links'] as $link): ?>
<li>
<a href="<?php echo htmlspecialchars($link['link_url']); ?>" target="_blank">
<?php echo htmlspecialchars($link['link_title']); ?>
</a>
<span class="link-actions">
<a href="#" class="text-warning me-1" data-bs-toggle="modal"
data-bs-target="#editContentLinkModal<?php echo $link['id']; ?>">
<i class="fas fa-edit"></i>
</a>
<a href="?del_link=<?php echo $link['id']; ?>" class="text-danger"
onclick="return confirm('คุณแน่ใจว่าต้องการลบลิงค์นี้?')">
<i class="fas fa-trash"></i>
</a>
</span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</td>
<td class="text-center"><?php echo htmlspecialchars($subject['curriculum_year']); ?></td>
<td class="text-center"><?php echo $subject['pass_percentage']; ?>%</td>
<td class="text-center">
<a href="subject_form.php?id=<?php echo $subject['id']; ?>" class="btn btn-sm btn-primary me-1">
<i class="fas fa-edit me-1"></i> แก้ไข
</a>
<a href="?del=<?php echo $subject['id']; ?>" class="btn btn-sm btn-danger me-1"
onclick="return confirm('คุณแน่ใจว่าต้องการลบวิชานี้?')">
<i class="fas fa-trash me-1"></i> ลบ
</a>
<a href="questions.php?subject_id=<?php echo $subject['id']; ?>" class="btn btn-sm btn-success me-1">
<i class="fas fa-file-alt me-1"></i> ข้อสอบ
</a>
<button type="button" class="btn btn-sm btn-warning" data-bs-toggle="modal"
data-bs-target="#contentLinkModal<?php echo $subject['id']; ?>">
<i class="fas fa-link me-1"></i> เพิ่มลิงค์
</button>
</td>
</tr>
<!-- Modal for Adding Content Link -->
<div class="modal fade" id="contentLinkModal<?php echo $subject['id']; ?>" tabindex="-1"
aria-labelledby="contentLinkModalLabel<?php echo $subject['id']; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="contentLinkModalLabel<?php echo $subject['id']; ?>">
เพิ่มลิงค์เนื้อหา: <?php echo htmlspecialchars($subject['name']); ?>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" name="subject_id" value="<?php echo $subject['id']; ?>">
<div class="mb-3">
<label for="link_title<?php echo $subject['id']; ?>" class="form-label">ชื่อลิงค์</label>
<input type="text" name="link_title" id="link_title<?php echo $subject['id']; ?>"
class="form-control" placeholder="เช่น การแนะนำวิชา" required>
</div>
<div class="mb-3">
<label for="link_url<?php echo $subject['id']; ?>" class="form-label">URL ลิงค์</label>
<input type="url" name="link_url" id="link_url<?php echo $subject['id']; ?>"
class="form-control" placeholder="เช่น https://example.com" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">ยกเลิก</button>
<button type="submit" name="add_content_link" class="btn btn-primary">
<i class="fas fa-plus me-1"></i> เพิ่มลิงค์
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal for Editing Content Link -->
<?php foreach ($subject['content_links'] as $link): ?>
<div class="modal fade" id="editContentLinkModal<?php echo $link['id']; ?>" tabindex="-1"
aria-labelledby="editContentLinkModalLabel<?php echo $link['id']; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editContentLinkModalLabel<?php echo $link['id']; ?>">
แก้ไขลิงค์เนื้อหา: <?php echo htmlspecialchars($subject['name']); ?>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" name="link_id" value="<?php echo $link['id']; ?>">
<div class="mb-3">
<label for="edit_link_title<?php echo $link['id']; ?>" class="form-label">ชื่อลิงค์</label>
<input type="text" name="link_title" id="edit_link_title<?php echo $link['id']; ?>"
class="form-control" value="<?php echo htmlspecialchars($link['link_title']); ?>" required>
</div>
<div class="mb-3">
<label for="edit_link_url<?php echo $link['id']; ?>" class="form-label">URL ลิงค์</label>
<input type="url" name="link_url" id="edit_link_url<?php echo $link['id']; ?>"
class="form-control" value="<?php echo htmlspecialchars($link['link_url']); ?>" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">ยกเลิก</button>
<button type="submit" name="edit_content_link" class="btn btn-primary">
<i class="fas fa-save me-1"></i> บันทึก
</button>
</div>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
<?php if (empty($subjects)): ?>
<tr>
<td colspan="5" class="text-center text-muted">ยังไม่มีวิชา กรุณาเพิ่มวิชาใหม่</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<div class="card-footer small text-muted">
แสดงทั้งหมด <?php echo count($subjects); ?> วิชา | อัพเดทล่าสุด: <?php echo date("d/m/Y H:i"); ?>
</div>
</div>
</div>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>