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

/phpBB/includes/acp/acp_ban.php

https://bitbucket.org/enitarzi/phpbb3-gorgon
PHP | 276 lines | 206 code | 46 blank | 24 comment | 24 complexity | db8b77e912aeec92b5f8a1b2e78c2264 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package acp
  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 acp
  19. */
  20. class acp_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, $phpbb_admin_path, $phpEx, $table_prefix;
  27. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  28. $bansubmit = (isset($_POST['bansubmit'])) ? true : false;
  29. $unbansubmit = (isset($_POST['unbansubmit'])) ? true : false;
  30. $current_time = time();
  31. $user->add_lang(array('acp/ban', 'acp/users'));
  32. $this->tpl_name = 'acp_ban';
  33. $form_key = 'acp_ban';
  34. add_form_key($form_key);
  35. if (($bansubmit || $unbansubmit) && !check_form_key($form_key))
  36. {
  37. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  38. }
  39. // Ban submitted?
  40. if ($bansubmit)
  41. {
  42. // Grab the list of entries
  43. $ban = utf8_normalize_nfc(request_var('ban', '', true));
  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. user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
  52. trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
  53. }
  54. }
  55. else if ($unbansubmit)
  56. {
  57. $ban = request_var('unban', array(''));
  58. if ($ban)
  59. {
  60. user_unban($mode, $ban);
  61. trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
  62. }
  63. }
  64. // Define language vars
  65. $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
  66. $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
  67. $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
  68. $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
  69. $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
  70. $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
  71. switch ($mode)
  72. {
  73. case 'user':
  74. $l_ban_cell = $user->lang['USERNAME'];
  75. break;
  76. case 'ip':
  77. $l_ban_cell = $user->lang['IP_HOSTNAME'];
  78. break;
  79. case 'email':
  80. $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
  81. break;
  82. }
  83. $this->display_ban_options($mode);
  84. $template->assign_vars(array(
  85. 'L_TITLE' => $this->page_title,
  86. 'L_EXPLAIN' => $l_ban_explain,
  87. 'L_UNBAN_TITLE' => $l_unban_title,
  88. 'L_UNBAN_EXPLAIN' => $l_unban_explain,
  89. 'L_BAN_CELL' => $l_ban_cell,
  90. 'L_BAN_EXCLUDE_EXPLAIN' => $l_ban_exclude_explain,
  91. 'L_NO_BAN_CELL' => $l_no_ban_cell,
  92. 'S_USERNAME_BAN' => ($mode == 'user') ? true : false,
  93. 'U_ACTION' => $this->u_action,
  94. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=acp_ban&amp;field=ban'),
  95. ));
  96. }
  97. /**
  98. * Display ban options
  99. */
  100. function display_ban_options($mode)
  101. {
  102. global $user, $db, $template;
  103. // Ban length options
  104. $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; ');
  105. $ban_end_options = '';
  106. foreach ($ban_end_text as $length => $text)
  107. {
  108. $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
  109. }
  110. switch ($mode)
  111. {
  112. case 'user':
  113. $field = 'username';
  114. $l_ban_cell = $user->lang['USERNAME'];
  115. $sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
  116. FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
  117. WHERE (b.ban_end >= ' . time() . '
  118. OR b.ban_end = 0)
  119. AND u.user_id = b.ban_userid
  120. ORDER BY u.username_clean ASC';
  121. break;
  122. case 'ip':
  123. $field = 'ban_ip';
  124. $l_ban_cell = $user->lang['IP_HOSTNAME'];
  125. $sql = 'SELECT *
  126. FROM ' . BANLIST_TABLE . '
  127. WHERE (ban_end >= ' . time() . "
  128. OR ban_end = 0)
  129. AND ban_ip <> ''
  130. ORDER BY ban_ip";
  131. break;
  132. case 'email':
  133. $field = 'ban_email';
  134. $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
  135. $sql = 'SELECT *
  136. FROM ' . BANLIST_TABLE . '
  137. WHERE (ban_end >= ' . time() . "
  138. OR ban_end = 0)
  139. AND ban_email <> ''
  140. ORDER BY ban_email";
  141. break;
  142. }
  143. $result = $db->sql_query($sql);
  144. $banned_options = $excluded_options = array();
  145. $ban_length = $ban_reasons = $ban_give_reasons = array();
  146. while ($row = $db->sql_fetchrow($result))
  147. {
  148. $option = '<option value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
  149. if ($row['ban_exclude'])
  150. {
  151. $excluded_options[] = $option;
  152. }
  153. else
  154. {
  155. $banned_options[] = $option;
  156. }
  157. $time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
  158. if ($time_length == 0)
  159. {
  160. // Banned permanently
  161. $ban_length[$row['ban_id']] = $user->lang['PERMANENT'];
  162. }
  163. else if (isset($ban_end_text[$time_length]))
  164. {
  165. // Banned for a given duration
  166. $ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DURATION'], $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
  167. }
  168. else
  169. {
  170. // Banned until given date
  171. $ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DATE'], $user->format_date($row['ban_end'], false, true));
  172. }
  173. $ban_reasons[$row['ban_id']] = $row['ban_reason'];
  174. $ban_give_reasons[$row['ban_id']] = $row['ban_give_reason'];
  175. }
  176. $db->sql_freeresult($result);
  177. if (sizeof($ban_length))
  178. {
  179. foreach ($ban_length as $ban_id => $length)
  180. {
  181. $template->assign_block_vars('ban_length', array(
  182. 'BAN_ID' => (int) $ban_id,
  183. 'LENGTH' => $length,
  184. 'A_LENGTH' => addslashes($length),
  185. ));
  186. }
  187. }
  188. if (sizeof($ban_reasons))
  189. {
  190. foreach ($ban_reasons as $ban_id => $reason)
  191. {
  192. $template->assign_block_vars('ban_reason', array(
  193. 'BAN_ID' => $ban_id,
  194. 'REASON' => $reason,
  195. 'A_REASON' => addslashes($reason),
  196. ));
  197. }
  198. }
  199. if (sizeof($ban_give_reasons))
  200. {
  201. foreach ($ban_give_reasons as $ban_id => $reason)
  202. {
  203. $template->assign_block_vars('ban_give_reason', array(
  204. 'BAN_ID' => $ban_id,
  205. 'REASON' => $reason,
  206. 'A_REASON' => addslashes($reason),
  207. ));
  208. }
  209. }
  210. $options = '';
  211. if ($excluded_options)
  212. {
  213. $options .= '<optgroup label="' . $user->lang['OPTIONS_EXCLUDED'] . '">';
  214. $options .= implode('', $excluded_options);
  215. $options .= '</optgroup>';
  216. }
  217. if ($banned_options)
  218. {
  219. $options .= '<optgroup label="' . $user->lang['OPTIONS_BANNED'] . '">';
  220. $options .= implode('', $banned_options);
  221. $options .= '</optgroup>';
  222. }
  223. $template->assign_vars(array(
  224. 'S_BAN_END_OPTIONS' => $ban_end_options,
  225. 'S_BANNED_OPTIONS' => ($banned_options || $excluded_options) ? true : false,
  226. 'BANNED_OPTIONS' => $options,
  227. ));
  228. }
  229. }
  230. ?>