PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/mcp/mcp_ban.php

https://github.com/marcfuentes/dal2012_noestoysolo
PHP | 219 lines | 162 code | 36 blank | 21 comment | 22 complexity | 7f420416ba211496df88281ca4f8ab67 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @package mcp
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * @package mcp
  19. */
  20. class mcp_ban
  21. {
  22. var $u_action;
  23. function main($id, $mode)
  24. {
  25. global $config, $db, $user, $auth, $template, $cache;
  26. global $phpbb_root_path, $phpEx;
  27. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  28. // Include the admin banning interface...
  29. include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
  30. $bansubmit = (isset($_POST['bansubmit'])) ? true : false;
  31. $unbansubmit = (isset($_POST['unbansubmit'])) ? true : false;
  32. $current_time = time();
  33. $user->add_lang(array('acp/ban', 'acp/users'));
  34. $this->tpl_name = 'mcp_ban';
  35. // Ban submitted?
  36. if ($bansubmit)
  37. {
  38. // Grab the list of entries
  39. $ban = request_var('ban', '', ($mode === 'user') ? true : false);
  40. if ($mode === 'user')
  41. {
  42. $ban = utf8_normalize_nfc($ban);
  43. }
  44. $ban_len = request_var('banlength', 0);
  45. $ban_len_other = request_var('banlengthother', '');
  46. $ban_exclude = request_var('banexclude', 0);
  47. $ban_reason = utf8_normalize_nfc(request_var('banreason', '', true));
  48. $ban_give_reason = utf8_normalize_nfc(request_var('bangivereason', '', true));
  49. if ($ban)
  50. {
  51. if (confirm_box(true))
  52. {
  53. user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
  54. trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
  55. }
  56. else
  57. {
  58. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  59. 'mode' => $mode,
  60. 'ban' => $ban,
  61. 'bansubmit' => true,
  62. 'banlength' => $ban_len,
  63. 'banlengthother' => $ban_len_other,
  64. 'banexclude' => $ban_exclude,
  65. 'banreason' => $ban_reason,
  66. 'bangivereason' => $ban_give_reason)));
  67. }
  68. }
  69. }
  70. else if ($unbansubmit)
  71. {
  72. $ban = request_var('unban', array(''));
  73. if ($ban)
  74. {
  75. if (confirm_box(true))
  76. {
  77. user_unban($mode, $ban);
  78. trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
  79. }
  80. else
  81. {
  82. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  83. 'mode' => $mode,
  84. 'unbansubmit' => true,
  85. 'unban' => $ban)));
  86. }
  87. }
  88. }
  89. // Ban length options
  90. $ban_end_text = array(0 => $user->lang['PERMANENT'], 30 => $user->lang['30_MINS'], 60 => $user->lang['1_HOUR'], 360 => $user->lang['6_HOURS'], 1440 => $user->lang['1_DAY'], 10080 => $user->lang['7_DAYS'], 20160 => $user->lang['2_WEEKS'], 40320 => $user->lang['1_MONTH'], -1 => $user->lang['UNTIL'] . ' -&gt; ');
  91. $ban_end_options = '';
  92. foreach ($ban_end_text as $length => $text)
  93. {
  94. $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
  95. }
  96. // Define language vars
  97. $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
  98. $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
  99. $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
  100. $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
  101. $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
  102. $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
  103. switch ($mode)
  104. {
  105. case 'user':
  106. $l_ban_cell = $user->lang['USERNAME'];
  107. break;
  108. case 'ip':
  109. $l_ban_cell = $user->lang['IP_HOSTNAME'];
  110. break;
  111. case 'email':
  112. $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
  113. break;
  114. }
  115. acp_ban::display_ban_options($mode);
  116. $template->assign_vars(array(
  117. 'L_TITLE' => $this->page_title,
  118. 'L_EXPLAIN' => $l_ban_explain,
  119. 'L_UNBAN_TITLE' => $l_unban_title,
  120. 'L_UNBAN_EXPLAIN' => $l_unban_explain,
  121. 'L_BAN_CELL' => $l_ban_cell,
  122. 'L_BAN_EXCLUDE_EXPLAIN' => $l_ban_exclude_explain,
  123. 'L_NO_BAN_CELL' => $l_no_ban_cell,
  124. 'S_USERNAME_BAN' => ($mode == 'user') ? true : false,
  125. 'U_ACTION' => $this->u_action,
  126. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_ban&amp;field=ban'),
  127. ));
  128. if ($mode === 'email' && !$auth->acl_get('a_user'))
  129. {
  130. return;
  131. }
  132. // As a "service" we will check if any post id is specified and populate the username of the poster id if given
  133. $post_id = request_var('p', 0);
  134. $user_id = request_var('u', 0);
  135. $username = $pre_fill = false;
  136. if ($user_id && $user_id <> ANONYMOUS)
  137. {
  138. $sql = 'SELECT username, user_email, user_ip
  139. FROM ' . USERS_TABLE . '
  140. WHERE user_id = ' . $user_id;
  141. $result = $db->sql_query($sql);
  142. switch ($mode)
  143. {
  144. case 'user':
  145. $pre_fill = (string) $db->sql_fetchfield('username');
  146. break;
  147. case 'ip':
  148. $pre_fill = (string) $db->sql_fetchfield('user_ip');
  149. break;
  150. case 'email':
  151. $pre_fill = (string) $db->sql_fetchfield('user_email');
  152. break;
  153. }
  154. $db->sql_freeresult($result);
  155. }
  156. else if ($post_id)
  157. {
  158. $post_info = get_post_data($post_id, 'm_ban');
  159. if (sizeof($post_info) && !empty($post_info[$post_id]))
  160. {
  161. switch ($mode)
  162. {
  163. case 'user':
  164. $pre_fill = $post_info[$post_id]['username'];
  165. break;
  166. case 'ip':
  167. $pre_fill = $post_info[$post_id]['poster_ip'];
  168. break;
  169. case 'email':
  170. $pre_fill = $post_info[$post_id]['user_email'];
  171. break;
  172. }
  173. }
  174. }
  175. if ($pre_fill)
  176. {
  177. // left for legacy template compatibility
  178. $template->assign_var('USERNAMES', $pre_fill);
  179. $template->assign_var('BAN_QUANTIFIER', $pre_fill);
  180. }
  181. }
  182. }
  183. ?>