PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website trường trung học phổ thông PHP/lc1/modules/shops/admin/group.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 214 lines | 186 code | 19 blank | 9 comment | 28 complexity | 174da0747384721bdebc0243307eb7f7 MD5 | raw file
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 2-9-2010 14:43
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['group'];
  10. $table_name = $db_config['prefix'] . "_" . $module_data . "_group";
  11. $error = $admins = "";
  12. $savegroup = 0;
  13. $data = array();
  14. list( $data['groupid'], $data['parentid'], $data['title'], $data['alias'], $data['description'], $data['keywords'], $data['who_view'], $groups_view ) = array(
  15. 0, 0, "", "", "", "", 0, ""
  16. );
  17. $groups_list = nv_groups_list();
  18. $savegroup = $nv_Request->get_int( 'savegroup', 'post', 0 );
  19. if ( ! empty( $savegroup ) )
  20. {
  21. $field_lang = nv_file_table( $table_name );
  22. $data['groupid'] = $nv_Request->get_int( 'groupid', 'post', 0 );
  23. $data['parentid_old'] = $nv_Request->get_int( 'parentid_old', 'post', 0 );
  24. $data['parentid'] = $nv_Request->get_int( 'parentid', 'post', 0 );
  25. $data['title'] = filter_text_input( 'title', 'post', '', 1 );
  26. $data['keywords'] = filter_text_input( 'keywords', 'post', '', 1 );
  27. $data['alias'] = filter_text_input( 'alias', 'post', '' );
  28. $data['description'] = $nv_Request->get_string( 'description', 'post', '' );
  29. $data['description'] = nv_nl2br( nv_htmlspecialchars( strip_tags( $data['description'] ) ), '<br />' );
  30. $data['alias'] = ( $data['alias'] == "" ) ? change_alias( $data['title'] ) : change_alias( $data['alias'] );
  31. $data['who_view'] = $nv_Request->get_int( 'who_view', 'post', 0 );
  32. $groups_view = "";
  33. $data['groups'] = $nv_Request->get_typed_array( 'groups_view', 'post', 'int', array() );
  34. $groups = array_intersect( $data['groups'], array_keys( $groups_list ) );
  35. $groups_view = implode( ",", $data['groups'] );
  36. if ( $data['title'] == "" )
  37. {
  38. $error = $lang_module['error_group_name'];
  39. }
  40. list( $check_alias ) = $db->sql_fetchrow( $db->sql_query( "SELECT count(*) FROM " . $table_name . " WHERE groupid!=" . $data['groupid'] . " and `" . NV_LANG_DATA . "_alias`=" . $db->dbescape( $data['alias'] ) . "" ) );
  41. if ( $check_alias and $data['parentid'] > 0 )
  42. {
  43. list( $parentid_alias ) = $db->sql_fetchrow( $db->sql_query( "SELECT `" . NV_LANG_DATA . "_alias` FROM " . $table_name . " WHERE groupid=" . $data['parentid'] . "" ) );
  44. $data['alias'] = $parentid_alias . "-" . $data['alias'];
  45. }
  46. if ( $data['groupid'] == 0 and $data['title'] != "" and $error == "" )
  47. {
  48. $listfield = "";
  49. $listvalue = "";
  50. foreach ( $field_lang as $field_lang_i )
  51. {
  52. list( $flang, $fname ) = $field_lang_i;
  53. $listfield .= ", `" . $flang . "_" . $fname . "`";
  54. if ( $flang == NV_LANG_DATA )
  55. {
  56. $listvalue .= ", " . $db->dbescape( $data[$fname] );
  57. }
  58. else
  59. {
  60. $listvalue .= ", " . $db->dbescape( $data[$fname] );
  61. }
  62. }
  63. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM " . $table_name . " WHERE `parentid`=" . $db->dbescape( $data['parentid'] ) . "" ) );
  64. $weight = intval( $weight ) + 1;
  65. $viewgroup = "viewgroup_page_list";
  66. $subgroupid = "";
  67. $query = "INSERT INTO " . $table_name . " (`groupid`, `parentid`, `image`, `thumbnail`, `weight`, `order`, `lev`, `viewgroup`, `numsubgroup`, `subgroupid`, `inhome`, `numlinks`, `admins`, `add_time`, `edit_time`, `del_cache_time`, `who_view`, `groups_view` " . $listfield . " )
  68. VALUES (NULL, " . $db->dbescape( $data['parentid'] ) . ",' ',' '," . $db->dbescape( $weight ) . ", '0', '0', " . $db->dbescape( $viewgroup ) . ", '0', " . $db->dbescape( $subgroupid ) . ", '1', '4'," . $db->dbescape( $admins ) . ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + 26000000, " . $db->dbescape( $data['who_view'] ) . "," . $db->dbescape( $groups_view ) . $listvalue . " )";
  69. $newgroupid = intval( $db->sql_query_insert_id( $query ) );
  70. if ( $newgroupid > 0 )
  71. {
  72. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['add_group'] , $data['title'], $admin_info['userid'] );
  73. $db->sql_freeresult();
  74. nv_fix_group_order();
  75. nv_del_moduleCache( $module_name );
  76. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "" );
  77. die();
  78. }
  79. else
  80. {
  81. //$error = $query;
  82. $error = $lang_module['errorsave'];
  83. }
  84. }
  85. elseif ( $data['groupid'] > 0 and $data['title'] != "" and $error == "" )
  86. {
  87. $query = "UPDATE " . $table_name . " SET `parentid`=" . $db->dbescape( $data['parentid'] ) . ", `" . NV_LANG_DATA . "_title`=" . $db->dbescape( $data['title'] ) . ", `" . NV_LANG_DATA . "_alias` = " . $db->dbescape( $data['alias'] ) . ", `" . NV_LANG_DATA . "_description`=" . $db->dbescape( $data['description'] ) . ", `" . NV_LANG_DATA . "_keywords`= " . $db->dbescape( $data['keywords'] ) . ", `who_view`=" . $db->dbescape( $data['who_view'] ) . ", `groups_view`=" . $db->dbescape( $groups_view ) . ", `edit_time`=UNIX_TIMESTAMP( ) WHERE `groupid` =" . $data['groupid'] . "";
  88. $db->sql_query( $query );
  89. if ( $db->sql_affectedrows() > 0 )
  90. {
  91. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['edit_group'], $data['title'], $admin_info['userid'] );
  92. $db->sql_freeresult();
  93. if ( $data['parentid'] != $data['parentid_old'] )
  94. {
  95. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM " . $table_name . " WHERE `parentid`=" . $db->dbescape( $data['parentid'] ) . "" ) );
  96. $weight = intval( $weight ) + 1;
  97. $sql = "UPDATE " . $table_name . " SET `weight`=" . $weight . " WHERE `groupid`=" . intval( $data['groupid'] );
  98. $db->sql_query( $sql );
  99. nv_fix_group_order();
  100. }
  101. nv_del_moduleCache( $module_name );
  102. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "" );
  103. die();
  104. }
  105. else
  106. {
  107. $error = $lang_module['errorsave'];
  108. }
  109. $db->sql_freeresult();
  110. }
  111. else
  112. {
  113. //$error = $lang_module['error_name'];
  114. }
  115. }
  116. $data['parentid'] = $nv_Request->get_int( 'parentid', 'get,post', 0 );
  117. $contents = "<div id=\"module_show_list\">";
  118. $contents .= nv_show_group_list( $data['parentid'] );
  119. $contents .= "</div>\n";
  120. $data['groupid'] = $nv_Request->get_int( 'groupid', 'get', 0 );
  121. if ( $data['groupid'] > 0 )
  122. {
  123. list( $data['groupid'], $data['parentid'], $data['title'], $data['alias'], $data['description'], $data['keywords'], $data['who_view'], $data['groups_view'] ) = $db->sql_fetchrow( $db->sql_query( "SELECT `groupid`, `parentid`, `" . NV_LANG_DATA . "_title`, `" . NV_LANG_DATA . "_alias`, `" . NV_LANG_DATA . "_description`, `" . NV_LANG_DATA . "_keywords`, `who_view`, `groups_view` FROM " . $table_name . " where `groupid`=" . $data['groupid'] . "" ) );
  124. $caption = $lang_module['edit_group'];
  125. }
  126. else
  127. {
  128. $caption = $lang_module['add_group'];
  129. }
  130. $groups_view = explode( ",", $groups_view );
  131. $sql = "SELECT groupid, " . NV_LANG_DATA . "_title, lev FROM " . $table_name . " WHERE `groupid` !='" . $data['groupid'] . "' ORDER BY `order` ASC";
  132. $result = $db->sql_query( $sql );
  133. $array_group_list = array();
  134. $array_group_list[0] = array(
  135. '0', $lang_module['group_sub_sl']
  136. );
  137. while ( list( $groupid_i, $title_i, $lev_i ) = $db->sql_fetchrow( $result ) )
  138. {
  139. $xtitle_i = "";
  140. if ( $lev_i > 0 )
  141. {
  142. $xtitle_i .= "&nbsp;";
  143. for ( $i = 1; $i <= $lev_i; $i ++ )
  144. {
  145. $xtitle_i .= "---";
  146. }
  147. }
  148. $xtitle_i .= $title_i;
  149. $array_group_list[] = array(
  150. $groupid_i, $xtitle_i
  151. );
  152. }
  153. // * call theme tpl of product groupalogs */
  154. $xtpl = new XTemplate( "group_add.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  155. $xtpl->assign( 'LANG', $lang_module );
  156. $xtpl->assign( 'caption', $caption );
  157. $xtpl->assign( 'who_view', $lang_global['who_view'] );
  158. $xtpl->assign( 'groups_view', $lang_global['groups_view'] );
  159. $xtpl->assign( 'DATA', $data );
  160. if ( $error != "" )
  161. {
  162. $xtpl->assign( 'error', $error );
  163. $xtpl->parse( 'main.error' );
  164. }
  165. foreach ( $array_group_list as $rows_i )
  166. {
  167. $sl = ( $rows_i[0] == $data['parentid'] ) ? " selected=\"selected\"" : "";
  168. $xtpl->assign( 'pgroup_i', $rows_i[0] );
  169. $xtpl->assign( 'ptitle_i', $rows_i[1] );
  170. $xtpl->assign( 'pselect', $sl );
  171. $xtpl->parse( 'main.parent_loop' );
  172. }
  173. $contents_html = "";
  174. foreach ( $array_who_view as $k => $w )
  175. {
  176. $sl = ( $data['who_view'] == $k ) ? " selected=\"selected\"" : "";
  177. $contents_html .= " <option value=\"" . $k . "\" " . $sl . ">" . $w . "</option>\n";
  178. }
  179. $xtpl->assign( 'who_view_html', $contents_html );
  180. $visibility = ( $data['who_view'] == 3 ) ? "visibility:visible;display:block;" : "visibility:hidden;display:none;";
  181. $xtpl->assign( 'visibility', $visibility );
  182. $contents_html = "";
  183. foreach ( $groups_list as $group_id => $grtl )
  184. {
  185. $contents_html .= "<p><input name=\"groups_view[]\" type=\"checkbox\" value=\"" . $group_id . "\"";
  186. if ( in_array( $group_id, $groups_view ) ) $contents_html .= " checked=\"checked\"";
  187. $contents_html .= " />&nbsp;" . $grtl . "</p>\n";
  188. }
  189. $xtpl->assign( 'groups_list_html', $contents_html );
  190. $xtpl->parse( 'main' );
  191. $contents .= $xtpl->text( 'main' );
  192. include ( NV_ROOTDIR . "/includes/header.php" );
  193. echo nv_admin_theme( $contents );
  194. include ( NV_ROOTDIR . "/includes/footer.php" );
  195. ?>