PageRenderTime 22ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 247 lines | 206 code | 30 blank | 11 comment | 27 complexity | 7910e21154f31885c2c82aca9bf4e3a8 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 3-5-2010 8:49
  7. */
  8. if ( ! defined( 'NV_IS_FILE_MODULES' ) ) die( 'Stop!!!' );
  9. /**
  10. * nv_show_funcs()
  11. *
  12. * @return void
  13. */
  14. function nv_show_funcs ( )
  15. {
  16. global $db, $nv_Request, $lang_module, $client_info, $module_name, $global_config, $site_mods;
  17. $mod = filter_text_input( 'mod', 'get', '' );
  18. if ( empty( $mod ) or ! preg_match( $global_config['check_module'], $mod ) ) die();
  19. $query = "SELECT `module_file`, `custom_title`, `admin_file` FROM `" . NV_MODULES_TABLE . "` WHERE `title`=" . $db->dbescape( $mod );
  20. $result = $db->sql_query( $query );
  21. $numrows = $db->sql_numrows( $result );
  22. if ( $numrows != 1 ) die();
  23. $row = $db->sql_fetchrow( $result );
  24. $custom_title = $row['custom_title'];
  25. $module_file = $row['module_file'];
  26. $admin_file = ( file_exists( NV_ROOTDIR . "/modules/" . $module_file . "/admin.functions.php" ) and file_exists( NV_ROOTDIR . "/modules/" . $module_file . "/admin/main.php" ) ) ? 1 : 0;
  27. $is_delCache = false;
  28. if ( $admin_file != intval( $row['admin_file'] ) )
  29. {
  30. $sql = "UPDATE `" . NV_MODULES_TABLE . "` SET `admin_file`=" . $admin_file . " WHERE `title`=" . $db->dbescape( $mod );
  31. $db->sql_query( $sql );
  32. $is_delCache = true;
  33. }
  34. $local_funcs = nv_scandir( NV_ROOTDIR . '/modules/' . $module_file . '/funcs', $global_config['check_op_file'] );
  35. if ( ! empty( $local_funcs ) )
  36. {
  37. $local_funcs = preg_replace( $global_config['check_op_file'], "\\1", $local_funcs );
  38. $local_funcs = array_flip( $local_funcs );
  39. }
  40. $module_version = array();
  41. $version_file = NV_ROOTDIR . "/modules/" . $module_file . "/version.php";
  42. if ( file_exists( $version_file ) )
  43. {
  44. require_once ( $version_file );
  45. }
  46. if ( empty( $module_version ) )
  47. {
  48. $timestamp = NV_CURRENTTIME - date( 'Z', NV_CURRENTTIME );
  49. $module_version = array(
  50. "name" => $mod, //
  51. "modfuncs" => "main", //
  52. "is_sysmod" => 0, //
  53. "virtual" => 0, //
  54. "version" => "3.0.01", //
  55. "date" => date( 'D, j M Y H:i:s', $timestamp ) . ' GMT', //
  56. "author" => "", //
  57. "note" => ""
  58. );
  59. }
  60. $module_version['submenu'] = isset( $module_version['submenu'] ) ? trim( $module_version['submenu'] ) : "";
  61. $modfuncs = array_map( "trim", explode( ",", $module_version['modfuncs'] ) );
  62. $arr_in_submenu = array_map( "trim", explode( ",", $module_version['submenu'] ) );
  63. $data_funcs = array();
  64. $weight_list = array();
  65. $query = "SELECT * FROM `" . NV_MODFUNCS_TABLE . "` WHERE `in_module`=" . $db->dbescape( $mod ) . " ORDER BY `subweight` ASC";
  66. $result = $db->sql_query( $query );
  67. while ( $row = $db->sql_fetchrow( $result ) )
  68. {
  69. $func = $row['func_name'];
  70. $show_func = in_array( $func, $modfuncs ) ? 1 : 0;
  71. if ( $row['show_func'] != $show_func )
  72. {
  73. $row['show_func'] = $show_func;
  74. $sql = "UPDATE `" . NV_MODFUNCS_TABLE . "` SET `show_func`=" . $show_func . " WHERE `func_id`=" . $row['func_id'];
  75. $db->sql_query( $sql );
  76. $is_delCache = true;
  77. }
  78. $data_funcs[$func]['func_id'] = $row['func_id'];
  79. $data_funcs[$func]['layout'] = $row['layout'];
  80. $data_funcs[$func]['show_func'] = $row['show_func'];
  81. $data_funcs[$func]['func_custom_name'] = $row['func_custom_name'];
  82. $data_funcs[$func]['in_submenu'] = $row['in_submenu'];
  83. $data_funcs[$func]['subweight'] = $row['subweight'];
  84. if ( $show_func )
  85. {
  86. $weight_list[] = $row['subweight'];
  87. }
  88. }
  89. $act_funcs = array_intersect_key( $data_funcs, $local_funcs );
  90. $old_funcs = array_diff_key( $data_funcs, $local_funcs );
  91. $new_funcs = array_diff_key( $local_funcs, $data_funcs );
  92. $is_refresh = false;
  93. if ( ! empty( $old_funcs ) )
  94. {
  95. foreach ( $old_funcs as $func => $values )
  96. {
  97. $query = "DELETE FROM `" . NV_BLOCKS_TABLE . "_weight` WHERE `func_id` = " . $values['func_id'];
  98. $db->sql_query( $query );
  99. $query = "DELETE FROM `" . NV_MODFUNCS_TABLE . "` WHERE `func_id` = " . $values['func_id'];
  100. $db->sql_query( $query );
  101. $is_delCache = true;
  102. }
  103. $db->sql_query( "OPTIMIZE TABLE `" . NV_BLOCKS_TABLE . "_weight`" );
  104. $db->sql_query( "OPTIMIZE TABLE `" . NV_MODFUNCS_TABLE . "`" );
  105. $is_refresh = true;
  106. }
  107. if ( ! empty( $new_funcs ) )
  108. {
  109. $mod_theme = "default";
  110. if ( ! empty( $site_mods[$mod]['theme'] ) and file_exists( NV_ROOTDIR . '/themes/' . $site_mods[$mod]['theme'] . '/config.ini' ) )
  111. {
  112. $mod_theme = $site_mods[$mod]['theme'];
  113. }
  114. if ( ! empty( $global_config['site_theme'] ) and file_exists( NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/config.ini' ) )
  115. {
  116. $mod_theme = $global_config['site_theme'];
  117. }
  118. $xml = simplexml_load_file( NV_ROOTDIR . '/themes/' . $mod_theme . '/config.ini' );
  119. $layoutdefault = ( string )$xml->layoutdefault;
  120. foreach ( array_keys( $new_funcs ) as $func )
  121. {
  122. $show_func = in_array( $func, $modfuncs ) ? 1 : 0;
  123. $sql = "INSERT INTO `" . NV_MODFUNCS_TABLE . "` (`func_id`, `func_name`, `func_custom_name`, `in_module`, `show_func`, `in_submenu`, `subweight`, `layout`, `setting`) VALUES (NULL, " . $db->dbescape( $func ) . ", " . $db->dbescape( ucfirst( $func ) ) . ", " . $db->dbescape( $mod ) . ", " . $show_func . ", 0, 0, " . $db->dbescape( $layoutdefault ) . ", '')";
  124. $func_id = $db->sql_query_insert_id( $sql );
  125. nv_setup_block_module( $mod, $func_id );
  126. }
  127. $is_refresh = true;
  128. $is_delCache = true;
  129. }
  130. if ( $is_refresh )
  131. {
  132. nv_fix_subweight( $mod );
  133. $act_funcs = array();
  134. $weight_list = array();
  135. $query = "SELECT * FROM `" . NV_MODFUNCS_TABLE . "` WHERE `in_module`=" . $db->dbescape( $mod ) . " AND `show_func`='1' ORDER BY `subweight` ASC";
  136. $result = $db->sql_query( $query );
  137. while ( $row = $db->sql_fetchrow( $result ) )
  138. {
  139. $func = $row['func_name'];
  140. $act_funcs[$func]['func_id'] = $row['func_id'];
  141. $act_funcs[$func]['layout'] = $row['layout'];
  142. $act_funcs[$func]['show_func'] = $row['show_func'];
  143. $act_funcs[$func]['func_custom_name'] = $row['func_custom_name'];
  144. $act_funcs[$func]['in_submenu'] = $row['in_submenu'];
  145. $act_funcs[$func]['subweight'] = $row['subweight'];
  146. $weight_list[] = $row['subweight'];
  147. }
  148. }
  149. if ( $is_delCache )
  150. {
  151. nv_del_moduleCache( 'modules' );
  152. nv_del_moduleCache( 'themes' );
  153. }
  154. $contents = array();
  155. $contents['caption'] = sprintf( $lang_module['funcs_list'], $custom_title );
  156. $contents['thead'] = array(
  157. $lang_module['funcs_subweight'], $lang_module['funcs_in_submenu'], $lang_module['funcs_title'], $lang_module['custom_title'], $lang_module['funcs_layout']
  158. );
  159. $contents['weight_list'] = $weight_list;
  160. foreach ( $act_funcs as $funcs => $values )
  161. {
  162. if ( $values['show_func'] )
  163. {
  164. $func_id = $values['func_id'];
  165. $contents['rows'][$func_id]['weight'] = array(
  166. $values['subweight'], "nv_chang_func_weight(" . $func_id . ");"
  167. );
  168. $contents['rows'][$func_id]['name'] = array(
  169. $funcs, $values['func_custom_name'], "nv_change_custom_name(" . $values['func_id'] . ",'action');"
  170. );
  171. $contents['rows'][$func_id]['layout'] = array(
  172. $values['layout'], "nv_chang_func_layout(" . $func_id . ");"
  173. );
  174. $contents['rows'][$func_id]['in_submenu'] = array(
  175. $values['in_submenu'], "nv_chang_func_in_submenu(" . $func_id . ");"
  176. );
  177. $contents['rows'][$func_id]['disabled'] = ( in_array( $funcs, $arr_in_submenu ) ) ? "" : " disabled";
  178. }
  179. }
  180. include ( NV_ROOTDIR . "/includes/header.php" );
  181. echo aj_show_funcs_theme( $contents );
  182. include ( NV_ROOTDIR . "/includes/footer.php" );
  183. }
  184. if ( $nv_Request->isset_request( 'aj', 'get' ) )
  185. {
  186. if ( filter_text_input( 'aj', 'get' ) == 'show_funcs' )
  187. {
  188. nv_show_funcs();
  189. die();
  190. }
  191. }
  192. $mod = filter_text_input( 'mod', 'get', '' );
  193. if ( empty( $mod ) or ! preg_match( $global_config['check_module'], $mod ) )
  194. {
  195. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  196. die();
  197. }
  198. $query = "SELECT `custom_title` FROM `" . NV_MODULES_TABLE . "` WHERE `title`=" . $db->dbescape( $mod );
  199. $result = $db->sql_query( $query );
  200. $numrows = $db->sql_numrows( $result );
  201. if ( $numrows != 1 )
  202. {
  203. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  204. die();
  205. }
  206. $row = $db->sql_fetchrow( $result );
  207. $page_title = sprintf( $lang_module['funcs_list'], $row['custom_title'] );
  208. $contents = array();
  209. $contents['div_id'][0] = "show_funcs";
  210. $contents['div_id'][1] = "action";
  211. $contents['ajax'][0] = "nv_show_funcs('show_funcs');";
  212. $contents['ajax'][1] = $nv_Request->isset_request( 'func_id,pos', 'get' ) ? "nv_bl_list(" . $nv_Request->get_int( 'func_id', 'get' ) . ",'" . filter_text_input( 'pos', 'get' ) . "','action');" : "";
  213. $contents = show_funcs_theme( $contents );
  214. include ( NV_ROOTDIR . "/includes/header.php" );
  215. echo nv_admin_theme( $contents );
  216. include ( NV_ROOTDIR . "/includes/footer.php" );
  217. ?>