PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/01.Source/01.CORE/admincp/modules/authors/suspend.php

http://creative-portal.googlecode.com/
PHP | 297 lines | 264 code | 26 blank | 7 comment | 33 complexity | d80b5e7b2fd06c8b27804905f8dca93b MD5 | raw file
Possible License(s): BSD-3-Clause
  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-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. $query = "SELECT * FROM `" . NV_AUTHORS_GLOBALTABLE . "` WHERE `admin_id`=" . intval( $admin_id );
  21. $result = $db->sql_query( $query );
  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. $save = $nv_Request->get_int( 'save', 'post', 0 );
  57. $error = "";
  58. if ( $save )
  59. {
  60. $new_reason = ( ! empty( $new_suspend ) ) ? filter_text_input( 'new_reason', 'post', '', 1 ) : "";
  61. $sendmail = $nv_Request->get_int( 'sendmail', 'post', 0 );
  62. $clean_history = defined( "NV_IS_GODADMIN" ) ? $nv_Request->get_int( 'clean_history', 'post', 0 ) : 0;
  63. if ( ! empty( $new_suspend ) and empty( $new_reason ) )
  64. {
  65. $error = sprintf( $lang_module['susp_reason_empty'], $row_user['username'] );
  66. }
  67. else
  68. {
  69. if ( $new_suspend )
  70. {
  71. if ( $clean_history )
  72. {
  73. $susp_reason = array();
  74. $susp_reason[] = array(
  75. 'starttime' => NV_CURRENTTIME, 'endtime' => 0, 'start_admin' => $admin_info['admin_id'], 'end_admin' => '', 'info' => $new_reason
  76. );
  77. }
  78. else
  79. {
  80. array_unshift( $susp_reason, array(
  81. 'starttime' => NV_CURRENTTIME, 'endtime' => 0, 'start_admin' => $admin_info['admin_id'], 'end_admin' => '', 'info' => $new_reason
  82. ) );
  83. }
  84. }
  85. else
  86. {
  87. if ( $clean_history )
  88. {
  89. $susp_reason = array();
  90. }
  91. else
  92. {
  93. $susp_reason[0] = array(
  94. 'starttime' => $last_reason['starttime'], 'endtime' => NV_CURRENTTIME, 'start_admin' => $last_reason['start_admin'], 'end_admin' => $admin_info['admin_id'], 'info' => $last_reason['info']
  95. );
  96. }
  97. }
  98. $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;
  99. if ( $db->sql_query( $sql ) )
  100. {
  101. if ( ! empty( $sendmail ) )
  102. {
  103. $title = sprintf( $lang_module['suspend_sendmail_title'], $global_config['site_name'] );
  104. $my_sig = ( ! empty( $admin_info['sig'] ) ) ? $admin_info['sig'] : "All the best";
  105. $my_mail = $admin_info['view_mail'] ? $admin_info['email'] : $global_config['site_email'];
  106. if ( $new_suspend )
  107. {
  108. $message = sprintf( $lang_module['suspend_sendmail_mess1'], $global_config['site_name'], nv_date( "d/m/Y H:i", NV_CURRENTTIME ), $new_reason, $my_mail );
  109. }
  110. else
  111. {
  112. $message = sprintf( $lang_module['suspend_sendmail_mess0'], $global_config['site_name'], nv_date( "d/m/Y H:i", NV_CURRENTTIME ), $last_reason['info'] );
  113. }
  114. $message = trim( $message );
  115. $mess = $message;
  116. $mess .= "\r\n\r\n............................\r\n\r\n";
  117. $mess .= nv_EncString( $message );
  118. $mess = nv_nl2br( $mess, "<br />" );
  119. $xtpl = new XTemplate( "message.tpl", NV_ROOTDIR . "/themes/" . $global_config['admin_theme'] . "/system" );
  120. $xtpl->assign( 'SITE_CHARSET', $global_config['site_charset'] );
  121. $xtpl->assign( 'SITE_NAME', $global_config['site_name'] );
  122. $xtpl->assign( 'SITE_SLOGAN', $global_config['site_description'] );
  123. $xtpl->assign( 'SITE_EMAIL', $global_config['site_email'] );
  124. $xtpl->assign( 'SITE_FONE', $global_config['site_phone'] );
  125. $xtpl->assign( 'SITE_URL', $global_config['site_url'] );
  126. $xtpl->assign( 'TITLE', $title );
  127. $xtpl->assign( 'CONTENT', $mess );
  128. $xtpl->assign( 'AUTHOR_SIG', $my_sig );
  129. $xtpl->assign( 'AUTHOR_NAME', $admin_info['username'] );
  130. $xtpl->assign( 'AUTHOR_POS', $admin_info['position'] );
  131. $xtpl->assign( 'AUTHOR_EMAIL', $my_mail );
  132. $xtpl->parse( 'main' );
  133. $content = $xtpl->text( 'main' );
  134. $from = array(
  135. $admin_info['username'], $my_mail
  136. );
  137. $to = $row_user['email'];
  138. $send = nv_sendmail( $from, $to, nv_EncString( $title ), $content );
  139. if ( ! $send )
  140. {
  141. nv_info_die( $lang_global['error_info_caption'], $lang_global['site_info'], $lang_global['error_sendmail_admin'], 1 );
  142. }
  143. }
  144. }
  145. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=suspend&id=" . $id );
  146. }
  147. }
  148. else
  149. {
  150. $adminpass = $new_reason = "";
  151. $clean_history = $sendmail = 0;
  152. }
  153. $contents['change_suspend']['new_suspend_caption'] = ( ! empty( $error ) ) ? $error : $lang_module['chg_is_suspend' . $new_suspend];
  154. $contents['change_suspend']['new_suspend_is_error'] = ( ! empty( $error ) ) ? 1 : 0;
  155. $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;
  156. $contents['change_suspend']['sendmail'] = array(
  157. $lang_module['suspend_sendmail'], $sendmail
  158. );
  159. if ( ! empty( $new_suspend ) )
  160. {
  161. $contents['change_suspend']['new_reason'] = array(
  162. $lang_module['suspend_reason'], $new_reason, 255
  163. );
  164. }
  165. if ( defined( "NV_IS_GODADMIN" ) )
  166. {
  167. if ( ( $new_suspend and ! empty( $susp_reason ) ) or ( empty( $new_suspend ) and count( $susp_reason ) >= 1 ) )
  168. {
  169. $contents['change_suspend']['clean_history'] = array(
  170. $lang_module['clean_history'], $clean_history
  171. );
  172. }
  173. }
  174. $contents['change_suspend']['submit'] = $lang_module['suspend' . $new_suspend];
  175. }
  176. if ( empty( $susp_reason ) )
  177. {
  178. $contents['suspend_info'] = array(
  179. sprintf( $lang_module['suspend_info_empty'], $row_user['username'] ), array()
  180. );
  181. }
  182. else
  183. {
  184. $inf = array();
  185. $ads = array();
  186. foreach ( $susp_reason as $vals )
  187. {
  188. $ads[] = $vals['start_admin'];
  189. if ( ! empty( $vals['end_admin'] ) ) $ads[] = $vals['end_admin'];
  190. }
  191. $ads = array_unique( $ads );
  192. $ads = "'" . implode( "','", $ads ) . "'";
  193. $query2 = "SELECT `userid`, `username`, `full_name` FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` IN (" . $ads . ")";
  194. $result2 = $db->sql_query( $query2 );
  195. $ads = array();
  196. while ( $row2 = $db->sql_fetchrow( $result2 ) )
  197. {
  198. $ads[$row2['userid']] = "<a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;admin_id=" . $row2['userid'] . "\">" . $row2['full_name'] . "</a>";
  199. }
  200. $db->sql_freeresult( $query2 );
  201. foreach ( $susp_reason as $vals )
  202. {
  203. $start = sprintf( $lang_module['suspend_info'], nv_date( "d/m/Y H:i", $vals['starttime'] ), $ads[$vals['start_admin']] );
  204. $end = "";
  205. if ( ! empty( $vals['endtime'] ) )
  206. {
  207. $end = sprintf( $lang_module['suspend_info'], nv_date( "d/m/Y H:i", $vals['endtime'] ), $ads[$vals['end_admin']] );
  208. }
  209. $inf[] = array(
  210. $start, $end, $vals['info']
  211. );
  212. }
  213. $contents['suspend_info'] = array(
  214. sprintf( $lang_module['suspend_info_yes'], $row_user['username'] ), $inf, $lang_module['suspend_start'], $lang_module['suspend_end'], $lang_module['suspend_reason']
  215. );
  216. }
  217. $page_title = sprintf( $lang_module['nv_admin_chg_suspend'], $row_user['username'] );
  218. //parse content
  219. $xtpl = new XTemplate( "suspend.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/authors" );
  220. $xtpl->assign( 'SUSPEND_INFO', $contents['suspend_info'][0] );
  221. if ( empty( $contents['suspend_info'][1] ) )
  222. {
  223. $xtpl->parse( 'suspend.suspend_info' );
  224. }
  225. else
  226. {
  227. $xtpl->assign( 'SUSPEND_INFO2', $contents['suspend_info'][2] );
  228. $xtpl->assign( 'SUSPEND_INFO3', $contents['suspend_info'][3] );
  229. $xtpl->assign( 'SUSPEND_INFO4', $contents['suspend_info'][4] );
  230. $a = 0;
  231. foreach ( $contents['suspend_info'][1] as $value )
  232. {
  233. $xtpl->assign( 'CLASS', ( $a % 2 ) ? " class=\"second\"" : "" );
  234. $xtpl->assign( 'VALUE0', $value[0] );
  235. $xtpl->assign( 'VALUE1', $value[1] );
  236. $xtpl->assign( 'VALUE2', $value[2] );
  237. $xtpl->parse( 'suspend.suspend_info1.loop' );
  238. $a ++;
  239. }
  240. $xtpl->parse( 'suspend.suspend_info1' );
  241. }
  242. if ( ! empty( $contents['change_suspend'] ) )
  243. {
  244. $class = ( $contents['change_suspend']['new_suspend_is_error'] ) ? " class=\"error\"" : "";
  245. $xtpl->assign( 'CLASS', ( $contents['change_suspend']['new_suspend_is_error'] ) ? " class=\"error\"" : "" );
  246. $xtpl->assign( 'NEW_SUSPEND_CAPTION', $contents['change_suspend']['new_suspend_caption'] );
  247. $xtpl->assign( 'ACTION', $contents['change_suspend']['new_suspend_action'] );
  248. if ( ! empty( $contents['change_suspend']['new_reason'] ) )
  249. {
  250. $xtpl->assign( 'NEW_REASON0', $contents['change_suspend']['new_reason'][0] );
  251. $xtpl->assign( 'NEW_REASON1', $contents['change_suspend']['new_reason'][1] );
  252. $xtpl->assign( 'NEW_REASON2', $contents['change_suspend']['new_reason'][2] );
  253. $xtpl->parse( 'suspend.change_suspend.new_reason' );
  254. }
  255. $xtpl->assign( 'SENDMAIL', $contents['change_suspend']['sendmail'][0] );
  256. $xtpl->assign( 'CHECKED', $contents['change_suspend']['sendmail'][1] ? " checked=\"checked\"" : "" );
  257. if ( ! empty( $contents['change_suspend']['clean_history'] ) )
  258. {
  259. $xtpl->assign( 'CLEAN_HISTORY', $contents['change_suspend']['clean_history'][0] );
  260. $xtpl->assign( 'CHECKED1', $contents['change_suspend']['clean_history'][1] ? " checked=\"checked\"" : "" );
  261. $xtpl->parse( 'suspend.change_suspend.clean_history' );
  262. }
  263. $xtpl->assign( 'SUBMIT', $contents['change_suspend']['submit'] );
  264. $xtpl->parse( 'suspend.change_suspend' );
  265. }
  266. include ( NV_ROOTDIR . "/includes/header.php" );
  267. $xtpl->parse( 'suspend' );
  268. $contents = $xtpl->text( 'suspend' );
  269. echo nv_admin_theme( $contents );
  270. include ( NV_ROOTDIR . "/includes/footer.php" );
  271. ?>