Gestionnaire de fichiers - Editer - /home/kridsana/webapp.cm.in.th/663012801/u66301280015/Final/student_attendance.php
Arrière
<?php session_start(); require_once 'config.php'; // ตรวจสอบการล็อกอิน if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') { header('Location: Login'); exit(); } // ตรวจสอบการเชื่อมต่อฐานข้อมูล if (!$conn) { die("Database connection failed: " . mysqli_connect_error()); } // ดึงรายการห้องเรียนทั้งหมด $sql_groups = "SELECT DISTINCT groupCode, groupAbbr FROM student ORDER BY groupAbbr"; $result_groups = $conn->query($sql_groups); $groups = []; while ($row = $result_groups->fetch_assoc()) { $groups[] = $row; } // กำหนดห้องเรียนที่เลือก $selected_group = isset($_GET['group']) ? $_GET['group'] : ''; // ดึงข้อมูลนักเรียนตามห้องที่เลือก $sql_students = "SELECT studentCode, firstname, surname, gradeNameTh, groupAbbr, groupName FROM student WHERE groupCode = ? ORDER BY studentCode"; $stmt = $conn->prepare($sql_students); $stmt->bind_param("s", $selected_group); $stmt->execute(); $result_students = $stmt->get_result(); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ระบบเช็คชื่อนักเรียน</title> <link href="https://fonts.googleapis.com/css2?family=K2D:wght@300;400;500;600&display=swap" rel="stylesheet"> <link rel="stylesheet" href="./Css/style.css"> <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script> <script> $(document).ready(function() { $('#groupSelect').select2({ placeholder: "โปรดเลือกห้องเรียน", allowClear: true }); }); </script> </head> <body> <!-- Navbar --> <nav class="navbar"> <div class="nav-container"> <a href="Admin_Page.php" class="nav-brand">ระบบจัดการ</a> <div class="nav-menu"> <a href="student_attendance.php" class="nav-link active">ระบบเช็คชื่อนักเรียน</a> <a href="student_attendance_report.php" class="nav-link">รายงานผลการเช็คชื่อ</a> <a href="activity_attendance.php" class="nav-link">ระบบเช็คชื่อเข้ากิจกรรม</a> <a href="Logout.php" class="nav-link" style="background-color: #e74c3c;">ออกจากระบบ</a> </div> </div> </nav> <div class="dashboard"> <div class="attendance-container"> <div class="header"> <h2>ระบบเช็คชื่อนักเรียน</h2> <div class="attendance-controls"> <select id="groupSelect" class="group-select" onchange="window.location.href='student_attendance.php?group=' + this.value;"> <option value="">โปรดเลือกห้องเรียน</option> <?php foreach ($groups as $group): ?> <option value="<?php echo htmlspecialchars($group['groupCode']); ?>" <?php echo ($selected_group == $group['groupCode']) ? 'selected' : ''; ?>> <?php echo htmlspecialchars($group['groupAbbr']); ?> </option> <?php endforeach; ?> </select> <button type="button" class="save-btn" onclick="saveAttendance()">บันทึกข้อมูล</button> </div> </div> <div class="report-table"> <table> <thead> <tr> <th>รหัสนักเรียน</th> <th>ชื่อ</th> <th>นามสกุล</th> <th>ระดับชั้น</th> <th>ห้อง</th> <th>สถานะ</th> </tr> </thead> <tbody> <?php while ($student = $result_students->fetch_assoc()): ?> <tr> <td><?php echo htmlspecialchars($student['studentCode']); ?></td> <td><?php echo htmlspecialchars($student['firstname']); ?></td> <td><?php echo htmlspecialchars($student['surname']); ?></td> <td><?php echo htmlspecialchars($student['gradeNameTh']); ?></td> <td><?php echo htmlspecialchars($student['groupAbbr']); ?></td> <td> <div class="status-buttons"> <label> <input type="radio" name="status_<?php echo $student['studentCode']; ?>" value="มา" checked> <span class="status-label present">มา</span> </label> <label> <input type="radio" name="status_<?php echo $student['studentCode']; ?>" value="มาสาย"> <span class="status-label late">มาสาย</span> </label> <label> <input type="radio" name="status_<?php echo $student['studentCode']; ?>" value="ขาด"> <span class="status-label absent">ขาด</span> </label> <label> <input type="radio" name="status_<?php echo $student['studentCode']; ?>" value="ลา"> <span class="status-label leave">ลา</span> </label> </div> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> </div> </div> <script> // บันทึกข้อมูลการเช็คชื่อ function saveAttendance() { const selectedGroup = document.getElementById('groupSelect').value; // ดึงค่า groupCode ที่เลือก const attendanceData = { groupCode: selectedGroup, // เพิ่ม groupCode ในข้อมูลที่จะส่ง students: [] }; document.querySelectorAll('tbody tr').forEach(row => { const studentCode = row.cells[0].textContent; const status = row.querySelector('input[type="radio"]:checked').value; attendanceData.students.push({ studentCode: studentCode, status: status }); }); // ส่งข้อมูลไปบันทึก fetch('save_attendance.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(attendanceData) }) .then(response => response.json()) .then(data => { if (data.success) { alert('บันทึกข้อมูลสำเร็จ'); } else { alert('เกิดข้อผิดพลาดในการบันทึกข้อมูล: ' + (data.message || '')); } }) .catch(error => { alert('เกิดข้อผิดพลาดในการส่งข้อมูล: ' + error); }); } </script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Génération de la page: 0.15 |
proxy
|
phpinfo
|
Réglages