Skip to content

Commit a30c3fb

Browse files
committed
edit and create new student
1 parent a273c6d commit a30c3fb

File tree

6 files changed

+351
-3
lines changed

6 files changed

+351
-3
lines changed

modules/manageheadbook/action_mysql.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
$sql_drop_module[] = 'DROP TABLE IF EXISTS ' . $db_config['prefix'] . '_' . $lang . '_' . $module_data . '_class;';
1919
$sql_drop_module[] = 'DROP TABLE IF EXISTS ' . $db_config['prefix'] . '_' . $lang . '_' . $module_data . '_subject;';
2020
$sql_drop_module[] = 'DROP TABLE IF EXISTS ' . $db_config['prefix'] . '_' . $lang . '_' . $module_data . '_student;';
21+
$sql_drop_module[] = 'DROP TABLE IF EXISTS ' . $db_config['prefix'] . '_' . $lang . '_' . $module_data . '_school_years;';
2122

2223
$sql_create_module = $sql_drop_module;
2324

@@ -57,3 +58,12 @@
5758
ten_mon_hoc varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
5859
PRIMARY KEY (ma_mon_hoc)
5960
) ENGINE=MyISAM";
61+
62+
$sql_create_module[] = "CREATE TABLE " . $db_config['prefix'] . "_" . $lang . "_" . $module_data . "_school_years (
63+
ma_nam_hoc int(11) NOT NULL AUTO_INCREMENT,
64+
tu_nam int(11) NOT NULL,
65+
den_nam int(11) NOT NULL,
66+
thoi_gian_bat_dau int(11) NOT NULL,
67+
thoi_gian_ket_thuc int(11) NOT NULL,
68+
PRIMARY KEY (ma_nam_hoc)
69+
) ENGINE=MyISAM;";

modules/manageheadbook/admin.functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
'delstudent',
2323
'subject',
2424
'addsubject',
25-
'delsubject'
26-
// 'addstudent',
25+
'delsubject',
26+
'addstudent'
2727
];
2828

