PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 231 lines | 196 code | 29 blank | 6 comment | 28 complexity | 56690c0fd3ee75a4786a7c12d4c190e3 MD5 | raw file
  1. <?php
  2. /**
  3. * @Project NUKEVIET CMS 3.0
  4. * @Author VINADES (contact@vinades.vn)
  5. * @Copyright(C) 2010 VINADES. All rights reserved
  6. * @Createdate 04/05/2010
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $table_caption = $lang_module['list_module_title'];
  10. $asel = $nv_Request->get_int( 'asel', 'get', 0 );
  11. $asel = ( ( defined( "NV_IS_GODADMIN" ) or ( defined( "NV_IS_SPADMIN" ) and $global_config['spadmin_add_admin'] == 1 ) ) and ! empty( $asel ) ) ? "&amp;asel=1" : "";
  12. $sql = "FROM `" . NV_USERS_GLOBALTABLE . "`";
  13. $base_url = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel;
  14. $methods = array( //
  15. 'userid' => array(
  16. 'key' => 'userid', 'value' => $lang_module['search_id'], 'selected' => ''
  17. ), //
  18. 'username' => array(
  19. 'key' => 'username', 'value' => $lang_module['search_account'], 'selected' => ''
  20. ), //
  21. 'full_name' => array(
  22. 'key' => 'full_name', 'value' => $lang_module['search_name'], 'selected' => ''
  23. ), //
  24. 'email' => array(
  25. 'key' => 'email', 'value' => $lang_module['search_mail'], 'selected' => ''
  26. ) //
  27. );
  28. $method = $nv_Request->isset_request( 'method', 'post' ) ? $nv_Request->get_string( 'method', 'post', '' ) : ( $nv_Request->isset_request( 'method', 'get' ) ? urldecode( $nv_Request->get_string( 'method', 'get', '' ) ) : '' );
  29. $methodvalue = $nv_Request->isset_request( 'value', 'post' ) ? $nv_Request->get_string( 'value', 'post' ) : ( $nv_Request->isset_request( 'value', 'get' ) ? urldecode( $nv_Request->get_string( 'value', 'get', '' ) ) : '' );
  30. $orders = array(
  31. 'userid', 'username', 'full_name', 'email', 'regdate'
  32. );
  33. $orderby = $nv_Request->get_string( 'sortby', 'get', 'userid' );
  34. $ordertype = $nv_Request->get_string( 'sorttype', 'get', 'DESC' );
  35. if ( $ordertype != "ASC" ) $ordertype = "DESC";
  36. if ( ! empty( $method ) and isset( $methods[$method] ) and ! empty( $methodvalue ) )
  37. {
  38. $sql .= " WHERE `" . $method . "` LIKE '%" . $db->dblikeescape( $methodvalue ) . "%'";
  39. $base_url .= "&amp;method=" . urlencode( $method ) . "&amp;value=" . urlencode( $methodvalue );
  40. $methods[$method]['selected'] = " selected=\"selected\"";
  41. $table_caption = $lang_module['search_page_title'];
  42. }
  43. if ( ! empty( $orderby ) and in_array( $orderby, $orders ) )
  44. {
  45. $sql .= " ORDER BY `" . $orderby . "` " . $ordertype;
  46. $base_url .= "&amp;sortby=" . $orderby . "&amp;sorttype=" . $ordertype;
  47. }
  48. $page = $nv_Request->get_int( 'page', 'get', 0 );
  49. $per_page = 30;
  50. $sql2 = "SELECT SQL_CALC_FOUND_ROWS * " . $sql . " LIMIT " . $page . ", " . $per_page;
  51. $query2 = $db->sql_query( $sql2 );
  52. $result = $db->sql_query( "SELECT FOUND_ROWS()" );
  53. list( $all_page ) = $db->sql_fetchrow( $result );
  54. $users_list = array();
  55. $admin_in = array();
  56. while ( $row = $db->sql_fetchrow( $query2 ) )
  57. {
  58. $users_list[$row['userid']] = array( //
  59. 'userid' => ( int )$row['userid'], //
  60. 'username' => ( string )$row['username'], //
  61. 'full_name' => ( string )$row['full_name'], //
  62. 'email' => ( string )$row['email'], //
  63. 'regdate' => date( "d/m/Y H:i", $row['regdate'] ), //
  64. 'checked' => ( int )$row['active'] ? " checked=\"checked\"" : "", //
  65. 'disabled' => " onclick=\"nv_chang_status(" . $row['userid'] . ");\"", //
  66. 'is_edit' => true, //
  67. 'is_delete' => true, //
  68. 'level' => $lang_module['level0'], //
  69. 'is_admin' => false //
  70. );
  71. $admin_in[] = $row['userid'];
  72. }
  73. if ( $admin_in )
  74. {
  75. $admin_in = implode( ",", $admin_in );
  76. $sql = "SELECT `admin_id`, `lev` FROM `" . NV_AUTHORS_GLOBALTABLE . "` WHERE `admin_id` IN (" . $admin_in . ")";
  77. $query = $db->sql_query( $sql );
  78. while ( $row = $db->sql_fetchrow( $query ) )
  79. {
  80. $is_my = ( $admin_info['admin_id'] == $row['admin_id'] ) ? true : false;
  81. $superadmin = ( $row['lev'] == 1 or $row['lev'] == 2 ) ? true : false;
  82. $users_list[$row['admin_id']]['checked'] = " checked=\"checked\"";
  83. $users_list[$row['admin_id']]['disabled'] = " disabled=\"disabled\"";
  84. $users_list[$row['admin_id']]['is_edit'] = false;
  85. $users_list[$row['admin_id']]['is_delete'] = false;
  86. if ( $row['lev'] == 1 )
  87. {
  88. $users_list[$row['admin_id']]['level'] = $lang_module['level1'];
  89. $users_list[$row['admin_id']]['img'] = 'admin1';
  90. }
  91. elseif ( $row['lev'] == 2 )
  92. {
  93. $users_list[$row['admin_id']]['level'] = $lang_module['level2'];
  94. $users_list[$row['admin_id']]['img'] = 'admin2';
  95. }
  96. else
  97. {
  98. $users_list[$row['admin_id']]['level'] = $lang_module['level3'];
  99. $users_list[$row['admin_id']]['img'] = 'admin3';
  100. }
  101. $users_list[$row['admin_id']]['is_admin'] = true;
  102. if ( defined( 'NV_IS_GODADMIN' ) )
  103. {
  104. $users_list[$row['admin_id']]['is_edit'] = true;
  105. }
  106. elseif ( defined( 'NV_IS_SPADMIN' ) and ( $is_my or ! $superadmin ) )
  107. {
  108. $users_list[$row['admin_id']]['is_edit'] = true;
  109. }
  110. elseif ( $is_my )
  111. {
  112. $users_list[$row['admin_id']]['is_edit'] = true;
  113. }
  114. }
  115. }
  116. $generate_page = nv_generate_page( $base_url, $all_page, $per_page, $page );
  117. $head_tds = array();
  118. $head_tds['userid']['title'] = $lang_module['userid'];
  119. $head_tds['userid']['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=userid&amp;sorttype=ASC";
  120. $head_tds['username']['title'] = $lang_module['account'];
  121. $head_tds['username']['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=username&amp;sorttype=ASC";
  122. $head_tds['full_name']['title'] = $lang_module['name'];
  123. $head_tds['full_name']['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=full_name&amp;sorttype=ASC";
  124. $head_tds['email']['title'] = $lang_module['email'];
  125. $head_tds['email']['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=email&amp;sorttype=ASC";
  126. $head_tds['regdate']['title'] = $lang_module['register_date'];
  127. $head_tds['regdate']['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=regdate&amp;sorttype=ASC";
  128. foreach ( $orders as $order )
  129. {
  130. if ( $orderby == $order and $ordertype == 'ASC' )
  131. {
  132. $head_tds[$order]['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=" . $order . "&amp;sorttype=DESC";
  133. $head_tds[$order]['title'] .= " &darr;";
  134. }
  135. elseif ( $orderby == $order and $ordertype == 'DESC' )
  136. {
  137. $head_tds[$order]['href'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel . "&amp;sortby=" . $order . "&amp;sorttype=ASC";
  138. $head_tds[$order]['title'] .= " &uarr;";
  139. }
  140. }
  141. $xtpl = new XTemplate( "main.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  142. $xtpl->assign( 'LANG', $lang_module );
  143. $xtpl->assign( 'FORM_ACTION', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel );
  144. $xtpl->assign( 'SORTURL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . $asel );
  145. $xtpl->assign( 'SEARCH_VALUE', $methodvalue );
  146. $xtpl->assign( 'TABLE_CAPTION', $table_caption );
  147. if ( defined( 'NV_IS_USER_FORUM' ) )
  148. {
  149. $xtpl->parse( 'main.is_forum' );
  150. }
  151. foreach ( $methods as $m )
  152. {
  153. $xtpl->assign( 'METHODS', $m );
  154. $xtpl->parse( 'main.method' );
  155. }
  156. foreach ( $head_tds as $head_td )
  157. {
  158. $xtpl->assign( 'HEAD_TD', $head_td );
  159. $xtpl->parse( 'main.head_td' );
  160. }
  161. foreach ( $users_list as $u )
  162. {
  163. $xtpl->assign( 'CONTENT_TD', $u );
  164. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  165. $xtpl->assign( 'NV_ADMIN_THEME', $global_config['admin_theme'] );
  166. if ( $u['is_admin'] )
  167. {
  168. $xtpl->parse( 'main.xusers.is_admin' );
  169. }
  170. if ( ! empty( $asel ) )
  171. {
  172. if ( ! $u['is_admin'] )
  173. {
  174. $xtpl->assign( 'ASEL_URL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=authors&amp;" . NV_OP_VARIABLE . "=add&amp;userid=" . $u['userid'] );
  175. $xtpl->parse( 'main.xusers.asel' );
  176. }
  177. }
  178. elseif ( !defined( 'NV_IS_USER_FORUM' ) )
  179. {
  180. if ( $u['is_edit'] )
  181. {
  182. $xtpl->assign( 'EDIT_URL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=edit&amp;userid=" . $u['userid'] );
  183. $xtpl->parse( 'main.xusers.edit' );
  184. }
  185. if ( $u['is_delete'] )
  186. {
  187. $xtpl->parse( 'main.xusers.del' );
  188. }
  189. }
  190. $xtpl->parse( 'main.xusers' );
  191. }
  192. if ( ! empty( $generate_page ) )
  193. {
  194. $xtpl->assign( 'GENERATE_PAGE', $generate_page );
  195. $xtpl->parse( 'main.generate_page' );
  196. }
  197. $xtpl->parse( 'main' );
  198. $contents = $xtpl->text( 'main' );
  199. include ( NV_ROOTDIR . "/includes/header.php" );
  200. echo nv_admin_theme( $contents );
  201. include ( NV_ROOTDIR . "/includes/footer.php" );
  202. ?>