$auth-> to phpbb::$acl->
[phpbb.git] / phpBB / modules / mcp / mcp_ban.php
blobb9f6c3e6343743aa0711adec5c352695c4818169
1 <?php
2 /**
4 * @package mcp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * @package mcp
22 class mcp_ban
24 var $u_action;
26 function main($id, $mode)
28 include(PHPBB_ROOT_PATH . 'includes/functions_user.' . PHP_EXT);
30 // Include the admin banning interface...
31 include(PHPBB_ROOT_PATH . 'includes/acp/acp_ban.' . PHP_EXT);
33 $bansubmit = phpbb_request::is_set_post('bansubmit');
34 $unbansubmit = phpbb_request::is_set_post('unbansubmit');
35 $current_time = time();
37 phpbb::$user->add_lang(array('acp/ban', 'acp/users'));
38 $this->tpl_name = 'mcp_ban';
40 // Ban submitted?
41 if ($bansubmit)
43 // Grab the list of entries
44 $ban = request_var('ban', '', ($mode === 'user') ? true : false);
46 if ($mode === 'user')
48 $ban = utf8_normalize_nfc($ban);
51 $ban_len = request_var('banlength', 0);
52 $ban_len_other = request_var('banlengthother', '');
53 $ban_exclude = request_var('banexclude', 0);
54 $ban_reason = utf8_normalize_nfc(request_var('banreason', '', true));
55 $ban_give_reason = utf8_normalize_nfc(request_var('bangivereason', '', true));
57 if ($ban)
59 if (confirm_box(true))
61 user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
63 trigger_error(phpbb::$user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . phpbb::$user->lang['BACK_TO_PREV'] . '</a>');
65 else
67 confirm_box(false, phpbb::$user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
68 'mode' => $mode,
69 'ban' => $ban,
70 'bansubmit' => true,
71 'banlength' => $ban_len,
72 'banlengthother' => $ban_len_other,
73 'banexclude' => $ban_exclude,
74 'banreason' => $ban_reason,
75 'bangivereason' => $ban_give_reason)));
79 else if ($unbansubmit)
81 $ban = request_var('unban', array(''));
83 if ($ban)
85 if (confirm_box(true))
87 user_unban($mode, $ban);
89 trigger_error(phpbb::$user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . phpbb::$user->lang['BACK_TO_PREV'] . '</a>');
91 else
93 confirm_box(false, phpbb::$user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
94 'mode' => $mode,
95 'unbansubmit' => true,
96 'unban' => $ban)));
101 // Ban length options
102 $ban_end_text = array(0 => phpbb::$user->lang['PERMANENT'], 30 => phpbb::$user->lang['30_MINS'], 60 => phpbb::$user->lang['1_HOUR'], 360 => phpbb::$user->lang['6_HOURS'], 1440 => phpbb::$user->lang['1_DAY'], 10080 => phpbb::$user->lang['7_DAYS'], 20160 => phpbb::$user->lang['2_WEEKS'], 40320 => phpbb::$user->lang['1_MONTH'], -1 => phpbb::$user->lang['UNTIL'] . ' -&gt; ');
104 $ban_end_options = '';
105 foreach ($ban_end_text as $length => $text)
107 $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
110 // Define language vars
111 $this->page_title = phpbb::$user->lang[strtoupper($mode) . '_BAN'];
113 $l_ban_explain = phpbb::$user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
114 $l_ban_exclude_explain = phpbb::$user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
115 $l_unban_title = phpbb::$user->lang[strtoupper($mode) . '_UNBAN'];
116 $l_unban_explain = phpbb::$user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
117 $l_no_ban_cell = phpbb::$user->lang[strtoupper($mode) . '_NO_BANNED'];
119 switch ($mode)
121 case 'user':
122 $l_ban_cell = phpbb::$user->lang['USERNAME'];
123 break;
125 case 'ip':
126 $l_ban_cell = phpbb::$user->lang['IP_HOSTNAME'];
127 break;
129 case 'email':
130 $l_ban_cell = phpbb::$user->lang['EMAIL_ADDRESS'];
131 break;
134 acp_ban::display_ban_options($mode);
136 $template->assign_vars(array(
137 'L_TITLE' => $this->page_title,
138 'L_EXPLAIN' => $l_ban_explain,
139 'L_UNBAN_TITLE' => $l_unban_title,
140 'L_UNBAN_EXPLAIN' => $l_unban_explain,
141 'L_BAN_CELL' => $l_ban_cell,
142 'L_BAN_EXCLUDE_EXPLAIN' => $l_ban_exclude_explain,
143 'L_NO_BAN_CELL' => $l_no_ban_cell,
145 'S_USERNAME_BAN' => ($mode == 'user') ? true : false,
147 'U_ACTION' => $this->u_action,
148 'U_FIND_USERNAME' => append_sid('memberlist', 'mode=searchuser&amp;form=mcp_ban&amp;field=ban'),
151 if ($mode === 'email' && !phpbb::$acl->acl_get('a_user'))
153 return;
156 // As a "service" we will check if any post id is specified and populate the username of the poster id if given
157 $post_id = request_var('p', 0);
158 $user_id = request_var('u', 0);
159 $username = $pre_fill = false;
161 if ($user_id && $user_id <> ANONYMOUS)
163 $sql = 'SELECT username, user_email, user_ip
164 FROM ' . USERS_TABLE . '
165 WHERE user_id = ' . $user_id;
166 $result = $db->sql_query($sql);
167 switch ($mode)
169 case 'user':
170 $pre_fill = (string) $db->sql_fetchfield('username');
171 break;
173 case 'ip':
174 $pre_fill = (string) $db->sql_fetchfield('user_ip');
175 break;
177 case 'email':
178 $pre_fill = (string) $db->sql_fetchfield('user_email');
179 break;
181 $db->sql_freeresult($result);
183 else if ($post_id)
185 $post_info = get_post_data($post_id, 'm_ban');
187 if (sizeof($post_info) && !empty($post_info[$post_id]))
189 switch ($mode)
191 case 'user':
192 $pre_fill = $post_info[$post_id]['username'];
193 break;
195 case 'ip':
196 $pre_fill = $post_info[$post_id]['poster_ip'];
197 break;
199 case 'email':
200 $pre_fill = $post_info[$post_id]['user_email'];
201 break;
207 if ($pre_fill)
209 $template->assign_var('BAN_QUANTIFIER', $pre_fill);