6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
26 function main($id, $mode)
28 global $config, $db, $user, $auth, $template, $cache;
29 global $phpbb_root_path, $phpEx;
31 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
33 // Include the admin banning interface...
34 include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
36 $bansubmit = (isset($_POST['bansubmit'])) ? true : false;
37 $unbansubmit = (isset($_POST['unbansubmit'])) ? true : false;
38 $current_time = time();
40 $user->add_lang(array('acp/ban', 'acp/users'));
41 $this->tpl_name = 'mcp_ban';
46 // Grab the list of entries
47 $ban = request_var('ban', '', ($mode === 'user') ? true : false);
51 $ban = utf8_normalize_nfc($ban);
54 $ban_len = request_var('banlength', 0);
55 $ban_len_other = request_var('banlengthother', '');
56 $ban_exclude = request_var('banexclude', 0);
57 $ban_reason = utf8_normalize_nfc(request_var('banreason', '', true));
58 $ban_give_reason = utf8_normalize_nfc(request_var('bangivereason', '', true));
62 if (confirm_box(true))
64 user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
66 trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>');
70 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
74 'banlength' => $ban_len,
75 'banlengthother' => $ban_len_other,
76 'banexclude' => $ban_exclude,
77 'banreason' => $ban_reason,
78 'bangivereason' => $ban_give_reason)));
82 else if ($unbansubmit)
84 $ban = request_var('unban', array(''));
88 if (confirm_box(true))
90 user_unban($mode, $ban);
92 trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>');
96 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
98 'unbansubmit' => true,
104 // Ban length options
105 $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'] . ' -> ');
107 $ban_end_options = '';
108 foreach ($ban_end_text as $length => $text)
110 $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
113 // Define language vars
114 $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
116 $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
117 $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
118 $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
119 $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
120 $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
125 $l_ban_cell = $user->lang['USERNAME'];
129 $l_ban_cell = $user->lang['IP_HOSTNAME'];
133 $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
137 acp_ban::display_ban_options($mode);
139 $template->assign_vars(array(
140 'L_TITLE' => $this->page_title,
141 'L_EXPLAIN' => $l_ban_explain,
142 'L_UNBAN_TITLE' => $l_unban_title,
143 'L_UNBAN_EXPLAIN' => $l_unban_explain,
144 'L_BAN_CELL' => $l_ban_cell,
145 'L_BAN_EXCLUDE_EXPLAIN' => $l_ban_exclude_explain,
146 'L_NO_BAN_CELL' => $l_no_ban_cell,
148 'S_USERNAME_BAN' => ($mode == 'user') ? true : false,
150 'U_ACTION' => $this->u_action,
151 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_ban&field=ban'),
154 if ($mode === 'email' && !$auth->acl_get('a_user'))
159 // As a "service" we will check if any post id is specified and populate the username of the poster id if given
160 $post_id = request_var('p', 0);
161 $user_id = request_var('u', 0);
162 $username = $pre_fill = false;
164 if ($user_id && $user_id <> ANONYMOUS)
166 $sql = 'SELECT username, user_email, user_ip
167 FROM ' . USERS_TABLE . '
168 WHERE user_id = ' . $user_id;
169 $result = $db->sql_query($sql);
173 $pre_fill = (string) $db->sql_fetchfield('username');
177 $pre_fill = (string) $db->sql_fetchfield('user_ip');
181 $pre_fill = (string) $db->sql_fetchfield('user_email');
184 $db->sql_freeresult($result);
188 $post_info = get_post_data($post_id, 'm_ban');
190 if (sizeof($post_info) && !empty($post_info[$post_id]))
195 $pre_fill = $post_info[$post_id]['username'];
199 $pre_fill = $post_info[$post_id]['poster_ip'];
203 $pre_fill = $post_info[$post_id]['user_email'];
212 // left for legacy template compatibility
213 $template->assign_var('USERNAMES', $pre_fill);
214 $template->assign_var('BAN_QUANTIFIER', $pre_fill);