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

/modules/to-giac-tp/admin.functions.php

https://gitlab.com/hocviettut/to-giac-tp
PHP | 255 lines | 112 code | 34 blank | 109 comment | 16 complexity | a2fd3c25c7c1ba41389c601d10f2ba11 MD5 | raw file
  1. <?php
  2. /**
  3. * @Project NUKEVIET 4.x
  4. * @Author VINADES (contact@vinades.vn)
  5. * @Copyright (C) 2014 VINADES. All rights reserved
  6. * @License GNU/GPL version 2 or any later version
  7. * @Createdate Apr 20, 2010 10:47:41 AM
  8. */
  9. if( ! defined( 'NV_ADMIN' ) or ! defined( 'NV_MAINFILE' ) or ! defined( 'NV_IS_MODADMIN' ) ) die( 'Stop!!!' );
  10. /**
  11. * nv_getAllowed()
  12. *
  13. * @return
  14. */
  15. function nv_getAllowed()
  16. {
  17. global $module_data, $db, $admin_info, $lang_module;
  18. $contact_allowed = array(
  19. 'view' => array(),
  20. 'reply' => array(),
  21. 'obt' => array()
  22. );
  23. if( defined( 'NV_IS_SPADMIN' ) )
  24. {
  25. $contact_allowed['view'][0] = $lang_module['is_default'];
  26. $contact_allowed['reply'][0] =$lang_module['is_default'];
  27. $contact_allowed['obt'][0] = $lang_module['is_default'];
  28. }
  29. $sql = 'SELECT id,full_name,admins FROM ' . NV_PREFIXLANG . '_' . $module_data . '_department';
  30. $result = $db->query( $sql );
  31. while( $row = $result->fetch() )
  32. {
  33. $id = intval( $row['id'] );
  34. if( defined( 'NV_IS_SPADMIN' ) )
  35. {
  36. $contact_allowed['view'][$id] = $row['full_name'];
  37. $contact_allowed['reply'][$id] = $row['full_name'];
  38. }
  39. $admins = $row['admins'];
  40. $admins = array_map( 'trim', explode( ';', $admins ) );
  41. foreach( $admins as $a )
  42. {
  43. if( preg_match( '/^([0-9]+)\/([0-1]{1})\/([0-1]{1})\/([0-1]{1})$/i', $a ) )
  44. {
  45. $admins2 = array_map( 'intval', explode( '/', $a ) );
  46. if( $admins2[0] == $admin_info['admin_id'] )
  47. {
  48. if( $admins2[1] == 1 and ! isset( $contact_allowed['view'][$id] ) ) $contact_allowed['view'][$id] = $row['full_name'];
  49. if( $admins2[2] == 1 and ! isset( $contact_allowed['reply'][$id] ) ) $contact_allowed['reply'][$id] = $row['full_name'];
  50. if( $admins2[3] == 1 and ! isset( $contact_allowed['obt'][$id] ) ) $contact_allowed['obt'][$id] = $row['full_name'];
  51. }
  52. }
  53. }
  54. }
  55. return $contact_allowed;
  56. }
  57. /**
  58. * nv_fix_report_type()
  59. *
  60. * @return
  61. */
  62. function nv_fix_report_type()
  63. {
  64. global $db, $module_data;
  65. $sql = 'SELECT rid FROM ' . NV_PREFIXLANG . '_' . $module_data . '_report_type ORDER BY weight ASC';
  66. $weight = 0;
  67. $result = $db->query( $sql );
  68. while( $row = $result->fetch() )
  69. {
  70. ++$weight;
  71. $sql = 'UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_report_type SET weight=' . $weight . ' WHERE rid=' . intval( $row['rid'] );
  72. $db->query( $sql );
  73. }
  74. $result->closeCursor();
  75. }
  76. /**
  77. * nv_news_fix_block()
  78. *
  79. * @param mixed $rid
  80. * @param bool $repairtable
  81. * @return
  82. */
  83. // function nv_news_fix_block( $rid, $repairtable = true )
  84. // {
  85. // global $db, $module_data;
  86. // $rid = intval( $rid );
  87. // if( $rid > 0 )
  88. // {
  89. // $sql = 'SELECT id FROM ' . NV_PREFIXLANG . '_' . $module_data . '_block where rid=' . $rid . ' ORDER BY weight ASC';
  90. // $result = $db->query( $sql );
  91. // $weight = 0;
  92. // while( $row = $result->fetch() )
  93. // {
  94. // ++$weight;
  95. // if( $weight <= 100 )
  96. // {
  97. // $sql = 'UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_block SET weight=' . $weight . ' WHERE rid=' . $rid . ' AND id=' . $row['id'];
  98. // }
  99. // else
  100. // {
  101. // $sql = 'DELETE FROM ' . NV_PREFIXLANG . '_' . $module_data . '_block WHERE rid=' . $rid . ' AND id=' . $row['id'];
  102. // }
  103. // $db->query( $sql );
  104. // }
  105. // $result->closeCursor();
  106. // if( $repairtable )
  107. // {
  108. // $db->query( 'OPTIMIZE TABLE ' . NV_PREFIXLANG . '_' . $module_data . '_block' );
  109. // }
  110. // }
  111. // }
  112. /**
  113. * nv_show_report_cat_list()
  114. *
  115. * @return
  116. */
  117. function nv_show_report_cat_list()
  118. {
  119. global $db, $lang_module, $lang_global, $module_name, $module_data, $op, $module_file, $global_config, $module_info;
  120. $sql = 'SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_report_type ORDER BY weight ASC';
  121. $_array_report_type = $db->query( $sql )->fetchAll();
  122. $num = sizeof( $_array_report_type );
  123. if( $num > 0 )
  124. {
  125. $array_adddefault = array(
  126. $lang_global['no'],
  127. $lang_global['yes']
  128. );
  129. $xtpl = new XTemplate( 'reportcat_lists.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file );
  130. $xtpl->assign( 'LANG', $lang_module );
  131. $xtpl->assign( 'GLANG', $lang_global );
  132. foreach ( $_array_report_type as $row)
  133. {
  134. $numnews = $db->query( 'SELECT COUNT(*) FROM ' . NV_PREFIXLANG . '_' . $module_data . '_report_col where rid=' . $row['rid'] )->fetchColumn();
  135. $xtpl->assign( 'ROW', array(
  136. 'rid' => $row['rid'],
  137. 'title' => $row['title'],
  138. 'numnews' => $numnews,
  139. 'url_edit' => NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module_name . '&amp;' . NV_OP_VARIABLE . '=' . $op . '&amp;rid=' . $row['rid'] . '#edit'
  140. ) );
  141. for( $i = 1; $i <= $num; ++$i )
  142. {
  143. $xtpl->assign( 'WEIGHT', array(
  144. 'key' => $i,
  145. 'title' => $i,
  146. 'selected' => $i == $row['weight'] ? ' selected="selected"' : ''
  147. ) );
  148. $xtpl->parse( 'main.loop.weight' );
  149. }
  150. foreach( $array_adddefault as $key => $val )
  151. {
  152. $xtpl->assign( 'ADDDEFAULT', array(
  153. 'key' => $key,
  154. 'title' => $val,
  155. 'selected' => $key == $row['adddefault'] ? ' selected="selected"' : ''
  156. ) );
  157. $xtpl->parse( 'main.loop.adddefault' );
  158. }
  159. $xtpl->parse( 'main.loop' );
  160. }
  161. $xtpl->parse( 'main' );
  162. $contents = $xtpl->text( 'main' );
  163. }
  164. else
  165. {
  166. $contents = '&nbsp;';
  167. }
  168. return $contents;
  169. }
  170. /**
  171. * nv_show_block_list()
  172. *
  173. * @param mixed $rid
  174. * @return
  175. */
  176. // function nv_show_block_list( $rid )
  177. // {
  178. // global $db, $lang_module, $lang_global, $module_name, $module_data, $op, $global_array_cat, $module_file, $global_config;
  179. // $xtpl = new XTemplate( 'report_list.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file );
  180. // $xtpl->assign( 'LANG', $lang_module );
  181. // $xtpl->assign( 'GLANG', $lang_global );
  182. // $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  183. // $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  184. // $xtpl->assign( 'NV_OP_VARIABLE', NV_OP_VARIABLE );
  185. // $xtpl->assign( 'MODULE_NAME', $module_name );
  186. // $xtpl->assign( 'OP', $op );
  187. // $xtpl->assign( 'RID', $rid );
  188. // $global_array_cat[0] = array( 'alias' => 'Other' );
  189. // $sql = 'SELECT t1.id, t1.catid, t1.title, t1.alias, t2.weight FROM ' . NV_PREFIXLANG . '_' . $module_data . '_rows t1 INNER JOIN ' . NV_PREFIXLANG . '_' . $module_data . '_block t2 ON t1.id = t2.id WHERE t2.rid= ' . $rid . ' AND t1.status=1 ORDER BY t2.weight ASC';
  190. // $array_block = $db->query( $sql )->fetchAll();
  191. // $num = sizeof( $array_block );
  192. // if( $num > 0 )
  193. // {
  194. // foreach ($array_block as $row)
  195. // {
  196. // $xtpl->assign( 'ROW', array(
  197. // 'id' => $row['id'],
  198. // 'link' => NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module_name . '&amp;' . NV_OP_VARIABLE . '=' . $global_array_cat[$row['catid']]['alias'] . '/' . $row['alias'] . '-' . $row['id'] . $global_config['rewrite_exturl'],
  199. // 'title' => $row['title']
  200. // ) );
  201. // for( $i = 1; $i <= $num; ++$i )
  202. // {
  203. // $xtpl->assign( 'WEIGHT', array(
  204. // 'key' => $i,
  205. // 'title' => $i,
  206. // 'selected' => $i == $row['weight'] ? ' selected="selected"' : ''
  207. // ) );
  208. // $xtpl->parse( 'main.loop.weight' );
  209. // }
  210. // $xtpl->parse( 'main.loop' );
  211. // }
  212. // $xtpl->parse( 'main' );
  213. // $contents = $xtpl->text( 'main' );
  214. // }
  215. // else
  216. // {
  217. // $contents = '&nbsp;';
  218. // }
  219. // return $contents;
  220. // }
  221. define( 'NV_IS_FILE_ADMIN', true );