2929
define('NV_IS_FILE_ADMIN', true);
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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+
if (!defined('NV_IS_FILE_ADMIN')) {
12+
exit('Stop!!!');
13+
}
14+
15+
if (!defined('NV_IS_FILE_ADMIN')) {
16+
die('Stop!!!');
17+
}
18+
19+
20+
$studentid = $nv_Request->get_int('studentid', 'post,get');
21+
22+
$xtpl = new XTemplate('addstudent.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
23+
$xtpl->assign('LANG', $lang_module);
24+
$xtpl->assign('GLANG', $lang_global);
25+
$xtpl->assign('NV_UPLOADS_DIR', NV_UPLOADS_DIR);
26+
$xtpl->assign('UPLOAD_CURRENT', NV_UPLOADS_DIR . '/' . $module_upload . '/' . date("Y_m"));
27+
$xtpl->assign('module_name', $module_name);
28+
29+
if ($studentid) {
30+
// chinh sua
31+
$page_title = $lang_module['edit_student'];
32+
33+
$querystudent = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_student WHERE ma_hoc_sinh = ' . $studentid);
34+
35+
$student = $querystudent->fetch();
36+
37+
$arrayclass=[];
38+
// Gọi csdl để lấy dữ liệu
39+
$queryclass = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_class');
40+
41+
42+
// đổ dữ liệu
43+
$selectedclass = $student['ma_lop'];
44+
while ($row = $queryclass->fetch()) {
45+
$arrayclass[$row['ma_lop']] = $row;
46+
}
47+
48+
// hien thi du lieu class drop down
49+
if(!empty($arrayclass)) {
50+
foreach ($arrayclass as $value) {
51+
$value['key'] = $value['ma_lop'];
52+
$value['title'] = $value['ten_lop'];
53+
$value['selected'] = $selectedclass == $value['ma_lop'] ? "selected" : "";
54+
55+
$xtpl->assign('DATA_CLASS', $value);
56+
$xtpl->parse('addstudent.loopclass');
57+
}
58+
}
59+
// hien thi du lieu sex drop down
60+
$selectedsex = $student['gioi_tinh'];
61+
for ($i = 0; $i <= 1; ++$i) {
62+
$value = [
63+
'key' => $i,
64+
'title' => $lang_module['sex' . $i],
65+
'selected' => $selectedsex == $lang_module['sex' . $i] ? ' selected="selected"' : ''
66+
];
67+
$xtpl->assign('DATA_SEX', $value);
68+
$xtpl->parse('addstudent.loopsex');
69+
}
70+
71+
//hien thi du lieu form con lai
72+
if($student) {
73+
$student['ngay_sinh'] = nv_date('d/m/Y', $student['ngay_sinh']);
74+
$xtpl->assign('DATA', $student);
75+
}
76+
77+
$row = [];
78+
if ($nv_Request->isset_request('btnsubmit', 'post')) {
79+
80+
$row['ho_ten'] = nv_substr($nv_Request->get_title('ho_ten', 'post', ''), 0, 250);
81+
// truy vấn mã giáo viên
82+
83+
$ngay_sinh = $nv_Request->get_string('ngay_sinh', 'post', '');
84+
if (!empty($ngay_sinh) and !preg_match("/^([0-9]{1,2})\\/([0-9]{1,2})\/([0-9]{4})$/", $ngay_sinh))
85+
$ngay_sinh = "";
86+
if (empty($ngay_sinh)) {
87+
$row['ngay_sinh'] = 0;
88+
} else {
89+
$phour = date('H');
90+
$pmin = date('i');
91+
unset($m);
92+
preg_match("/^([0-9]{1,2})\\/([0-9]{1,2})\/([0-9]{4})$/", $ngay_sinh, $m);
93+
$row['ngay_sinh'] = mktime($phour, $pmin, 0, $m[2], $m[1], $m[3]);
94+
}
95+
96+
if(!empty($arrayclass)) {
97+
98+
foreach ($arrayclass as $value) {
99+
$row['ma_lop'] = $nv_Request->get_int('class_' . $value['ma_lop'], 'post', '');
100+
}
101+
for ($i = 0; $i <= 1; ++$i) {
102+
$row['gioi_tinh'] = nv_substr($nv_Request->get_title('sex_' . $i, 'post', ''), 0, 250);
103+
}
104+
$row['gioi_tinh'] = $lang_module['sex' . $row['gioi_tinh']];
105+
}
106+
107+
$row['so_tiet_nghi'] = $nv_Request->get_int('so_tiet_nghi', 'post', '');
108+
$row['anh_dai_dien'] = nv_substr($nv_Request->get_title('anh_dai_dien', 'post', ''), 0, 250);
109+
$row['dia_chi'] = nv_substr($nv_Request->get_title('dia_chi', 'post', ''), 0, 250);
110+
111+
//Xu ly luu du lieu
112+
$_sql = 'UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_student SET ho_ten=:ho_ten, ngay_sinh=:ngay_sinh
113+
, gioi_tinh=:gioi_tinh, ma_lop=:ma_lop, dia_chi=:dia_chi, so_tiet_nghi=:so_tiet_nghi, anh_dai_dien=:anh_dai_dien WHERE ma_hoc_sinh=' . $studentid;
114+
$sth = $db->prepare($_sql);
115+
$sth->bindParam(':ho_ten', $row['ho_ten'], PDO::PARAM_STR);
116+
$sth->bindParam(':ngay_sinh', $row['ngay_sinh'], PDO::PARAM_STR);
117+
$sth->bindParam(':gioi_tinh', $row['gioi_tinh'], PDO::PARAM_STR);
118+
$sth->bindParam(':ma_lop', $row['ma_lop'], PDO::PARAM_STR);
119+
$sth->bindParam(':dia_chi', $row['dia_chi'], PDO::PARAM_STR);
120+
$sth->bindParam(':so_tiet_nghi', $row['so_tiet_nghi'], PDO::PARAM_STR);
121+
$sth->bindParam(':anh_dai_dien', $row['anh_dai_dien'], PDO::PARAM_STR);
122+
$exe = $sth->execute();
123+
124+
if ($exe) {
125+
nv_redirect_location(NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=student&classid=' . $row['ma_lop']);
126+
}
127+
}
128+
} else {
129+
// them moi
130+
$page_title = $lang_module['add_student'];
131+
132+
$arrayclass=[];
133+
// Gọi csdl để lấy dữ liệu
134+
$queryclass = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_class');
135+
136+
// đổ dữ liệu
137+
$i =0;
138+
$selectedclass;
139+
while ($row = $queryclass->fetch()) {
140+
$arrayclass[$row['ma_lop']] = $row;
141+
if($i ==0)
142+
{
143+
$selectedclass = $row['ma_lop'];
144+
}
145+
$i++;
146+
}
147+
148+
// hien thi du lieu class drop down
149+
if(!empty($arrayclass)) {
150+
foreach ($arrayclass as $value) {
151+
$value['key'] = $value['ma_lop'];
152+
$value['title'] = $value['ten_lop'];
153+
$value['selected'] = $selectedclass == $value['ma_lop'] ? "selected" : "";
154+
155+
$xtpl->assign('DATA_CLASS', $value);
156+
$xtpl->parse('addstudent.loopclass');
157+
}
158+
}
159+
// hien thi du lieu sex drop down
160+
$selectedsex = $lang_module['sex0'];
161+
for ($i = 0; $i <= 1; ++$i) {
162+
$value = [
163+
'key' => $i,
164+
'title' => $lang_module['sex' . $i],
165+
'selected' => $selectedsex == $lang_module['sex' . $i] ? ' selected="selected"' : ''
166+
];
167+
$xtpl->assign('DATA_SEX', $value);
168+
$xtpl->parse('addstudent.loopsex');
169+
}
170+
171+
$row = [];
172+
if ($nv_Request->isset_request('btnsubmit', 'post')) {
173+
174+
$row['ho_ten'] = nv_substr($nv_Request->get_title('ho_ten', 'post', ''), 0, 250);
175+
// truy vấn mã giáo viên
176+
177+
$ngay_sinh = $nv_Request->get_string('ngay_sinh', 'post', '');
178+
if (!empty($ngay_sinh) and !preg_match("/^([0-9]{1,2})\\/([0-9]{1,2})\/([0-9]{4})$/", $ngay_sinh))
179+
$ngay_sinh = "";
180+
if (empty($ngay_sinh)) {
181+
$row['ngay_sinh'] = 0;
182+
} else {
183+
$phour = date('H');
184+
$pmin = date('i');
185+
unset($m);
186+
preg_match("/^([0-9]{1,2})\\/([0-9]{1,2})\/([0-9]{4})$/", $ngay_sinh, $m);
187+
$row['ngay_sinh'] = mktime($phour, $pmin, 0, $m[2], $m[1], $m[3]);
188+
}
189+
190+
if(!empty($arrayclass)) {
191+
192+
foreach ($arrayclass as $value) {
193+
$row['ma_lop'] = $nv_Request->get_int('class_' . $value['ma_lop'], 'post', '');
194+
}
195+
for ($i = 0; $i <= 1; ++$i) {
196+
$row['gioi_tinh'] = nv_substr($nv_Request->get_title('sex_' . $i, 'post', ''), 0, 250);
197+
}
198+
$row['gioi_tinh'] = $lang_module['sex' . $row['gioi_tinh']];
199+
}
200+
201+
$row['so_tiet_nghi'] = $nv_Request->get_int('so_tiet_nghi', 'post', '');
202+
$row['anh_dai_dien'] = nv_substr($nv_Request->get_title('anh_dai_dien', 'post', ''), 0, 250);
203+
$row['dia_chi'] = nv_substr($nv_Request->get_title('dia_chi', 'post', ''), 0, 250);
204+
205+
//Xu ly luu du lieu
206+
$_sql = 'INSERT INTO ' . NV_PREFIXLANG . '_' . $module_data . '_student (
207+
ho_ten, ngay_sinh, gioi_tinh, ma_lop, dia_chi, so_tiet_nghi, anh_dai_dien) VALUES (
208+
:ho_ten, :ngay_sinh, :gioi_tinh, :ma_lop, :dia_chi, :so_tiet_nghi, :anh_dai_dien)';
209+
$sth = $db->prepare($_sql);
210+
$sth->bindParam(':ho_ten', $row['ho_ten'], PDO::PARAM_STR);
211+
$sth->bindParam(':ngay_sinh', $row['ngay_sinh'], PDO::PARAM_STR);
212+
$sth->bindParam(':gioi_tinh', $row['gioi_tinh'], PDO::PARAM_STR);
213+
$sth->bindParam(':ma_lop', $row['ma_lop'], PDO::PARAM_STR);
214+
$sth->bindParam(':dia_chi', $row['dia_chi'], PDO::PARAM_STR);
215+
$sth->bindParam(':so_tiet_nghi', $row['so_tiet_nghi'], PDO::PARAM_STR);
216+
$sth->bindParam(':anh_dai_dien', $row['anh_dai_dien'], PDO::PARAM_STR);
217+
$exe = $sth->execute();
218+
219+
if ($exe) {
220+
nv_redirect_location(NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=student&classid=' . $row['ma_lop']);
221+
}
222+
}
223+
224+
}
225+
226+
227+
$xtpl->parse('addstudent');
228+
$contents = $xtpl->text('addstudent');
229+
230+
231+
include NV_ROOTDIR . '/includes/header.php';
232+
echo nv_admin_theme($contents);
233+
include NV_ROOTDIR . '/includes/footer.php';

modules/manageheadbook/language/admin_vi.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
$lang_module['address'] = 'Địa chỉ';
4444

4545
$lang_module['add_student'] = 'Thêm mới học sinh';
46+
$lang_module['edit_student'] = 'Chỉnh sửa học sinh';
47+
48+
$lang_module['sex0'] = 'Nữ';
49+
$lang_module['sex1'] = 'Nam';
4650

4751

4852

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!-- BEGIN: addstudent -->
2+
<link rel="stylesheet" type="text/css" href="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/jquery-ui/jquery-ui.min.css">
3+
4+
<div id="edit">
5+
<!-- BEGIN: error -->
6+
<div class="alert alert-danger">
7+
{error}
8+
</div>
9+
<!-- END: error -->
10+
11+
<form action="" method="post">
12+
<table class="table table-striped table-bordered table-hover">
13+
<tbody>
14+
<tr>
15+
<td>{LANG.full_name} <span class="red">*</span></td>
16+
<td>
17+
<input class="form-control w400" name="ho_ten" type="text" value="{DATA.ho_ten}" maxlength="255" />
18+
</td>
19+
</tr>
20+
<tr class="form-inline">
21+
<td>{LANG.birthday} <span class="red">*</span></td>
22+
<td>
23+
<span class="text-middle">
24+
<input class="form-control" name="ngay_sinh" id="dayparty" value="{DATA.ngay_sinh}" style="width: 100px;" maxlength="10" type="text" />
25+
</span>
26+
</td>
27+
</tr>
28+
<tr class="form-inline">
29+
<td>{LANG.sex} <span class="red">*</span></td>
30+
<td>
31+
<select class="form-control w150" name="sex_{DATA_SEX.key}">
32+
<!-- BEGIN: loopsex -->
33+
<option value="{DATA_SEX.key}" {DATA_SEX.selected}>{DATA_SEX.title}</option>
34+
<!-- END: loopsex -->
35+
</select>
36+
</td>
37+
</tr>
38+
<tr class="form-inline">
39+
<td>{LANG.class} <span class="red">*</span></td>
40+
<td>
41+
<select class="form-control w100" name="class_{DATA_CLASS.key}">
42+
<!-- BEGIN: loopclass -->
43+
<option value="{DATA_CLASS.key}" {DATA_CLASS.selected}>{DATA_CLASS.title}</option>
44+
<!-- END: loopclass -->
45+
</select>
46+
</td>
47+
</tr>
48+
<tr>
49+
<td>{LANG.address} <span class="red">*</span></td>
50+
<td>
51+
<input class="form-control w400" name="dia_chi" type="text" value="{DATA.dia_chi}" maxlength="255" />
52+
</td>
53+
</tr>
54+
<tr>
55+
<td>{LANG.number_absent} <span class="red">*</span></td>
56+
<td>
57+
<input class="form-control w400" name="so_tiet_nghi" type="text" value="{DATA.so_tiet_nghi}" maxlength="255" />
58+
</td>
59+
</tr>
60+
<tr>
61+
<td>{LANG.avatar} <span class="red">*</span></td>
62+
<td>
63+
<input class="form-control w400 pull-left" style="margin-right: 5px" name="anh_dai_dien" id="anh_dai_dien" type="text" value="{DATA.anh_dai_dien}" maxlength="255" />
64+
<input type="button" class="btn btn-primary" value="Browse server" name="selectimg"/>
65+
</td>
66+
</tr>
67+
</tbody>
68+
</table>
69+
<div class="text-center">
70+
<input class="btn btn-primary" type="submit" name="btnsubmit" value="{LANG.save}">
71+
</div>
72+
</form>
73+
</div>
74+
<script type="text/javascript" src="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/jquery-ui/jquery-ui.min.js"></script>
75+
<script type="text/javascript" src="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/language/jquery.ui.datepicker-{NV_LANG_INTERFACE}.js"></script>
76+
<script type="text/javascript">
77+
//<![CDATA[
78+
var area = "anh_dai_dien";
79+
var path = "{NV_UPLOADS_DIR}/{module_name}";
80+
var currentpath = "{UPLOAD_CURRENT}";
81+
var type = "image";
82+
$("#birthday,#dayinto,#dayparty").datepicker({
83+
showOn : "both",
84+
dateFormat : "dd/mm/yy",
85+
changeMonth : true,
86+
changeYear : true,
87+
showOtherMonths : true,
88+
buttonImage : nv_base_siteurl + "assets/images/calendar.gif",
89+
buttonImageOnly : true,
90+
yearRange: "-90:+0"
91+
});
92+
$(document).ready(function() {
93+
$("input[name=selectimg]").click(function() {
94+
nv_open_browse(script_name + "?" + nv_name_variable + "=upload&popup=1&area=" + area + "&path=" + path + "&type=" + type + "&currentpath=" + currentpath, "NVImg", "850", "420", "resizable=no,scrollbars=no,toolbar=no,location=no,status=no");
95+
return false;
96+
});
97+
});
98+
//]]>
99+
</script>
100+
<!-- END: addstudent -->
101+
Footer

themes/admin_default/modules/manageheadbook/student.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<!-- BEGIN: loop -->
1919
<tr>
2020
<td>{DATA_STUDENT.stt}</td>
21-
<td class="text-center">{DATA_STUDENT.ho_ten}</td>
21+
<td>{DATA_STUDENT.ho_ten}</td>
2222
<td>{DATA_STUDENT.ngay_sinh}</td>
2323
<td>{DATA_STUDENT.gioi_tinh}</td>
2424
<td>{DATA_STUDENT.ten_lop}</td>

0 commit comments

Comments
 (0)