Skip to content

Commit 3d56a5f

Browse files
authored
Merge pull request #5 from phapdev/edit_create_class
edit and create new class
2 parents 89e3e3c + c5b11d6 commit 3d56a5f

File tree

5 files changed

+175
-2
lines changed

5 files changed

+175
-2
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
/**
4+
* Headbook Management System
5+
* @version 4.x
6+
* @author Group DNTU
7+
* @license GNU/GPL version 3
8+
* @see https://github.com/phapdev/manage_headbook.git The Manage headbook GitHub project
9+
*/
10+
11+
12+
if (!defined('NV_IS_FILE_ADMIN')) {
13+
exit('Stop!!!');
14+
}
15+
16+
$classid = $nv_Request->get_int('id', 'post,get');
17+
18+
$xtpl = new XTemplate('addclass.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
19+
$xtpl->assign('LANG', $lang_module);
20+
$xtpl->assign('GLANG', $lang_global);
21+
// day la chinh sua form
22+
if ($classid) {
23+
$page_title = $lang_module['edit_class'];
24+
$arrayteacher=[];
25+
$queryteacher = $db->query('SELECT * FROM nv4_users WHERE group_id = 2 ORDER BY last_name ASC');
26+
27+
while ($row = $queryteacher->fetch()) {
28+
$arrayteacher[$row['userid']] = $row;
29+
}
30+
31+
32+
$queryclass = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_class WHERE ma_lop = ' . $classid);
33+
34+
$class = $queryclass->fetch();
35+
36+
$selected = $class['ma_gvcn'];
37+
38+
if ($class) {
39+
$xtpl->assign('CLASS', $class);
40+
}
41+
if(!empty($arrayteacher)) {
42+
foreach ($arrayteacher as $value) {
43+
$value['key'] = $value['userid'];
44+
$value['title'] = $value['last_name'] . ' ' . $value['first_name'];
45+
$value['selected'] = $selected == $value['userid'] ? "selected" : "";
46+
47+
$xtpl->assign('DATA', $value);
48+
$xtpl->parse('addclass.loop');
49+
}
50+
}
51+
52+
$row = [];
53+
if ($nv_Request->isset_request('btnsubmit', 'post')) {
54+
55+
$row['ten_lop'] = nv_substr($nv_Request->get_title('ten_lop', 'post', ''), 0, 250);
56+
// truy vấn mã giáo viên
57+
$row['ma_gvcn'] = $nv_Request->get_int('ma_gvcn', 'post', '');
58+
$row['khoi'] = $nv_Request->get_int('khoi', 'post', '');
59+
60+
//Xu ly luu du lieu
61+
$_sql = 'UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_class
62+
SET ten_lop = :ten_lop, ma_gvcn = :ma_gvcn, khoi = :khoi WHERE ma_lop = '. $classid;
63+
$sth = $db->prepare($_sql);
64+
$sth->bindParam(':ten_lop', $row['ten_lop'], PDO::PARAM_STR);
65+
$sth->bindParam(':ma_gvcn', $row['ma_gvcn'], PDO::PARAM_STR);
66+
$sth->bindParam(':khoi', $row['khoi'], PDO::PARAM_STR);
67+
$exe = $sth->execute();
68+
69+
if ($exe) {
70+
nv_redirect_location(NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=class');
71+
}
72+
}
73+
74+
75+
}
76+
//day la add form moi
77+
else {
78+
$page_title = $lang_module['addclass'];
79+
$array=[];
80+
// Gọi csdl để lấy dữ liệu
81+
$queryteacher = $db->query('SELECT * FROM nv4_users WHERE group_id = 2 ORDER BY last_name ASC');
82+
// đổ dữ liệu
83+
$selected = 0;
84+
while ($row = $queryteacher->fetch()) {
85+
$array[$row['userid']] = $row;
86+
}
87+
88+
// hien thi du lieu
89+
if(!empty($array)) {
90+
foreach ($array as $value) {
91+
$value['key'] = $value['userid'];
92+
$value['title'] = $value['last_name'] . ' ' . $value['first_name'];
93+
94+
$xtpl->assign('DATA', $value);
95+
$xtpl->parse('addclass.loop');
96+
}
97+
}
98+
}
99+
100+
$row = [];
101+
if ($nv_Request->isset_request('btnsubmit', 'post')) {
102+
103+
$row['ten_lop'] = nv_substr($nv_Request->get_title('ten_lop', 'post', ''), 0, 250);
104+
// truy vấn mã giáo viên
105+
$row['ma_gvcn'] = $nv_Request->get_int('ma_gvcn', 'post', '');
106+
$row['khoi'] = $nv_Request->get_int('khoi', 'post', '');
107+
//Xu ly luu du lieu
108+
$sql;
109+
if ($classid) {
110+
$_sql = 'UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_class
111+
SET ten_lop = :ten_lop, ma_gvcn = :ma_gvcn, khoi = :khoi WHERE ma_lop = ' . $classid;
112+
} else {
113+
$_sql = 'INSERT INTO ' . NV_PREFIXLANG . '_' . $module_data . '_class (
114+
ten_lop, ma_gvcn, khoi) VALUES (:ten_lop, :ma_gvcn, :khoi)';
115+
}
116+
$sth = $db->prepare($_sql);
117+
$sth->bindParam(':ten_lop', $row['ten_lop'], PDO::PARAM_STR);
118+
$sth->bindParam(':ma_gvcn', $row['ma_gvcn'], PDO::PARAM_STR);
119+
$sth->bindParam(':khoi', $row['khoi'], PDO::PARAM_STR);
120+
$exe = $sth->execute();
121+
122+
if ($exe) {
123+
nv_redirect_location(NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=class');
124+
}
125+
}
126+
127+
128+
$xtpl->parse('addclass');
129+
$contents = $xtpl->text('addclass');
130+
131+
include NV_ROOTDIR . '/includes/header.php';
132+
echo nv_admin_theme($contents);
133+
include NV_ROOTDIR . '/includes/footer.php';

modules/manageheadbook/admin/class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
$queryteacher = $db->query('SELECT * FROM nv4_users WHERE userid = ' . $value['ma_gvcn'] );
4040
$rowteacher = $queryteacher->fetch();
4141

42-
$value['teacher'] = $rowteacher['first_name'] . ' ' . $rowteacher['last_name'];
42+
$value['ten_gvcn'] = $rowteacher['last_name'] . ' ' . $rowteacher['first_name'];
43+
4344
$xtpl->assign('DATA_CLASS', $value);
4445
$xtpl->parse('class.loop');
4546
}

modules/manageheadbook/language/admin_vi.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
$lang_module['list_student'] = 'Danh sách học sinh';
2828

2929
$lang_module['add_class'] = 'Thêm mới lớp';
30+
$lang_module['edit_class'] = 'Chỉnh sửa lớp';
3031
$lang_module['class_delete_unsuccess'] = 'Xóa lớp không thành công!';
32+
$lang_module['choose_teacher'] = 'Chọn giáo viên chủ nhiệm';
33+
34+
3135
// $lang_module['class'] = '';
3236

3337

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- BEGIN: addclass -->
2+
<form action="" method="post" class="form-inline">
3+
<div class="table-responsive">
4+
<table class="table table-striped table-bordered table-hover">
5+
<colgroup>
6+
<col style="width: 260px" />
7+
<col/>
8+
</colgroup>
9+
<tbody>
10+
<tr>
11+
<td>{LANG.class_name} <span class="red">*</span></td>
12+
<td><input class="form-control w400" name="ten_lop" value="{CLASS.ten_lop}"/></td>
13+
</tr>
14+
<tr>
15+
<td>{LANG.home_room_teacher} <span class="red">*</span></td>
16+
<td>
17+
<select class="form-control w200" name="ma_gvcn">
18+
<option value="0" {DATA.selected}>{LANG.choose_teacher}</option>
19+
<!-- BEGIN: loop -->
20+
<option value="{DATA.key}" {DATA.selected}>{DATA.title}</option>
21+
<!-- END: loop -->
22+
</select>
23+
</td>
24+
</tr>
25+
<tr>
26+
<td>{LANG.unit} <span class="red">*</span></td>
27+
<td><input class="form-control w400" name="khoi" value="{CLASS.khoi}"/></td>
28+
</tr>
29+
</tbody>
30+
</table>
31+
</div>
32+
<div class="text-center">
33+
<input class="btn btn-primary" type="submit" name="btnsubmit" value="{GLANG.save}">
34+
</div>
35+
<!-- END: addclass -->

themes/admin_default/modules/manageheadbook/class.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<tr>
1616
<td class="text-center">{DATA_CLASS.ma_lop}</td>
1717
<td>{DATA_CLASS.ten_lop}</td>
18-
<td>{DATA_CLASS.ma_gvcn}</td>
18+
<td>{DATA_CLASS.ten_gvcn}</td>
1919
<td>{DATA_CLASS.khoi}</td>
2020
<td class="text-center">
2121
<a href="{DATA_CLASS.url_studentlist}" class="btn btn-default btn-xs"><i class="fa fa-fw fa-list"></i>{LANG.list_student}</a>

0 commit comments

Comments
 (0)