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+ die ('Stop!!! ' );
13+ }
14+
15+
16+ // them nam hoc moi
17+ $ page_title = $ lang_module ['add_year_title ' ];
18+ $ row = [];
19+
20+ if ($ nv_Request ->isset_request ('btnsubmit ' , 'post ' )) {
21+
22+ $ thoi_gian_bat_dau = $ nv_Request ->get_string ('thoi_gian_bat_dau ' , 'post ' , '' );
23+ if (!empty ($ thoi_gian_bat_dau ) and !preg_match ("/^([0-9]{1,2}) \\/([0-9]{1,2})\/([0-9]{4})$/ " , $ thoi_gian_bat_dau ))
24+ $ thoi_gian_bat_dau = "" ;
25+ if (empty ($ thoi_gian_bat_dau )) {
26+ $ row ['thoi_gian_bat_dau ' ] = 0 ;
27+ } else {
28+ $ phour = date ('H ' );
29+ $ pmin = date ('i ' );
30+ unset($ m );
31+ preg_match ("/^([0-9]{1,2}) \\/([0-9]{1,2})\/([0-9]{4})$/ " , $ thoi_gian_bat_dau , $ m );
32+ $ row ['thoi_gian_bat_dau ' ] = mktime ($ phour , $ pmin , 0 , $ m [2 ], $ m [1 ], $ m [3 ]);
33+ }
34+
35+ $ thoi_gian_ket_thuc = $ nv_Request ->get_string ('thoi_gian_ket_thuc ' , 'post ' , '' );
36+ if (!empty ($ thoi_gian_ket_thuc ) and !preg_match ("/^([0-9]{1,2}) \\/([0-9]{1,2})\/([0-9]{4})$/ " , $ thoi_gian_ket_thuc ))
37+ $ thoi_gian_ket_thuc = "" ;
38+ if (empty ($ thoi_gian_ket_thuc )) {
39+ $ row ['thoi_gian_ket_thuc ' ] = 0 ;
40+ } else {
41+ $ phour = date ('H ' );
42+ $ pmin = date ('i ' );
43+ unset($ m );
44+ preg_match ("/^([0-9]{1,2}) \\/([0-9]{1,2})\/([0-9]{4})$/ " , $ thoi_gian_ket_thuc , $ m );
45+ $ row ['thoi_gian_ket_thuc ' ] = mktime ($ phour , $ pmin , 0 , $ m [2 ], $ m [1 ], $ m [3 ]);
46+ }
47+
48+ $ row ['tu_nam ' ] = $ nv_Request ->get_int ('tu_nam ' , 'post ' , '' );
49+ $ row ['den_nam ' ] = $ nv_Request ->get_int ('den_nam ' , 'post ' , '' );
50+
51+ //Xu ly luu du lieu
52+ $ _sql = 'INSERT INTO ' . NV_PREFIXLANG . '_ ' . $ module_data . '_school_year (
53+ tu_nam, den_nam, thoi_gian_bat_dau, thoi_gian_ket_thuc) VALUES (
54+ :tu_nam, :den_nam, :thoi_gian_bat_dau, :thoi_gian_ket_thuc) ' ;
55+ $ sth = $ db ->prepare ($ _sql );
56+ $ sth ->bindParam (':tu_nam ' , $ row ['tu_nam ' ], PDO ::PARAM_STR );
57+ $ sth ->bindParam (':den_nam ' , $ row ['den_nam ' ], PDO ::PARAM_STR );
58+ $ sth ->bindParam (':thoi_gian_bat_dau ' , $ row ['thoi_gian_bat_dau ' ], PDO ::PARAM_STR );
59+ $ sth ->bindParam (':thoi_gian_ket_thuc ' , $ row ['thoi_gian_ket_thuc ' ], PDO ::PARAM_STR );
60+ $ sth ->execute ();
61+
62+ // tiep tuc goi thang moi them vao de lay id
63+ $ query = $ db ->query ('SELECT * FROM ' . NV_PREFIXLANG . '_ ' . $ module_data . '_school_year WHERE tu_nam= ' . $ row ['tu_nam ' ] .' AND den_nam= ' . $ row ['den_nam ' ].' AND thoi_gian_bat_dau= ' . $ row ['thoi_gian_bat_dau ' ] .' AND thoi_gian_ket_thuc= ' . $ row ['thoi_gian_ket_thuc ' ]);
64+
65+ // đổ dữ liệu
66+ $ dataschoolyear = $ query ->fetch ();
67+
68+
69+ $ time_per_week = 86400 * 7 ;
70+ $ time_per_1day = 86400 ;
71+
72+ $ time_from_day = $ row ['thoi_gian_bat_dau ' ] ;
73+ $ time_to_day = $ row ['thoi_gian_ket_thuc ' ];
74+
75+ $ sum_time = 0 ;
76+
77+ if (date ('w ' ,$ time_from_day ) != 1 ) {
78+ for ($ i = 0 ; date ('w ' ,$ time_from_day ) != 1 ; ++$ i ) {
79+ $ time_from_day -= $ time_per_1day ;
80+ }
81+ }
82+
83+ $ _sqlweek = "INSERT INTO " . NV_PREFIXLANG . "_ " . $ module_data . "_week (ma_nam_hoc, tu_ngay, den_ngay, ten_tuan) VALUES " ;
84+ for ($ i = 0 ; $ sum_time <= $ time_to_day ; $ i ++) {
85+ $ sum_time = $ time_from_day + $ i * $ time_per_week + $ time_per_week - $ time_per_1day ;
86+ $ tu_ngay = $ time_from_day + $ i * $ time_per_week ;
87+ $ den_ngay = $ time_from_day + $ i * $ time_per_week + $ time_per_week - $ time_per_1day ;
88+ $ ten_tuan ='Tuần ' . ($ i +1 );
89+ if ($ sum_time > $ time_to_day )
90+ $ _sqlweek = $ _sqlweek . " ( " . $ dataschoolyear ['ma_nam_hoc ' ].", " .$ tu_ngay .", " .$ den_ngay .", ' " .$ ten_tuan ."'); " ;
91+ else
92+ $ _sqlweek = $ _sqlweek . " ( " . $ dataschoolyear ['ma_nam_hoc ' ].", " .$ tu_ngay .", " .$ den_ngay .", ' " .$ ten_tuan ."'), " ;
93+ }
94+ // die($_sqlweek);
95+ $ db ->query ($ _sqlweek );
96+
97+
98+ if ($ db ) {
99+ nv_redirect_location (NV_BASE_ADMINURL . 'index.php? ' . NV_LANG_VARIABLE . '= ' . NV_LANG_DATA . '& ' . NV_NAME_VARIABLE . '= ' . $ module_name . '& ' . NV_OP_VARIABLE . '=schoolyearlist ' );
100+ }
101+ }
102+
103+ $ xtpl = new XTemplate ('addyear.tpl ' , NV_ROOTDIR . '/themes/ ' . $ global_config ['module_theme ' ] . '/modules/ ' . $ module_file );
104+ $ xtpl ->assign ('LANG ' , $ lang_module );
105+ $ xtpl ->assign ('GLANG ' , $ lang_global );
106+
107+
108+
109+
110+ $ xtpl ->parse ('addyear ' );
111+ $ contents = $ xtpl ->text ('addyear ' );
112+
113+ include NV_ROOTDIR . '/includes/header.php ' ;
114+ echo nv_admin_theme ($ contents );
115+ include NV_ROOTDIR . '/includes/footer.php ' ;
0 commit comments