PageRenderTime 42ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/nukeviet/admin/modules/authors/suspend.php

http://nuke-viet.googlecode.com/
PHP | 324 lines | 275 code | 42 blank | 7 comment | 32 complexity | 4908f3333ee23b7992fc6ad543d8f714 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2012 VINADES.,JSC. All rights reserved
  6. * @Createdate 2-1-2010 21:21
  7. */
  8. if( ! defined( 'NV_IS_FILE_AUTHORS' ) ) die( 'Stop!!!' );
  9. if( ! defined( 'NV_IS_SPADMIN' ) )
  10. {
  11. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  12. die();
  13. }
  14. $admin_id = $nv_Request->get_int( 'admin_id', 'get', 0 );
  15. if( empty( $admin_id ) or $admin_id == $admin_info['admin_id'] )
  16. {
  17. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  18. die();
  19. }
  20. $sql = "SELECT * FROM `" . NV_AUTHORS_GLOBALTABLE . "` WHERE `admin_id`=" . intval( $admin_id );
  21. $result = $db->sql_query( $sql );
  22. $numrows = $db->sql_numrows( $result );
  23. if( empty( $numrows ) )
  24. {
  25. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  26. die();
  27. }
  28. $row = $db->sql_fetchrow( $result );
  29. if( $row['lev'] == 1 or ( ! defined( "NV_IS_GODADMIN" ) and $row['lev'] == 2 ) )
  30. {
  31. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  32. die();
  33. }
  34. $row_user = $db->sql_fetchrow( $db->sql_query( "SELECT * FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid`=" . $admin_id . "" ) );
  35. $susp_reason = array();
  36. $last_reason = array();
  37. if( ! empty( $row['susp_reason'] ) )
  38. {
  39. $susp_reason = unserialize( $row['susp_reason'] );
  40. $last_reason = ( ! empty( $susp_reason ) ) ? $susp_reason[0] : "";
  41. }
  42. $old_suspend = intval( $row['is_suspend'] );
  43. if( empty( $old_suspend ) )
  44. {
  45. $allow_change = true;
  46. }
  47. else
  48. {
  49. $allow_change = ( defined( "NV_IS_GODADMIN" ) ) ? true : ( ( defined( "NV_IS_SPADMIN" ) and $last_reason['start_admin'] == $admin_info['login'] and $global_config['spadmin_add_admin'] == 1 ) ? true : false );
  50. }
  51. $contents = array();
  52. $contents['change_suspend'] = array();
  53. if( $allow_change )
  54. {
  55. $new_suspend = ( $old_suspend ) ? 0 : 1;
  56. $error = "";
  57. if( $nv_Request->get_int( 'save', 'post', 0 ) )
  58. {
  59. $new_reason = ( ! empty( $new_suspend ) ) ? filter_text_input( 'new_reason', 'post', '', 1 ) : "";
  60. $sendmail = $nv_Request->get_int( 'sendmail', 'post', 0 );
  61. $clean_history = defined( "NV_IS_GODADMIN" ) ? $nv_Request->get_int( 'clean_history', 'post', 0 ) : 0;
  62. if( ! empty( $new_suspend ) and empty( $new_reason ) )
  63. {
  64. $error = sprintf( $lang_module['susp_reason_empty'], $row_user['username'] );
  65. }
  66. else
  67. {
  68. if( $new_suspend )
  69. {
  70. if( $clean_history )
  71. {
  72. $susp_reason = array();
  73. $susp_reason[] = array(
  74. 'starttime' => NV_CURRENTTIME,
  75. 'endtime' => 0,
  76. 'start_admin' => $admin_info['admin_id'],
  77. 'end_admin' => '',
  78. 'info' => $new_reason
  79. );
  80. }
  81. else
  82. {
  83. array_unshift( $susp_reason, array(
  84. 'starttime' => NV_CURRENTTIME,
  85. 'endtime' => 0,
  86. 'start_admin' => $admin_info['admin_id'],
  87. 'end_admin' => '',
  88. 'info' => $new_reason
  89. ) );
  90. }
  91. }
  92. else
  93. {
  94. if( $clean_history )
  95. {
  96. $susp_reason = array();
  97. }
  98. else
  99. {
  100. $susp_reason[0] = array(
  101. 'starttime' => $last_reason['starttime'],
  102. 'endtime' => NV_CURRENTTIME,
  103. 'start_admin' => $last_reason['start_admin'],
  104. 'end_admin' => $admin_info['admin_id'],
  105. 'info' => $last_reason['info']
  106. );
  107. }
  108. }
  109. $sql = "UPDATE `" . NV_AUTHORS_GLOBALTABLE . "` SET `edittime`=" . NV_CURRENTTIME . ", `is_suspend`=" . $new_suspend . ", `susp_reason`=" . $db->dbescape( serialize( $susp_reason ) ) . " WHERE `admin_id`=" . $admin_id;
  110. if( $db->sql_query( $sql ) )
  111. {
  112. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['suspend' . $new_suspend] . " ", " Username : " . $row_user['username'], $admin_info['userid'] );
  113. if( ! empty( $sendmail ) )
  114. {
  115. $title = sprintf( $lang_module['suspend_sendmail_title'], $global_config['site_name'] );
  116. $my_sig = ( ! empty( $admin_info['sig'] ) ) ? $admin_info['sig'] : "All the best";
  117. $my_mail = $admin_info['view_mail'] ? $admin_info['email'] : $global_config['site_email'];
  118. if( $new_suspend )
  119. {
  120. $message = sprintf( $lang_module['suspend_sendmail_mess1'], $global_config['site_name'], nv_date( "d/m/Y H:i", NV_CURRENTTIME ), $new_reason, $my_mail );
  121. }
  122. else
  123. {
  124. $message = sprintf( $lang_module['suspend_sendmail_mess0'], $global_config['site_name'], nv_date( "d/m/Y H:i", NV_CURRENTTIME ), $last_reason['info'] );
  125. }
  126. $message = trim( $message );
  127. $mess = $message;
  128. $mess .= "\r\n\r\n............................\r\n\r\n";
  129. $mess .= nv_EncString( $message );
  130. $mess = nv_nl2br( $mess, "<br />" );
  131. $xtpl = new XTemplate( "message.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/system" );
  132. $xtpl->assign( 'SITE_CHARSET', $global_config['site_charset'] );
  133. $xtpl->assign( 'SITE_NAME', $global_config['site_name'] );
  134. $xtpl->assign( 'SITE_SLOGAN', $global_config['site_description'] );
  135. $xtpl->assign( 'SITE_EMAIL', $global_config['site_email'] );
  136. $xtpl->assign( 'SITE_FONE', $global_config['site_phone'] );
  137. $xtpl->assign( 'SITE_URL', $global_config['site_url'] );
  138. $xtpl->assign( 'TITLE', $title );
  139. $xtpl->assign( 'CONTENT', $mess );
  140. $xtpl->assign( 'AUTHOR_SIG', $my_sig );
  141. $xtpl->assign( 'AUTHOR_NAME', $admin_info['username'] );
  142. $xtpl->assign( 'AUTHOR_POS', $admin_info['position'] );
  143. $xtpl->assign( 'AUTHOR_EMAIL', $my_mail );
  144. $xtpl->parse( 'main' );
  145. $content = $xtpl->text( 'main' );
  146. $from = array( $admin_info['username'], $my_mail );
  147. $to = $row_user['email'];
  148. $send = nv_sendmail( $from, $to, nv_EncString( $title ), $content );
  149. if( ! $send )
  150. {
  151. nv_info_die( $lang_global['error_info_caption'], $lang_global['site_info'], $lang_global['error_sendmail_admin'], 1 );
  152. }
  153. }
  154. }
  155. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=suspend&id=" . $id );
  156. }
  157. }
  158. else
  159. {
  160. $adminpass = $new_reason = "";
  161. $clean_history = $sendmail = 0;
  162. }
  163. $contents['change_suspend']['new_suspend_caption'] = ( ! empty( $error ) ) ? $error : $lang_module['chg_is_suspend' . $new_suspend];
  164. $contents['change_suspend']['new_suspend_is_error'] = ( ! empty( $error ) ) ? 1 : 0;
  165. $contents['change_suspend']['new_suspend_action'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=suspend&amp;admin_id=" . $admin_id;
  166. $contents['change_suspend']['sendmail'] = array( $lang_module['suspend_sendmail'], $sendmail );
  167. if( ! empty( $new_suspend ) )
  168. {
  169. $contents['change_suspend']['new_reason'] = array(
  170. $lang_module['suspend_reason'],
  171. $new_reason,
  172. 255 );
  173. }
  174. if( defined( "NV_IS_GODADMIN" ) )
  175. {
  176. if( ( $new_suspend and ! empty( $susp_reason ) ) or ( empty( $new_suspend ) and sizeof( $susp_reason ) >= 1 ) )
  177. {
  178. $contents['change_suspend']['clean_history'] = array( $lang_module['clean_history'], $clean_history );
  179. }
  180. }
  181. $contents['change_suspend']['submit'] = $lang_module['suspend' . $new_suspend];
  182. }
  183. if( empty( $susp_reason ) )
  184. {
  185. $contents['suspend_info'] = array( sprintf( $lang_module['suspend_info_empty'], $row_user['username'] ), array() );
  186. }
  187. else
  188. {
  189. $inf = array();
  190. $ads = array();
  191. foreach( $susp_reason as $vals )
  192. {
  193. $ads[] = $vals['start_admin'];
  194. if( ! empty( $vals['end_admin'] ) ) $ads[] = $vals['end_admin'];
  195. }
  196. $ads = array_unique( $ads );
  197. $ads = "'" . implode( "','", $ads ) . "'";
  198. $query2 = "SELECT `userid`, `username`, `full_name` FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` IN (" . $ads . ")";
  199. $result2 = $db->sql_query( $query2 );
  200. $ads = array();
  201. while( $row2 = $db->sql_fetchrow( $result2 ) )
  202. {
  203. $ads[$row2['userid']] = "<a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;admin_id=" . $row2['userid'] . "\">" . $row2['full_name'] . "</a>";
  204. }
  205. $db->sql_freeresult( $query2 );
  206. foreach( $susp_reason as $vals )
  207. {
  208. $start = sprintf( $lang_module['suspend_info'], nv_date( "d/m/Y H:i", $vals['starttime'] ), $ads[$vals['start_admin']] );
  209. $end = "";
  210. if( ! empty( $vals['endtime'] ) )
  211. {
  212. $end = sprintf( $lang_module['suspend_info'], nv_date( "d/m/Y H:i", $vals['endtime'] ), $ads[$vals['end_admin']] );
  213. }
  214. $inf[] = array(
  215. $start,
  216. $end,
  217. $vals['info']
  218. );
  219. }
  220. $contents['suspend_info'] = array(
  221. sprintf( $lang_module['suspend_info_yes'], $row_user['username'] ),
  222. $inf,
  223. $lang_module['suspend_start'],
  224. $lang_module['suspend_end'],
  225. $lang_module['suspend_reason']
  226. );
  227. }
  228. $page_title = sprintf( $lang_module['nv_admin_chg_suspend'], $row_user['username'] );
  229. // Parse content
  230. $xtpl = new XTemplate( "suspend.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  231. $xtpl->assign( 'SUSPEND_INFO', $contents['suspend_info'][0] );
  232. if( empty( $contents['suspend_info'][1] ) )
  233. {
  234. $xtpl->parse( 'suspend.suspend_info' );
  235. }
  236. else
  237. {
  238. $xtpl->assign( 'SUSPEND_INFO2', $contents['suspend_info'][2] );
  239. $xtpl->assign( 'SUSPEND_INFO3', $contents['suspend_info'][3] );
  240. $xtpl->assign( 'SUSPEND_INFO4', $contents['suspend_info'][4] );
  241. $a = 0;
  242. foreach( $contents['suspend_info'][1] as $value )
  243. {
  244. $xtpl->assign( 'CLASS', ( $a % 2 ) ? " class=\"second\"" : "" );
  245. $xtpl->assign( 'VALUE0', $value[0] );
  246. $xtpl->assign( 'VALUE1', $value[1] );
  247. $xtpl->assign( 'VALUE2', $value[2] );
  248. $xtpl->parse( 'suspend.suspend_info1.loop' );
  249. ++$a;
  250. }
  251. $xtpl->parse( 'suspend.suspend_info1' );
  252. }
  253. if( ! empty( $contents['change_suspend'] ) )
  254. {
  255. $class = ( $contents['change_suspend']['new_suspend_is_error'] ) ? " class=\"error\"" : "";
  256. $xtpl->assign( 'CLASS', ( $contents['change_suspend']['new_suspend_is_error'] ) ? " class=\"error\"" : "" );
  257. $xtpl->assign( 'NEW_SUSPEND_CAPTION', $contents['change_suspend']['new_suspend_caption'] );
  258. $xtpl->assign( 'ACTION', $contents['change_suspend']['new_suspend_action'] );
  259. if( ! empty( $contents['change_suspend']['new_reason'] ) )
  260. {
  261. $xtpl->assign( 'NEW_REASON0', $contents['change_suspend']['new_reason'][0] );
  262. $xtpl->assign( 'NEW_REASON1', $contents['change_suspend']['new_reason'][1] );
  263. $xtpl->assign( 'NEW_REASON2', $contents['change_suspend']['new_reason'][2] );
  264. $xtpl->parse( 'suspend.change_suspend.new_reason' );
  265. }
  266. $xtpl->assign( 'SENDMAIL', $contents['change_suspend']['sendmail'][0] );
  267. $xtpl->assign( 'CHECKED', $contents['change_suspend']['sendmail'][1] ? " checked=\"checked\"" : "" );
  268. if( ! empty( $contents['change_suspend']['clean_history'] ) )
  269. {
  270. $xtpl->assign( 'CLEAN_HISTORY', $contents['change_suspend']['clean_history'][0] );
  271. $xtpl->assign( 'CHECKED1', $contents['change_suspend']['clean_history'][1] ? " checked=\"checked\"" : "" );
  272. $xtpl->parse( 'suspend.change_suspend.clean_history' );
  273. }
  274. $xtpl->assign( 'SUBMIT', $contents['change_suspend']['submit'] );
  275. $xtpl->parse( 'suspend.change_suspend' );
  276. }
  277. $xtpl->parse( 'suspend' );
  278. $contents = $xtpl->text( 'suspend' );
  279. include ( NV_ROOTDIR . "/includes/header.php" );
  280. echo nv_admin_theme( $contents );
  281. include ( NV_ROOTDIR . "/includes/footer.php" );
  282. ?>