bạn có thể viết 1 modul của nukeviet 4.5 theo yêu cầu: kết nối data, khi học sinh nhập…
- User
bạn có thể viết 1 modul của nukeviet 4.5 theo yêu cầu: kết nối data, khi học sinh nhập đúng số điện thoại sẽ xuất ra thời khóa biểu, ....
Assistant
Mô-đun Kết nối dữ liệu và Hiển thị Thời Khóa Biểu cho NukeViet 4.5
Dưới đây là một mô-đun cho NukeViet 4.5 giúp kết nối dữ liệu và hiển thị thời khóa biểu khi học sinh nhập đúng số điện thoại.
1. Tạo file
student_timetable.php<?php /** * Mô-đun Hiển thị thời khóa biểu cho học sinh * NukeViet 4.5 */ if (!defined('NV_MAINFILE')) { die('Stop!!!'); } $module_info = array( 'title' => 'Thời khóa biểu học sinh', 'modfuncs' => array('main', 'timetable'), 'is_menu' => 1, 'version' => '1.0.0', 'date' => '2023-11-15', 'author' => 'Your Name', 'note' => 'Hiển thị thời khóa biểu cho học sinh' ); $module_config = array(); // Kết nối cơ sở dữ liệu function nv_student_timetable_connect_db() { global $db; // Kiểm tra kết nối if (!is_object($db)) { require_once NV_ROOTDIR . '/includes/core/database/mysql.php'; $db = new NV_Sql($global_config['dbport'], $global_config['dbhost'], $global_config['dbuname'], $global_config['dbpass'], $global_config['dbname'], $global_config['dbprefix']); } return $db; } // Lấy thông tin học sinh theo số điện thoại function nv_student_timetable_get_student($phone) { $db = nv_student_timetable_connect_db(); $sql = "SELECT * FROM " . NV_PREFIXLANG . "_students WHERE phone = :phone"; $stmt = $db->prepare($sql); $stmt->bindParam(':phone', $phone, PDO::PARAM_STR); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); } // Lấy thời khóa biểu của học sinh function nv_student_timetable_get_timetable($student_id) { $db = nv_student_timetable_connect_db(); $sql = "SELECT t.*, s.subject_name, r.room_name, t.teacher_name FROM " . NV_PREFIXLANG . "_timetable t JOIN " . NV_PREFIXLANG . "_subjects s ON t.subject_id = s.subject_id JOIN " . NV_PREFIXLANG . "_rooms r ON t.room_id = r.room_id WHERE t.student_id = :student_id ORDER BY t.day, t.period"; $stmt = $db->prepare($sql); $stmt->bindParam(':student_id', $student_id, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } // Hiển thị form nhập số điện thoại function nv_student_timetable_main() { global $module_info, $module_data, $lang_module, $global_config; $contents = ''; // Kiểm tra nếu đã gửi form if ($nv_Request->isset_request('submit', 'post')) { $phone = $nv_Request->get_title('phone', 'post', ''); // Kiểm tra số điện thoại if (empty($phone)) { $contents = "Vui lòng nhập số điện thoại!"; } else { // Lấy thông tin học sinh $student = nv_student_timetable_get_student($phone); if (empty($student)) { $contents = "Không tìm thấy học sinh với số điện thoại này!"; } else { // Lấy thời khóa biểu $timetable = nv_student_timetable_get_timetable($student['student_id']); if (empty($timetable)) { $contents = "Học sinh này không có thời khóa biểu!"; } else { // Hiển thị thời khóa biểu $contents = nv_student_timetable_display_timetable($timetable); } } } } // Hiển thị form nhập số điện thoại $xtitle = $lang_module['student_timetable']; $xtcontent = ' <form method="post" action="' . NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_info['name'] . '"> <div class="form-group"> <label for="phone">' . $lang_module['enter_phone'] . '</label> <input type="text" class="form-control" id="phone" name="phone" placeholder="Nhập số điện thoại" required> </div> <button type="submit" name="submit" class="btn btn-primary">' . $lang_module['view_timetable'] . '</button> </form>'; if (!empty($contents)) { $xtcontent .= '<div class="mt-3">' . $contents . '</div>'; } $xtcontent .= ' <style> .timetable-table { width: 100%; border-collapse: collapse; margin-top: 20px; } .timetable-table th, .timetable-table td { border: 1px solid #ddd; padding: 8px; text-align: center; } .timetable-table th { background-color: #f2f2f2; } </style>'; include NV_ROOTDIR . '/includes/header.php'; echo nv_site_theme($contents); include NV_ROOTDIR . '/includes/footer.php'; } // Hiển thị thời khóa biểu function nv_student_timetable_display_timetable($timetable) { $html = '<h3>Thời khóa biểu</h3>'; $html .= '<table class="timetable-table">'; $html .= '<thead><tr><th>Thứ</th><th>Tiết</th><th>Môn học</th><th>Phòng</th><th>Giáo viên</th></tr></thead>'; $html .= '<tbody>'; $days = ['Thứ 2', 'Thứ 3', 'Thứ 4', 'Thứ 5', 'Thứ 6', 'Thứ 7', 'Chủ nhật']; $periods = ['1-2', '3-4', '5-6', '7-8', '9-10']; // Tạo bảng thời khóa biểu foreach ($days as $day) { $html .= '<tr><td rowspan="5">' . $day . '</td>'; foreach ($periods as $period) { $found = false; foreach ($timetable as $item) { if ($item['day'] == array_search($day, $days) + 1 && $item['period'] == array_search($period, $periods) + 1) { $html .= '<tr><td>' . $period . '</td><td>' . $item['subject_name'] . '</td><td>' . $item['room_name'] . '</td><td>' . $item['teacher_name'] . '</td></tr>'; $found = true; break; } } if (!$found) { $html .= '<tr><td>' . $period . '</td><td colspan="3">Không có môn học</td></tr>'; } } } $html .= '</tbody></table>'; return $html; } // Xử lý yêu cầu $op = $nv_Request->get_title('op', 'get', 'main'); $module = $nv_Request->get_title('module', 'get', ''); if ($module == $module_info['name']) { if ($op == 'main') { nv_student_timetable_main(); } elseif ($op == 'timetable') { // Xử lý yêu cầu thời khóa biểu } }2. Tạo file ngôn ngữ
lang_vi.php<?php if (!defined('NV_MAINFILE')) { die('Stop!!!'); } $lang_module['student_timetable'] = 'Thời khóa biểu học sinh'; $lang_module['enter_phone'] = 'Nhập số điện thoại của bạn'; $lang_module['view_timetable'] = 'Xem thời khóa biểu'; $lang_module['no_student_found'] = 'Không tìm thấy học sinh với số điện thoại này'; $lang_module['no_timetable'] = 'Học sinh này không có thời khóa biểu';3. Tạo file cấu hình
config.php<?php if (!defined('NV_MAINFILE')) { die('Stop!!!'); } $module_config = array(); // Cấu hình cơ sở dữ liệu $module_config['db_config'] = array( 'dbhost' => $global_config['dbhost'], 'dbport' => $global_config['dbport'], 'dbname' => $global_config['dbname'], 'dbuname' => $global_config['dbuname'], 'dbpass' => $global_config['dbpass'], 'dbprefix' => NV_PREFIXLANG . '_' );4. Tạo file cấu trúc cơ sở dữ liệu
install.sqlCREATE TABLE IF NOT EXISTS `nv4_students` ( `student_id` int(11) NOT NULL AUTO_INCREMENT, `student_code` varchar(20) NOT NULL, `full_name` varchar(100) NOT NULL, `date_of_birth` date DEFAULT NULL, `class_id` int(11) NOT NULL, `address` varchar(255) DEFAULT NULL, `phone` varchar(20) NOT NULL, `email` varchar(100) DEFAULT NULL, `status` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`student_id`), UNIQUE KEY `phone` (`phone`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `nv4_subjects` ( `subject_id` int(11) NOT NULL AUTO_INCREMENT, `subject_code` varchar(20) NOT NULL, `subject_name` varchar(100) NOT NULL, `description` text, `status` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`subject_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `nv4_rooms` ( `room_id` int(11) NOT NULL AUTO_INCREMENT, `room_code` varchar(20) NOT NULL, `room_name` varchar(100) NOT NULL, `description` text, `status` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`room_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `nv4_timetable` ( `timetable_id` int(11) NOT NULL AUTO_INCREMENT, `student_id` int(11) NOT NULL, `subject_id` int(11) NOT NULL, `room_id` int(11) NOT NULL, `teacher_name` varchar(100) NOT NULL, `day` tinyint(1) NOT NULL COMMENT '1-7 (Thứ 2-8)', `period` tinyint(1) NOT NULL COMMENT '1-5 (Tiết 1-2, 3-4, 5-6, 7-8, 9-10)', `status` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`timetable_id`), KEY `student_id` (`student_id`), KEY `subject_id` (`subject_id`), KEY `room_id` (`room_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;5. Cách cài đặt
- Tạo thư mục
modules/student_timetabletrong thư mục gốc của NukeViet - Đưa các file trên vào thư mục này
- Chạy file
install.sqlđể tạo cơ sở dữ liệu - Đăng nhập vào admin của NukeViet và kích hoạt mô-đun
6. Ghi chú
- Bạn cần điều chỉnh cấu trúc cơ sở dữ liệu theo nhu cầu cụ thể của bạn
- Đảm bảo các bảng có dữ liệu trước khi sử dụng mô-đun
- Có thể tùy chỉnh giao diện hiển thị thời khóa biểu theo ý muốn
- Đối với NukeViet 4.5, bạn có thể cần điều chỉnh một số phần để phù hợp với phiên bản cụ thể của bạn
Nếu bạn cần thêm chức năng nào đó hoặc có bất kỳ câu hỏi nào, hãy cho tôi biết!
- Tạo thư mục
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.