Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 1480 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| acp_users | |
0.00% |
0 / 1478 |
|
0.00% |
0 / 4 |
140250 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| main | |
0.00% |
0 / 1465 |
|
0.00% |
0 / 1 |
135056 | |||
| optionset | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| optionget | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * @ignore |
| 16 | */ |
| 17 | |
| 18 | use phpbb\controller\helper; |
| 19 | use phpbb\language\language; |
| 20 | use phpbb\messenger\method\messenger_interface; |
| 21 | |
| 22 | if (!defined('IN_PHPBB')) |
| 23 | { |
| 24 | exit; |
| 25 | } |
| 26 | |
| 27 | class acp_users |
| 28 | { |
| 29 | var $u_action; |
| 30 | var $p_master; |
| 31 | |
| 32 | function __construct($p_master) |
| 33 | { |
| 34 | $this->p_master = $p_master; |
| 35 | } |
| 36 | |
| 37 | function main($id, $mode) |
| 38 | { |
| 39 | global $config, $db, $user, $auth, $template; |
| 40 | global $phpbb_root_path, $phpbb_admin_path, $phpEx; |
| 41 | global $phpbb_dispatcher, $request; |
| 42 | global $phpbb_container, $phpbb_log; |
| 43 | |
| 44 | /** @var helper $controller_helper */ |
| 45 | $controller_helper = $phpbb_container->get('controller.helper'); |
| 46 | |
| 47 | /** @var language $language Language object */ |
| 48 | $language = $phpbb_container->get('language'); |
| 49 | |
| 50 | $user->add_lang(array('posting', 'ucp', 'acp/users')); |
| 51 | $this->tpl_name = 'acp_users'; |
| 52 | |
| 53 | $error = array(); |
| 54 | $username = $request->variable('username', '', true); |
| 55 | $user_id = $request->variable('u', 0); |
| 56 | $action = $request->variable('action', ''); |
| 57 | |
| 58 | // Get referer to redirect user to the appropriate page after delete action |
| 59 | $redirect = $request->variable('redirect', ''); |
| 60 | $redirect_tag = "redirect=$redirect"; |
| 61 | $redirect_url = append_sid("{$phpbb_admin_path}index.$phpEx", "i=$redirect"); |
| 62 | |
| 63 | $submit = (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false; |
| 64 | |
| 65 | $form_name = 'acp_users'; |
| 66 | add_form_key($form_name); |
| 67 | |
| 68 | // Whois (special case) |
| 69 | if ($action == 'whois') |
| 70 | { |
| 71 | if (!function_exists('user_get_id_name')) |
| 72 | { |
| 73 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 74 | } |
| 75 | |
| 76 | $this->page_title = 'WHOIS'; |
| 77 | $this->tpl_name = 'simple_body'; |
| 78 | |
| 79 | $user_ip = phpbb_ip_normalise($request->variable('user_ip', '')); |
| 80 | $domain = gethostbyaddr($user_ip); |
| 81 | $ipwhois = user_ipwhois($user_ip); |
| 82 | |
| 83 | $template->assign_vars(array( |
| 84 | 'MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), |
| 85 | 'MESSAGE_TEXT' => nl2br($ipwhois)) |
| 86 | ); |
| 87 | |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | // Show user selection mask |
| 92 | if (!$username && !$user_id) |
| 93 | { |
| 94 | $this->page_title = 'SELECT_USER'; |
| 95 | |
| 96 | $template->assign_vars(array( |
| 97 | 'U_ACTION' => $this->u_action, |
| 98 | 'ANONYMOUS_USER_ID' => ANONYMOUS, |
| 99 | |
| 100 | 'S_SELECT_USER' => true, |
| 101 | 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=select_user&field=username&select_single=true'), |
| 102 | )); |
| 103 | |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | if (!$user_id) |
| 108 | { |
| 109 | $sql = 'SELECT user_id |
| 110 | FROM ' . USERS_TABLE . " |
| 111 | WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; |
| 112 | $result = $db->sql_query($sql); |
| 113 | $user_id = (int) $db->sql_fetchfield('user_id'); |
| 114 | $db->sql_freeresult($result); |
| 115 | |
| 116 | if (!$user_id) |
| 117 | { |
| 118 | trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Generate content for all modes |
| 123 | $sql = 'SELECT u.*, s.* |
| 124 | FROM ' . USERS_TABLE . ' u |
| 125 | LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) |
| 126 | WHERE u.user_id = ' . $user_id . ' |
| 127 | ORDER BY s.session_time DESC'; |
| 128 | $result = $db->sql_query_limit($sql, 1); |
| 129 | $user_row = $db->sql_fetchrow($result); |
| 130 | $db->sql_freeresult($result); |
| 131 | |
| 132 | if (!$user_row) |
| 133 | { |
| 134 | trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); |
| 135 | } |
| 136 | |
| 137 | // Generate overall "header" for user admin |
| 138 | $s_form_options = ''; |
| 139 | |
| 140 | // Build modes dropdown list |
| 141 | $sql = 'SELECT module_mode, module_auth |
| 142 | FROM ' . MODULES_TABLE . " |
| 143 | WHERE module_basename = 'acp_users' |
| 144 | AND module_enabled = 1 |
| 145 | AND module_class = 'acp' |
| 146 | ORDER BY left_id, module_mode"; |
| 147 | $result = $db->sql_query($sql); |
| 148 | |
| 149 | $dropdown_modes = array(); |
| 150 | while ($row = $db->sql_fetchrow($result)) |
| 151 | { |
| 152 | if (!$this->p_master->module_auth_self($row['module_auth'])) |
| 153 | { |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | $dropdown_modes[$row['module_mode']] = true; |
| 158 | } |
| 159 | $db->sql_freeresult($result); |
| 160 | |
| 161 | foreach ($dropdown_modes as $module_mode => $null) |
| 162 | { |
| 163 | $selected = ($mode == $module_mode) ? ' selected="selected"' : ''; |
| 164 | $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>'; |
| 165 | } |
| 166 | |
| 167 | $template->assign_vars(array( |
| 168 | 'U_BACK' => (empty($redirect)) ? $this->u_action : $redirect_url, |
| 169 | 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&u=$user_id"), |
| 170 | 'U_ACTION' => $this->u_action . '&u=' . $user_id . ((empty($redirect)) ? '' : '&' . $redirect_tag), |
| 171 | 'S_FORM_OPTIONS' => $s_form_options, |
| 172 | 'MANAGED_USERNAME' => $user_row['username']) |
| 173 | ); |
| 174 | |
| 175 | // Prevent normal users/admins change/view founders if they are not a founder by themselves |
| 176 | if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) |
| 177 | { |
| 178 | trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING); |
| 179 | } |
| 180 | |
| 181 | $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode)); |
| 182 | |
| 183 | switch ($mode) |
| 184 | { |
| 185 | case 'overview': |
| 186 | |
| 187 | if (!function_exists('user_get_id_name')) |
| 188 | { |
| 189 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 190 | } |
| 191 | |
| 192 | $user->add_lang('acp/ban'); |
| 193 | |
| 194 | $delete = $request->variable('delete', 0); |
| 195 | $delete_type = $request->variable('delete_type', ''); |
| 196 | $ip = $request->variable('ip', 'ip'); |
| 197 | |
| 198 | /** |
| 199 | * Run code at beginning of ACP users overview |
| 200 | * |
| 201 | * @event core.acp_users_overview_before |
| 202 | * @var array user_row Current user data |
| 203 | * @var string mode Active module |
| 204 | * @var string action Module that should be run |
| 205 | * @var bool submit Do we display the form only |
| 206 | * or did the user press submit |
| 207 | * @var array error Array holding error messages |
| 208 | * @since 3.1.3-RC1 |
| 209 | */ |
| 210 | $vars = array('user_row', 'mode', 'action', 'submit', 'error'); |
| 211 | extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_before', compact($vars))); |
| 212 | |
| 213 | if ($submit) |
| 214 | { |
| 215 | if ($delete) |
| 216 | { |
| 217 | if (!$auth->acl_get('a_userdel')) |
| 218 | { |
| 219 | send_status_line(403, 'Forbidden'); |
| 220 | trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 221 | } |
| 222 | |
| 223 | // Check if the user wants to remove himself or the guest user account |
| 224 | if ($user_id == ANONYMOUS) |
| 225 | { |
| 226 | trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 227 | } |
| 228 | |
| 229 | // Founders can not be deleted. |
| 230 | if ($user_row['user_type'] == USER_FOUNDER) |
| 231 | { |
| 232 | trigger_error($user->lang['CANNOT_REMOVE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 233 | } |
| 234 | |
| 235 | if ($user_id == $user->data['user_id']) |
| 236 | { |
| 237 | trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 238 | } |
| 239 | |
| 240 | if ($delete_type) |
| 241 | { |
| 242 | if (confirm_box(true)) |
| 243 | { |
| 244 | user_delete($delete_type, $user_id, $user_row['username']); |
| 245 | |
| 246 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DELETED', false, array($user_row['username'])); |
| 247 | trigger_error($user->lang['USER_DELETED'] . adm_back_link( |
| 248 | (empty($redirect)) ? $this->u_action : $redirect_url |
| 249 | ) |
| 250 | ); |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | $delete_confirm_hidden_fields = array( |
| 255 | 'u' => $user_id, |
| 256 | 'i' => $id, |
| 257 | 'mode' => $mode, |
| 258 | 'action' => $action, |
| 259 | 'update' => true, |
| 260 | 'delete' => 1, |
| 261 | 'delete_type' => $delete_type, |
| 262 | ); |
| 263 | |
| 264 | // Checks if the redirection page is specified |
| 265 | if (!empty($redirect)) |
| 266 | { |
| 267 | $delete_confirm_hidden_fields['redirect'] = $redirect; |
| 268 | } |
| 269 | |
| 270 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($delete_confirm_hidden_fields)); |
| 271 | } |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // Handle quicktool actions |
| 280 | switch ($action) |
| 281 | { |
| 282 | case 'banuser': |
| 283 | case 'banemail': |
| 284 | case 'banip': |
| 285 | |
| 286 | if ($user_id == $user->data['user_id']) |
| 287 | { |
| 288 | trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 289 | } |
| 290 | |
| 291 | if ($user_id == ANONYMOUS) |
| 292 | { |
| 293 | trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 294 | } |
| 295 | |
| 296 | if ($user_row['user_type'] == USER_FOUNDER) |
| 297 | { |
| 298 | trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 299 | } |
| 300 | |
| 301 | if (!check_form_key($form_name)) |
| 302 | { |
| 303 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 304 | } |
| 305 | |
| 306 | $ban = array(); |
| 307 | |
| 308 | switch ($action) |
| 309 | { |
| 310 | case 'banuser': |
| 311 | $ban[] = $user_row['username']; |
| 312 | $reason = 'USER_ADMIN_BAN_NAME_REASON'; |
| 313 | break; |
| 314 | |
| 315 | case 'banemail': |
| 316 | $ban[] = $user_row['user_email']; |
| 317 | $reason = 'USER_ADMIN_BAN_EMAIL_REASON'; |
| 318 | break; |
| 319 | |
| 320 | case 'banip': |
| 321 | $ban[] = $user_row['user_ip']; |
| 322 | |
| 323 | $sql = 'SELECT DISTINCT poster_ip |
| 324 | FROM ' . POSTS_TABLE . " |
| 325 | WHERE poster_id = $user_id"; |
| 326 | $result = $db->sql_query($sql); |
| 327 | |
| 328 | while ($row = $db->sql_fetchrow($result)) |
| 329 | { |
| 330 | $ban[] = $row['poster_ip']; |
| 331 | } |
| 332 | $db->sql_freeresult($result); |
| 333 | |
| 334 | $reason = 'USER_ADMIN_BAN_IP_REASON'; |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | $ban_reason = $request->variable('ban_reason', $user->lang[$reason], true); |
| 339 | $ban_give_reason = $request->variable('ban_give_reason', '', true); |
| 340 | |
| 341 | // Log not used at the moment, we simply utilize the ban function. |
| 342 | $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason); |
| 343 | |
| 344 | trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 345 | |
| 346 | break; |
| 347 | |
| 348 | case 'reactivate': |
| 349 | |
| 350 | if ($user_id == $user->data['user_id']) |
| 351 | { |
| 352 | trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 353 | } |
| 354 | |
| 355 | if (!check_form_key($form_name)) |
| 356 | { |
| 357 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 358 | } |
| 359 | |
| 360 | if ($user_row['user_type'] == USER_FOUNDER) |
| 361 | { |
| 362 | trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 363 | } |
| 364 | |
| 365 | if ($user_row['user_type'] == USER_IGNORE) |
| 366 | { |
| 367 | trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 368 | } |
| 369 | |
| 370 | if ($config['email_enable']) |
| 371 | { |
| 372 | $server_url = generate_board_url(); |
| 373 | |
| 374 | $user_actkey = gen_rand_string(mt_rand(6, 10)); |
| 375 | $email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive'; |
| 376 | |
| 377 | if ($user_row['user_type'] == USER_NORMAL) |
| 378 | { |
| 379 | user_active_flip('deactivate', $user_id, INACTIVE_REMIND); |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | // Grabbing the last confirm key - we only send a reminder |
| 384 | $sql = 'SELECT user_actkey |
| 385 | FROM ' . USERS_TABLE . ' |
| 386 | WHERE user_id = ' . $user_id; |
| 387 | $result = $db->sql_query($sql); |
| 388 | $user_activation_key = (string) $db->sql_fetchfield('user_actkey'); |
| 389 | $db->sql_freeresult($result); |
| 390 | |
| 391 | $user_actkey = empty($user_activation_key) ? $user_actkey : $user_activation_key; |
| 392 | } |
| 393 | |
| 394 | // Always update actkey even if same and also update actkey expiration to 24 hours from now |
| 395 | $sql_ary = [ |
| 396 | 'user_actkey' => $user_actkey, |
| 397 | 'user_actkey_expiration' => $user::get_token_expiration(), |
| 398 | ]; |
| 399 | |
| 400 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 401 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 402 | WHERE user_id = ' . (int) $user_id; |
| 403 | $db->sql_query($sql); |
| 404 | |
| 405 | // Start sending email |
| 406 | $email_method = $phpbb_container->get('messenger.method.email'); |
| 407 | $email_method->set_use_queue(false); |
| 408 | $email_method->template($email_template, $user_row['user_lang']); |
| 409 | $email_method->set_addresses($user_row); |
| 410 | $email_method->anti_abuse_headers($config, $user); |
| 411 | $email_method->assign_vars([ |
| 412 | 'WELCOME_MSG' => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT), |
| 413 | 'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT), |
| 414 | 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey", |
| 415 | ]); |
| 416 | $email_method->send(); |
| 417 | |
| 418 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE', false, array($user_row['username'])); |
| 419 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE_USER', false, array( |
| 420 | 'reportee_id' => $user_id |
| 421 | )); |
| 422 | |
| 423 | trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 424 | } |
| 425 | |
| 426 | break; |
| 427 | |
| 428 | case 'active': |
| 429 | |
| 430 | if ($user_id == $user->data['user_id']) |
| 431 | { |
| 432 | // It is only deactivation since the user is already activated (else he would not have reached this page) |
| 433 | trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 434 | } |
| 435 | |
| 436 | if (!check_form_key($form_name)) |
| 437 | { |
| 438 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 439 | } |
| 440 | |
| 441 | if ($user_row['user_type'] == USER_FOUNDER) |
| 442 | { |
| 443 | trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 444 | } |
| 445 | |
| 446 | if ($user_row['user_type'] == USER_IGNORE) |
| 447 | { |
| 448 | trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 449 | } |
| 450 | |
| 451 | user_active_flip('flip', $user_id); |
| 452 | |
| 453 | if ($user_row['user_type'] == USER_INACTIVE) |
| 454 | { |
| 455 | if ($config['require_activation'] == USER_ACTIVATION_ADMIN) |
| 456 | { |
| 457 | /* @var $phpbb_notifications \phpbb\notification\manager */ |
| 458 | $phpbb_notifications = $phpbb_container->get('notification_manager'); |
| 459 | $phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']); |
| 460 | |
| 461 | $email_method = $phpbb_container->get('messenger.method.email'); |
| 462 | $email_method->set_use_queue(false); |
| 463 | $email_method->template('admin_welcome_activated', $user_row['user_lang']); |
| 464 | $email_method->set_addresses($user_row); |
| 465 | $email_method->anti_abuse_headers($config, $user); |
| 466 | $email_method->assign_vars([ |
| 467 | 'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT), |
| 468 | ]); |
| 469 | $email_method->send(); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | $message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED'; |
| 474 | $log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE'; |
| 475 | |
| 476 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log, false, array($user_row['username'])); |
| 477 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, $log . '_USER', false, array( |
| 478 | 'reportee_id' => $user_id |
| 479 | )); |
| 480 | |
| 481 | trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 482 | |
| 483 | break; |
| 484 | |
| 485 | case 'delsig': |
| 486 | |
| 487 | if (!check_form_key($form_name)) |
| 488 | { |
| 489 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 490 | } |
| 491 | |
| 492 | $sql_ary = array( |
| 493 | 'user_sig' => '', |
| 494 | 'user_sig_bbcode_uid' => '', |
| 495 | 'user_sig_bbcode_bitfield' => '' |
| 496 | ); |
| 497 | |
| 498 | $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " |
| 499 | WHERE user_id = $user_id"; |
| 500 | $db->sql_query($sql); |
| 501 | |
| 502 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG', false, array($user_row['username'])); |
| 503 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG_USER', false, array( |
| 504 | 'reportee_id' => $user_id |
| 505 | )); |
| 506 | |
| 507 | trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 508 | |
| 509 | break; |
| 510 | |
| 511 | case 'delavatar': |
| 512 | |
| 513 | if (!check_form_key($form_name)) |
| 514 | { |
| 515 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 516 | } |
| 517 | |
| 518 | // Delete old avatar if present |
| 519 | /* @var $phpbb_avatar_manager \phpbb\avatar\manager */ |
| 520 | $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); |
| 521 | $phpbb_avatar_manager->handle_avatar_delete($db, $user, $phpbb_avatar_manager->clean_row($user_row, 'user'), USERS_TABLE, 'user_'); |
| 522 | |
| 523 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR', false, array($user_row['username'])); |
| 524 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR_USER', false, array( |
| 525 | 'reportee_id' => $user_id |
| 526 | )); |
| 527 | |
| 528 | trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 529 | break; |
| 530 | |
| 531 | case 'delposts': |
| 532 | |
| 533 | if (confirm_box(true)) |
| 534 | { |
| 535 | // Delete posts, attachments, etc. |
| 536 | delete_posts('poster_id', $user_id); |
| 537 | |
| 538 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_POSTS', false, array($user_row['username'])); |
| 539 | trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 544 | 'u' => $user_id, |
| 545 | 'i' => $id, |
| 546 | 'mode' => $mode, |
| 547 | 'action' => $action, |
| 548 | 'update' => true)) |
| 549 | ); |
| 550 | } |
| 551 | |
| 552 | break; |
| 553 | |
| 554 | case 'delattach': |
| 555 | |
| 556 | if (confirm_box(true)) |
| 557 | { |
| 558 | /** @var \phpbb\attachment\manager $attachment_manager */ |
| 559 | $attachment_manager = $phpbb_container->get('attachment.manager'); |
| 560 | $attachment_manager->delete('user', $user_id); |
| 561 | unset($attachment_manager); |
| 562 | |
| 563 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_ATTACH', false, array($user_row['username'])); |
| 564 | trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 569 | 'u' => $user_id, |
| 570 | 'i' => $id, |
| 571 | 'mode' => $mode, |
| 572 | 'action' => $action, |
| 573 | 'update' => true)) |
| 574 | ); |
| 575 | } |
| 576 | |
| 577 | break; |
| 578 | |
| 579 | case 'deloutbox': |
| 580 | |
| 581 | if (confirm_box(true)) |
| 582 | { |
| 583 | $msg_ids = array(); |
| 584 | $lang = 'EMPTY'; |
| 585 | |
| 586 | $sql = 'SELECT msg_id |
| 587 | FROM ' . PRIVMSGS_TO_TABLE . " |
| 588 | WHERE author_id = $user_id |
| 589 | AND folder_id = " . PRIVMSGS_OUTBOX; |
| 590 | $result = $db->sql_query($sql); |
| 591 | |
| 592 | if ($row = $db->sql_fetchrow($result)) |
| 593 | { |
| 594 | if (!function_exists('delete_pm')) |
| 595 | { |
| 596 | include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx); |
| 597 | } |
| 598 | |
| 599 | do |
| 600 | { |
| 601 | $msg_ids[] = (int) $row['msg_id']; |
| 602 | } |
| 603 | while ($row = $db->sql_fetchrow($result)); |
| 604 | |
| 605 | $db->sql_freeresult($result); |
| 606 | |
| 607 | delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX); |
| 608 | |
| 609 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_OUTBOX', false, array($user_row['username'])); |
| 610 | |
| 611 | $lang = 'EMPTIED'; |
| 612 | } |
| 613 | $db->sql_freeresult($result); |
| 614 | |
| 615 | trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 620 | 'u' => $user_id, |
| 621 | 'i' => $id, |
| 622 | 'mode' => $mode, |
| 623 | 'action' => $action, |
| 624 | 'update' => true)) |
| 625 | ); |
| 626 | } |
| 627 | break; |
| 628 | |
| 629 | case 'moveposts': |
| 630 | |
| 631 | if (!check_form_key($form_name)) |
| 632 | { |
| 633 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 634 | } |
| 635 | |
| 636 | $user->add_lang('acp/forums'); |
| 637 | |
| 638 | $new_forum_id = $request->variable('new_f', 0); |
| 639 | |
| 640 | if (!$new_forum_id) |
| 641 | { |
| 642 | $this->page_title = 'USER_ADMIN_MOVE_POSTS'; |
| 643 | |
| 644 | $template->assign_vars(array( |
| 645 | 'S_SELECT_FORUM' => true, |
| 646 | 'U_ACTION' => $this->u_action . "&action=$action&u=$user_id", |
| 647 | 'U_BACK' => $this->u_action . "&u=$user_id", |
| 648 | 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true)) |
| 649 | ); |
| 650 | |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | // Is the new forum postable to? |
| 655 | $sql = 'SELECT forum_name, forum_type |
| 656 | FROM ' . FORUMS_TABLE . " |
| 657 | WHERE forum_id = $new_forum_id"; |
| 658 | $result = $db->sql_query($sql); |
| 659 | $forum_info = $db->sql_fetchrow($result); |
| 660 | $db->sql_freeresult($result); |
| 661 | |
| 662 | if (!$forum_info) |
| 663 | { |
| 664 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 665 | } |
| 666 | |
| 667 | if ($forum_info['forum_type'] != FORUM_POST) |
| 668 | { |
| 669 | trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 670 | } |
| 671 | |
| 672 | // Two stage? |
| 673 | // Move topics comprising only posts from this user |
| 674 | $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array(); |
| 675 | $forum_id_ary = array($new_forum_id); |
| 676 | |
| 677 | $sql = 'SELECT topic_id, post_visibility, COUNT(post_id) AS total_posts |
| 678 | FROM ' . POSTS_TABLE . " |
| 679 | WHERE poster_id = $user_id |
| 680 | AND forum_id <> $new_forum_id |
| 681 | GROUP BY topic_id, post_visibility"; |
| 682 | $result = $db->sql_query($sql); |
| 683 | |
| 684 | while ($row = $db->sql_fetchrow($result)) |
| 685 | { |
| 686 | $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts']; |
| 687 | } |
| 688 | $db->sql_freeresult($result); |
| 689 | |
| 690 | if (count($topic_id_ary)) |
| 691 | { |
| 692 | $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment |
| 693 | FROM ' . TOPICS_TABLE . ' |
| 694 | WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); |
| 695 | $result = $db->sql_query($sql); |
| 696 | |
| 697 | while ($row = $db->sql_fetchrow($result)) |
| 698 | { |
| 699 | if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved'] |
| 700 | && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] |
| 701 | && $topic_id_ary[$row['topic_id']][ITEM_REAPPROVE] == $row['topic_posts_unapproved'] |
| 702 | && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) |
| 703 | { |
| 704 | $move_topic_ary[] = $row['topic_id']; |
| 705 | } |
| 706 | else |
| 707 | { |
| 708 | $move_post_ary[$row['topic_id']]['title'] = $row['topic_title']; |
| 709 | $move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0; |
| 710 | } |
| 711 | |
| 712 | $forum_id_ary[] = $row['forum_id']; |
| 713 | } |
| 714 | $db->sql_freeresult($result); |
| 715 | } |
| 716 | |
| 717 | // Entire topic comprises posts by this user, move these topics |
| 718 | if (count($move_topic_ary)) |
| 719 | { |
| 720 | move_topics($move_topic_ary, $new_forum_id, false); |
| 721 | } |
| 722 | |
| 723 | if (count($move_post_ary)) |
| 724 | { |
| 725 | // Create new topic |
| 726 | // Update post_ids, report_ids, attachment_ids |
| 727 | foreach ($move_post_ary as $topic_id => $post_ary) |
| 728 | { |
| 729 | // Create new topic |
| 730 | $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
| 731 | 'topic_poster' => $user_id, |
| 732 | 'topic_time' => time(), |
| 733 | 'forum_id' => $new_forum_id, |
| 734 | 'icon_id' => 0, |
| 735 | 'topic_visibility' => ITEM_APPROVED, |
| 736 | 'topic_title' => $post_ary['title'], |
| 737 | 'topic_first_poster_name' => $user_row['username'], |
| 738 | 'topic_type' => POST_NORMAL, |
| 739 | 'topic_time_limit' => 0, |
| 740 | 'topic_attachment' => $post_ary['attach']) |
| 741 | ); |
| 742 | $db->sql_query($sql); |
| 743 | |
| 744 | $new_topic_id = $db->sql_nextid(); |
| 745 | |
| 746 | // Move posts |
| 747 | $sql = 'UPDATE ' . POSTS_TABLE . " |
| 748 | SET forum_id = $new_forum_id, topic_id = $new_topic_id |
| 749 | WHERE topic_id = $topic_id |
| 750 | AND poster_id = $user_id"; |
| 751 | $db->sql_query($sql); |
| 752 | |
| 753 | if ($post_ary['attach']) |
| 754 | { |
| 755 | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " |
| 756 | SET topic_id = $new_topic_id |
| 757 | WHERE topic_id = $topic_id |
| 758 | AND poster_id = $user_id"; |
| 759 | $db->sql_query($sql); |
| 760 | } |
| 761 | |
| 762 | $new_topic_id_ary[] = $new_topic_id; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | $forum_id_ary = array_unique($forum_id_ary); |
| 767 | $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary)); |
| 768 | |
| 769 | if (count($topic_id_ary)) |
| 770 | { |
| 771 | sync('topic_reported', 'topic_id', $topic_id_ary); |
| 772 | sync('topic', 'topic_id', $topic_id_ary); |
| 773 | } |
| 774 | |
| 775 | if (count($forum_id_ary)) |
| 776 | { |
| 777 | sync('forum', 'forum_id', $forum_id_ary, false, true); |
| 778 | } |
| 779 | |
| 780 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS', false, array($user_row['username'], $forum_info['forum_name'])); |
| 781 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS_USER', false, array( |
| 782 | 'reportee_id' => $user_id, |
| 783 | $forum_info['forum_name'] |
| 784 | )); |
| 785 | |
| 786 | trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 787 | |
| 788 | break; |
| 789 | |
| 790 | case 'leave_nr': |
| 791 | |
| 792 | if (confirm_box(true)) |
| 793 | { |
| 794 | remove_newly_registered($user_id, $user_row); |
| 795 | |
| 796 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REMOVED_NR', false, array($user_row['username'])); |
| 797 | trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 798 | } |
| 799 | else |
| 800 | { |
| 801 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 802 | 'u' => $user_id, |
| 803 | 'i' => $id, |
| 804 | 'mode' => $mode, |
| 805 | 'action' => $action, |
| 806 | 'update' => true)) |
| 807 | ); |
| 808 | } |
| 809 | |
| 810 | break; |
| 811 | |
| 812 | default: |
| 813 | $u_action = $this->u_action; |
| 814 | |
| 815 | /** |
| 816 | * Run custom quicktool code |
| 817 | * |
| 818 | * @event core.acp_users_overview_run_quicktool |
| 819 | * @var string action Quick tool that should be run |
| 820 | * @var array user_row Current user data |
| 821 | * @var string u_action The u_action link |
| 822 | * @var int user_id User id of the user to manage |
| 823 | * @since 3.1.0-a1 |
| 824 | * @changed 3.2.2-RC1 Added u_action |
| 825 | * @changed 3.2.10-RC1 Added user_id |
| 826 | */ |
| 827 | $vars = array('action', 'user_row', 'u_action', 'user_id'); |
| 828 | extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars))); |
| 829 | |
| 830 | unset($u_action); |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | // Handle registration info updates |
| 835 | $data = array( |
| 836 | 'username' => $request->variable('user', $user_row['username'], true), |
| 837 | 'user_founder' => $request->variable('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0), |
| 838 | 'email' => strtolower($request->variable('user_email', $user_row['user_email'])), |
| 839 | 'new_password' => $request->variable('new_password', '', true), |
| 840 | 'password_confirm' => $request->variable('password_confirm', '', true), |
| 841 | ); |
| 842 | |
| 843 | // Validation data - we do not check the password complexity setting here |
| 844 | $check_ary = array( |
| 845 | 'new_password' => array( |
| 846 | array('string', true, $config['min_pass_chars'], 0), |
| 847 | array('password')), |
| 848 | 'password_confirm' => array('string', true, $config['min_pass_chars'], 0), |
| 849 | ); |
| 850 | |
| 851 | // Check username if altered |
| 852 | if ($data['username'] != $user_row['username']) |
| 853 | { |
| 854 | $check_ary += array( |
| 855 | 'username' => array( |
| 856 | array('string', false, $config['min_name_chars'], $config['max_name_chars']), |
| 857 | array('username', $user_row['username'], true) |
| 858 | ), |
| 859 | ); |
| 860 | } |
| 861 | |
| 862 | // Check email if altered |
| 863 | if ($data['email'] != $user_row['user_email']) |
| 864 | { |
| 865 | $check_ary += array( |
| 866 | 'email' => array( |
| 867 | array('string', false, 6, 60), |
| 868 | array('user_email', $user_row['user_email']), |
| 869 | ), |
| 870 | ); |
| 871 | } |
| 872 | |
| 873 | $error = validate_data($data, $check_ary); |
| 874 | |
| 875 | if ($data['new_password'] && $data['password_confirm'] != $data['new_password']) |
| 876 | { |
| 877 | $error[] = 'NEW_PASSWORD_ERROR'; |
| 878 | } |
| 879 | |
| 880 | if (!check_form_key($form_name)) |
| 881 | { |
| 882 | $error[] = 'FORM_INVALID'; |
| 883 | } |
| 884 | |
| 885 | // Instantiate passwords manager |
| 886 | /* @var $passwords_manager \phpbb\passwords\manager */ |
| 887 | $passwords_manager = $phpbb_container->get('passwords.manager'); |
| 888 | |
| 889 | // Which updates do we need to do? |
| 890 | $update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false; |
| 891 | $update_password = $data['new_password'] && !$passwords_manager->check($data['new_password'], $user_row['user_password']); |
| 892 | $update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false; |
| 893 | |
| 894 | if (!count($error)) |
| 895 | { |
| 896 | $sql_ary = array(); |
| 897 | |
| 898 | if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) |
| 899 | { |
| 900 | // Only allow founders updating the founder status... |
| 901 | if ($user->data['user_type'] == USER_FOUNDER) |
| 902 | { |
| 903 | // Setting a normal member to be a founder |
| 904 | if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER) |
| 905 | { |
| 906 | // Make sure the user is not setting an Inactive or ignored user to be a founder |
| 907 | if ($user_row['user_type'] == USER_IGNORE) |
| 908 | { |
| 909 | trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 910 | } |
| 911 | |
| 912 | if ($user_row['user_type'] == USER_INACTIVE) |
| 913 | { |
| 914 | trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 915 | } |
| 916 | |
| 917 | $sql_ary['user_type'] = USER_FOUNDER; |
| 918 | } |
| 919 | else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER) |
| 920 | { |
| 921 | // Check if at least one founder is present |
| 922 | $sql = 'SELECT user_id |
| 923 | FROM ' . USERS_TABLE . ' |
| 924 | WHERE user_type = ' . USER_FOUNDER . ' |
| 925 | AND user_id <> ' . $user_id; |
| 926 | $result = $db->sql_query_limit($sql, 1); |
| 927 | $row = $db->sql_fetchrow($result); |
| 928 | $db->sql_freeresult($result); |
| 929 | |
| 930 | if ($row) |
| 931 | { |
| 932 | $sql_ary['user_type'] = USER_NORMAL; |
| 933 | } |
| 934 | else |
| 935 | { |
| 936 | trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * Modify user data before we update it |
| 944 | * |
| 945 | * @event core.acp_users_overview_modify_data |
| 946 | * @var array user_row Current user data |
| 947 | * @var array data Submitted user data |
| 948 | * @var array sql_ary User data we udpate |
| 949 | * @since 3.1.0-a1 |
| 950 | */ |
| 951 | $vars = array('user_row', 'data', 'sql_ary'); |
| 952 | extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars))); |
| 953 | |
| 954 | if ($update_username !== false) |
| 955 | { |
| 956 | $sql_ary['username'] = $update_username; |
| 957 | $sql_ary['username_clean'] = utf8_clean_string($update_username); |
| 958 | |
| 959 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_NAME', false, array( |
| 960 | 'reportee_id' => $user_id, |
| 961 | $user_row['username'], |
| 962 | $update_username |
| 963 | )); |
| 964 | } |
| 965 | |
| 966 | if ($update_email !== false) |
| 967 | { |
| 968 | $sql_ary += ['user_email' => $update_email]; |
| 969 | |
| 970 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array( |
| 971 | 'reportee_id' => $user_id, |
| 972 | $user_row['username'], |
| 973 | $user_row['user_email'], |
| 974 | $update_email |
| 975 | )); |
| 976 | } |
| 977 | |
| 978 | if ($update_password) |
| 979 | { |
| 980 | $sql_ary += array( |
| 981 | 'user_password' => $passwords_manager->hash($data['new_password']), |
| 982 | 'user_passchg' => time(), |
| 983 | ); |
| 984 | |
| 985 | $user->reset_login_keys($user_id); |
| 986 | |
| 987 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array( |
| 988 | 'reportee_id' => $user_id, |
| 989 | $user_row['username'] |
| 990 | )); |
| 991 | } |
| 992 | |
| 993 | if (count($sql_ary)) |
| 994 | { |
| 995 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 996 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 997 | WHERE user_id = ' . $user_id; |
| 998 | $db->sql_query($sql); |
| 999 | } |
| 1000 | |
| 1001 | if ($update_username) |
| 1002 | { |
| 1003 | user_update_name($user_row['username'], $update_username); |
| 1004 | } |
| 1005 | |
| 1006 | // Let the users permissions being updated |
| 1007 | $auth->acl_clear_prefetch($user_id); |
| 1008 | |
| 1009 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_USER_UPDATE', false, array($data['username'])); |
| 1010 | |
| 1011 | trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 1012 | } |
| 1013 | |
| 1014 | // Replace "error" strings with their real, localised form |
| 1015 | $error = array_map(array($user, 'lang'), $error); |
| 1016 | } |
| 1017 | |
| 1018 | if ($user_id == $user->data['user_id']) |
| 1019 | { |
| 1020 | $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX'); |
| 1021 | if ($user_row['user_new']) |
| 1022 | { |
| 1023 | $quick_tool_ary['leave_nr'] = 'LEAVE_NR'; |
| 1024 | } |
| 1025 | } |
| 1026 | else |
| 1027 | { |
| 1028 | $quick_tool_ary = array(); |
| 1029 | |
| 1030 | if ($user_row['user_type'] != USER_FOUNDER) |
| 1031 | { |
| 1032 | $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP'); |
| 1033 | } |
| 1034 | |
| 1035 | if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE) |
| 1036 | { |
| 1037 | $quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE')); |
| 1038 | } |
| 1039 | |
| 1040 | $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX'); |
| 1041 | |
| 1042 | if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE)) |
| 1043 | { |
| 1044 | $quick_tool_ary['reactivate'] = 'FORCE'; |
| 1045 | } |
| 1046 | |
| 1047 | if ($user_row['user_new']) |
| 1048 | { |
| 1049 | $quick_tool_ary['leave_nr'] = 'LEAVE_NR'; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | if ($config['load_onlinetrack']) |
| 1054 | { |
| 1055 | $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline |
| 1056 | FROM ' . SESSIONS_TABLE . " |
| 1057 | WHERE session_user_id = $user_id"; |
| 1058 | $result = $db->sql_query($sql); |
| 1059 | $row = $db->sql_fetchrow($result); |
| 1060 | $db->sql_freeresult($result); |
| 1061 | |
| 1062 | $user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0; |
| 1063 | $user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0; |
| 1064 | unset($row); |
| 1065 | } |
| 1066 | |
| 1067 | /** |
| 1068 | * Add additional quick tool options and overwrite user data |
| 1069 | * |
| 1070 | * @event core.acp_users_display_overview |
| 1071 | * @var array user_row Array with user data |
| 1072 | * @var array quick_tool_ary Ouick tool options |
| 1073 | * @since 3.1.0-a1 |
| 1074 | */ |
| 1075 | $vars = array('user_row', 'quick_tool_ary'); |
| 1076 | extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars))); |
| 1077 | |
| 1078 | $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>'; |
| 1079 | foreach ($quick_tool_ary as $value => $lang) |
| 1080 | { |
| 1081 | $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>'; |
| 1082 | } |
| 1083 | |
| 1084 | $last_active = $user_row['user_last_active'] ?: ($user_row['session_time'] ?? 0); |
| 1085 | |
| 1086 | $inactive_reason = ''; |
| 1087 | if ($user_row['user_type'] == USER_INACTIVE) |
| 1088 | { |
| 1089 | $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN']; |
| 1090 | |
| 1091 | switch ($user_row['user_inactive_reason']) |
| 1092 | { |
| 1093 | case INACTIVE_REGISTER: |
| 1094 | $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER']; |
| 1095 | break; |
| 1096 | |
| 1097 | case INACTIVE_PROFILE: |
| 1098 | $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE']; |
| 1099 | break; |
| 1100 | |
| 1101 | case INACTIVE_MANUAL: |
| 1102 | $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL']; |
| 1103 | break; |
| 1104 | |
| 1105 | case INACTIVE_REMIND: |
| 1106 | $inactive_reason = $user->lang['INACTIVE_REASON_REMIND']; |
| 1107 | break; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | // Posts in Queue |
| 1112 | $sql = 'SELECT COUNT(post_id) as posts_in_queue |
| 1113 | FROM ' . POSTS_TABLE . ' |
| 1114 | WHERE poster_id = ' . $user_id . ' |
| 1115 | AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)); |
| 1116 | $result = $db->sql_query($sql); |
| 1117 | $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); |
| 1118 | $db->sql_freeresult($result); |
| 1119 | |
| 1120 | $sql = 'SELECT post_id |
| 1121 | FROM ' . POSTS_TABLE . ' |
| 1122 | WHERE poster_id = '. $user_id; |
| 1123 | $result = $db->sql_query_limit($sql, 1); |
| 1124 | $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id'); |
| 1125 | $db->sql_freeresult($result); |
| 1126 | |
| 1127 | $template->assign_vars(array( |
| 1128 | 'L_NAME_CHARS_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS_XY', (int) $config['min_name_chars']), $user->lang('CHARACTERS_XY', (int) $config['max_name_chars'])), |
| 1129 | 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars'])), |
| 1130 | 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']), |
| 1131 | 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, |
| 1132 | |
| 1133 | 'S_OVERVIEW' => true, |
| 1134 | 'S_USER_IP' => ($user_row['user_ip']) ? true : false, |
| 1135 | 'S_USER_FOUNDER' => ($user_row['user_type'] == USER_FOUNDER) ? true : false, |
| 1136 | 'S_ACTION_OPTIONS' => $s_action_options, |
| 1137 | 'S_OWN_ACCOUNT' => ($user_id == $user->data['user_id']) ? true : false, |
| 1138 | 'S_USER_INACTIVE' => ($user_row['user_type'] == USER_INACTIVE) ? true : false, |
| 1139 | |
| 1140 | 'U_SHOW_IP' => $this->u_action . "&u=$user_id&ip=" . (($ip == 'ip') ? 'hostname' : 'ip'), |
| 1141 | 'U_WHOIS' => $this->u_action . "&action=whois&user_ip={$user_row['user_ip']}", |
| 1142 | 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue') : '', |
| 1143 | 'U_SEARCH_USER' => ($config['load_search'] && $auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$user_row['user_id']}&sr=posts") : '', |
| 1144 | |
| 1145 | 'U_SWITCH_PERMISSIONS' => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&u={$user_row['user_id']}&hash=" . generate_link_hash('switchperm')) : '', |
| 1146 | |
| 1147 | 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'], |
| 1148 | 'USER' => $user_row['username'], |
| 1149 | 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), |
| 1150 | 'REGISTERED_IP' => ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], |
| 1151 | 'USER_LASTACTIVE' => ($last_active) ? $user->format_date($last_active) : ' - ', |
| 1152 | 'USER_EMAIL' => $user_row['user_email'], |
| 1153 | 'USER_WARNINGS' => $user_row['user_warnings'], |
| 1154 | 'USER_POSTS' => $user_row['user_posts'], |
| 1155 | 'USER_HAS_POSTS' => $user_row['user_has_posts'], |
| 1156 | 'USER_INACTIVE_REASON' => $inactive_reason, |
| 1157 | )); |
| 1158 | |
| 1159 | break; |
| 1160 | |
| 1161 | case 'feedback': |
| 1162 | |
| 1163 | $user->add_lang('mcp'); |
| 1164 | |
| 1165 | // Set up general vars |
| 1166 | $start = $request->variable('start', 0); |
| 1167 | $deletemark = (isset($_POST['delmarked'])) ? true : false; |
| 1168 | $deleteall = (isset($_POST['delall'])) ? true : false; |
| 1169 | $marked = $request->variable('mark', array(0)); |
| 1170 | $message = $request->variable('message', '', true); |
| 1171 | |
| 1172 | /* @var $pagination \phpbb\pagination */ |
| 1173 | $pagination = $phpbb_container->get('pagination'); |
| 1174 | |
| 1175 | // Sort keys |
| 1176 | $sort_days = $request->variable('st', 0); |
| 1177 | $sort_key = $request->variable('sk', 't'); |
| 1178 | $sort_dir = $request->variable('sd', 'd'); |
| 1179 | |
| 1180 | // Delete entries if requested and able |
| 1181 | if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) |
| 1182 | { |
| 1183 | if (!check_form_key($form_name)) |
| 1184 | { |
| 1185 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 1186 | } |
| 1187 | |
| 1188 | $where_sql = ''; |
| 1189 | if ($deletemark && $marked) |
| 1190 | { |
| 1191 | $sql_in = array(); |
| 1192 | foreach ($marked as $mark) |
| 1193 | { |
| 1194 | $sql_in[] = $mark; |
| 1195 | } |
| 1196 | $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in); |
| 1197 | unset($sql_in); |
| 1198 | } |
| 1199 | |
| 1200 | if ($where_sql || $deleteall) |
| 1201 | { |
| 1202 | $sql = 'DELETE FROM ' . LOG_TABLE . ' |
| 1203 | WHERE log_type = ' . LOG_USERS . " |
| 1204 | AND reportee_id = $user_id |
| 1205 | $where_sql"; |
| 1206 | $db->sql_query($sql); |
| 1207 | |
| 1208 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CLEAR_USER', false, array($user_row['username'])); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | if ($submit && $message) |
| 1213 | { |
| 1214 | if (!check_form_key($form_name)) |
| 1215 | { |
| 1216 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 1217 | } |
| 1218 | |
| 1219 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array($user_row['username'])); |
| 1220 | $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array( |
| 1221 | 'forum_id' => 0, |
| 1222 | 'topic_id' => 0, |
| 1223 | $user_row['username'] |
| 1224 | )); |
| 1225 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GENERAL', false, array( |
| 1226 | 'reportee_id' => $user_id, |
| 1227 | $message |
| 1228 | )); |
| 1229 | |
| 1230 | trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 1231 | } |
| 1232 | |
| 1233 | // Sorting |
| 1234 | $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 1235 | $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); |
| 1236 | $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); |
| 1237 | |
| 1238 | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; |
| 1239 | gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); |
| 1240 | |
| 1241 | // Define where and sort sql for use in displaying logs |
| 1242 | $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0; |
| 1243 | $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); |
| 1244 | |
| 1245 | // Grab log data |
| 1246 | $log_data = array(); |
| 1247 | $log_count = 0; |
| 1248 | $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort); |
| 1249 | |
| 1250 | $base_url = $this->u_action . "&u=$user_id&$u_sort_param"; |
| 1251 | $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); |
| 1252 | |
| 1253 | $template->assign_vars(array( |
| 1254 | 'S_FEEDBACK' => true, |
| 1255 | |
| 1256 | 'S_LIMIT_DAYS' => $s_limit_days, |
| 1257 | 'S_SORT_KEY' => $s_sort_key, |
| 1258 | 'S_SORT_DIR' => $s_sort_dir, |
| 1259 | 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')) |
| 1260 | ); |
| 1261 | |
| 1262 | foreach ($log_data as $row) |
| 1263 | { |
| 1264 | $template->assign_block_vars('log', array( |
| 1265 | 'USERNAME' => $row['username_full'], |
| 1266 | 'IP' => $row['ip'], |
| 1267 | 'DATE' => $user->format_date($row['time']), |
| 1268 | 'ACTION' => nl2br($row['action']), |
| 1269 | 'ID' => $row['id']) |
| 1270 | ); |
| 1271 | } |
| 1272 | |
| 1273 | break; |
| 1274 | |
| 1275 | case 'warnings': |
| 1276 | $user->add_lang('mcp'); |
| 1277 | |
| 1278 | // Set up general vars |
| 1279 | $deletemark = (isset($_POST['delmarked'])) ? true : false; |
| 1280 | $deleteall = (isset($_POST['delall'])) ? true : false; |
| 1281 | $confirm = (isset($_POST['confirm'])) ? true : false; |
| 1282 | $marked = $request->variable('mark', array(0)); |
| 1283 | |
| 1284 | // Delete entries if requested and able |
| 1285 | if ($deletemark || $deleteall || $confirm) |
| 1286 | { |
| 1287 | if (confirm_box(true)) |
| 1288 | { |
| 1289 | $where_sql = ''; |
| 1290 | $deletemark = $request->variable('delmarked', 0); |
| 1291 | $deleteall = $request->variable('delall', 0); |
| 1292 | if ($deletemark && $marked) |
| 1293 | { |
| 1294 | $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked)); |
| 1295 | } |
| 1296 | |
| 1297 | if ($where_sql || $deleteall) |
| 1298 | { |
| 1299 | $sql = 'DELETE FROM ' . WARNINGS_TABLE . " |
| 1300 | WHERE user_id = $user_id |
| 1301 | $where_sql"; |
| 1302 | $db->sql_query($sql); |
| 1303 | |
| 1304 | if ($deleteall) |
| 1305 | { |
| 1306 | $log_warnings = $deleted_warnings = 0; |
| 1307 | } |
| 1308 | else |
| 1309 | { |
| 1310 | $num_warnings = (int) $db->sql_affectedrows(); |
| 1311 | $deleted_warnings = ' user_warnings - ' . $num_warnings; |
| 1312 | $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings; |
| 1313 | } |
| 1314 | |
| 1315 | $sql = 'UPDATE ' . USERS_TABLE . " |
| 1316 | SET user_warnings = $deleted_warnings |
| 1317 | WHERE user_id = $user_id"; |
| 1318 | $db->sql_query($sql); |
| 1319 | |
| 1320 | if ($log_warnings) |
| 1321 | { |
| 1322 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED', false, array($user_row['username'], $num_warnings)); |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED_ALL', false, array($user_row['username'])); |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | else |
| 1331 | { |
| 1332 | $s_hidden_fields = array( |
| 1333 | 'i' => $id, |
| 1334 | 'mode' => $mode, |
| 1335 | 'u' => $user_id, |
| 1336 | 'mark' => $marked, |
| 1337 | ); |
| 1338 | if (isset($_POST['delmarked'])) |
| 1339 | { |
| 1340 | $s_hidden_fields['delmarked'] = 1; |
| 1341 | } |
| 1342 | if (isset($_POST['delall'])) |
| 1343 | { |
| 1344 | $s_hidden_fields['delall'] = 1; |
| 1345 | } |
| 1346 | if (isset($_POST['delall']) || (isset($_POST['delmarked']) && count($marked))) |
| 1347 | { |
| 1348 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour |
| 1354 | FROM ' . WARNINGS_TABLE . ' w |
| 1355 | LEFT JOIN ' . LOG_TABLE . ' l |
| 1356 | ON (w.log_id = l.log_id) |
| 1357 | LEFT JOIN ' . USERS_TABLE . ' m |
| 1358 | ON (l.user_id = m.user_id) |
| 1359 | WHERE w.user_id = ' . $user_id . ' |
| 1360 | ORDER BY w.warning_time DESC'; |
| 1361 | $result = $db->sql_query($sql); |
| 1362 | |
| 1363 | while ($row = $db->sql_fetchrow($result)) |
| 1364 | { |
| 1365 | if (!$row['log_operation']) |
| 1366 | { |
| 1367 | // We do not have a log-entry anymore, so there is no data available |
| 1368 | $row['action'] = $user->lang['USER_WARNING_LOG_DELETED']; |
| 1369 | } |
| 1370 | else |
| 1371 | { |
| 1372 | $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}'; |
| 1373 | if (!empty($row['log_data'])) |
| 1374 | { |
| 1375 | $log_data_ary = @unserialize($row['log_data']); |
| 1376 | $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary; |
| 1377 | |
| 1378 | if (isset($user->lang[$row['log_operation']])) |
| 1379 | { |
| 1380 | // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array |
| 1381 | // It doesn't matter if we add more arguments than placeholders |
| 1382 | if ((substr_count($row['action'], '%') - count($log_data_ary)) > 0) |
| 1383 | { |
| 1384 | $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - count($log_data_ary), '')); |
| 1385 | } |
| 1386 | $row['action'] = vsprintf($row['action'], $log_data_ary); |
| 1387 | $row['action'] = bbcode_nl2br(censor_text($row['action'])); |
| 1388 | } |
| 1389 | else if (!empty($log_data_ary)) |
| 1390 | { |
| 1391 | $row['action'] .= '<br />' . implode('', $log_data_ary); |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | $template->assign_block_vars('warn', array( |
| 1397 | 'ID' => $row['warning_id'], |
| 1398 | 'USERNAME' => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-', |
| 1399 | 'ACTION' => make_clickable($row['action']), |
| 1400 | 'DATE' => $user->format_date($row['warning_time']), |
| 1401 | )); |
| 1402 | } |
| 1403 | $db->sql_freeresult($result); |
| 1404 | |
| 1405 | $template->assign_vars(array( |
| 1406 | 'S_WARNINGS' => true, |
| 1407 | )); |
| 1408 | |
| 1409 | break; |
| 1410 | |
| 1411 | case 'profile': |
| 1412 | |
| 1413 | if (!function_exists('user_get_id_name')) |
| 1414 | { |
| 1415 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 1416 | } |
| 1417 | |
| 1418 | /* @var $cp \phpbb\profilefields\manager */ |
| 1419 | $cp = $phpbb_container->get('profilefields.manager'); |
| 1420 | |
| 1421 | $cp_data = $cp_error = array(); |
| 1422 | |
| 1423 | $sql = 'SELECT lang_id |
| 1424 | FROM ' . LANG_TABLE . " |
| 1425 | WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'"; |
| 1426 | $result = $db->sql_query($sql); |
| 1427 | $row = $db->sql_fetchrow($result); |
| 1428 | $db->sql_freeresult($result); |
| 1429 | |
| 1430 | $user_row['iso_lang_id'] = $row['lang_id']; |
| 1431 | |
| 1432 | $data = array( |
| 1433 | 'bday_day' => 0, |
| 1434 | 'bday_month' => 0, |
| 1435 | 'bday_year' => 0, |
| 1436 | ); |
| 1437 | |
| 1438 | if ($user_row['user_birthday']) |
| 1439 | { |
| 1440 | list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']); |
| 1441 | } |
| 1442 | |
| 1443 | $data['bday_day'] = $request->variable('bday_day', $data['bday_day']); |
| 1444 | $data['bday_month'] = $request->variable('bday_month', $data['bday_month']); |
| 1445 | $data['bday_year'] = $request->variable('bday_year', $data['bday_year']); |
| 1446 | $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']); |
| 1447 | |
| 1448 | /** |
| 1449 | * Modify user data on editing profile in ACP |
| 1450 | * |
| 1451 | * @event core.acp_users_modify_profile |
| 1452 | * @var array data Array with user profile data |
| 1453 | * @var bool submit Flag indicating if submit button has been pressed |
| 1454 | * @var int user_id The user id |
| 1455 | * @var array user_row Array with the full user data |
| 1456 | * @since 3.1.4-RC1 |
| 1457 | */ |
| 1458 | $vars = array('data', 'submit', 'user_id', 'user_row'); |
| 1459 | extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_profile', compact($vars))); |
| 1460 | |
| 1461 | if ($submit) |
| 1462 | { |
| 1463 | $error = validate_data($data, array( |
| 1464 | 'bday_day' => array('num', true, 1, 31), |
| 1465 | 'bday_month' => array('num', true, 1, 12), |
| 1466 | 'bday_year' => array('num', true, 1901, gmdate('Y', time())), |
| 1467 | 'user_birthday' => array('date', true), |
| 1468 | )); |
| 1469 | |
| 1470 | // validate custom profile fields |
| 1471 | $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error); |
| 1472 | |
| 1473 | if (count($cp_error)) |
| 1474 | { |
| 1475 | $error = array_merge($error, $cp_error); |
| 1476 | } |
| 1477 | if (!check_form_key($form_name)) |
| 1478 | { |
| 1479 | $error[] = 'FORM_INVALID'; |
| 1480 | } |
| 1481 | |
| 1482 | /** |
| 1483 | * Validate profile data in ACP before submitting to the database |
| 1484 | * |
| 1485 | * @event core.acp_users_profile_validate |
| 1486 | * @var array data Array with user profile data |
| 1487 | * @var int user_id The user id |
| 1488 | * @var array user_row Array with the full user data |
| 1489 | * @var array error Array with the form errors |
| 1490 | * @since 3.1.4-RC1 |
| 1491 | * @changed 3.1.12-RC1 Removed submit, added user_id, user_row |
| 1492 | */ |
| 1493 | $vars = array('data', 'user_id', 'user_row', 'error'); |
| 1494 | extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_validate', compact($vars))); |
| 1495 | |
| 1496 | if (!count($error)) |
| 1497 | { |
| 1498 | $sql_ary = array( |
| 1499 | 'user_birthday' => $data['user_birthday'], |
| 1500 | ); |
| 1501 | |
| 1502 | /** |
| 1503 | * Modify profile data in ACP before submitting to the database |
| 1504 | * |
| 1505 | * @event core.acp_users_profile_modify_sql_ary |
| 1506 | * @var array cp_data Array with the user custom profile fields data |
| 1507 | * @var array data Array with user profile data |
| 1508 | * @var int user_id The user id |
| 1509 | * @var array user_row Array with the full user data |
| 1510 | * @var array sql_ary Array with sql data |
| 1511 | * @since 3.1.4-RC1 |
| 1512 | */ |
| 1513 | $vars = array('cp_data', 'data', 'user_id', 'user_row', 'sql_ary'); |
| 1514 | extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_modify_sql_ary', compact($vars))); |
| 1515 | |
| 1516 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 1517 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " |
| 1518 | WHERE user_id = $user_id"; |
| 1519 | $db->sql_query($sql); |
| 1520 | |
| 1521 | // Update Custom Fields |
| 1522 | $cp->update_profile_field_data($user_id, $cp_data); |
| 1523 | |
| 1524 | trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 1525 | } |
| 1526 | |
| 1527 | // Replace "error" strings with their real, localised form |
| 1528 | $error = array_map(array($user, 'lang'), $error); |
| 1529 | } |
| 1530 | |
| 1531 | $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>'; |
| 1532 | for ($i = 1; $i < 32; $i++) |
| 1533 | { |
| 1534 | $selected = ($i == $data['bday_day']) ? ' selected="selected"' : ''; |
| 1535 | $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>"; |
| 1536 | } |
| 1537 | |
| 1538 | $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>'; |
| 1539 | for ($i = 1; $i < 13; $i++) |
| 1540 | { |
| 1541 | $selected = ($i == $data['bday_month']) ? ' selected="selected"' : ''; |
| 1542 | $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>"; |
| 1543 | } |
| 1544 | |
| 1545 | $now = getdate(); |
| 1546 | $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>'; |
| 1547 | for ($i = $now['year'] - 100; $i <= $now['year']; $i++) |
| 1548 | { |
| 1549 | $selected = ($i == $data['bday_year']) ? ' selected="selected"' : ''; |
| 1550 | $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>"; |
| 1551 | } |
| 1552 | unset($now); |
| 1553 | |
| 1554 | $template->assign_vars(array( |
| 1555 | 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, |
| 1556 | 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, |
| 1557 | 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, |
| 1558 | |
| 1559 | 'S_PROFILE' => true) |
| 1560 | ); |
| 1561 | |
| 1562 | // Get additional profile fields and assign them to the template block var 'profile_fields' |
| 1563 | $user->get_profile_fields($user_id); |
| 1564 | |
| 1565 | $cp->generate_profile_fields('profile', $user_row['iso_lang_id']); |
| 1566 | |
| 1567 | break; |
| 1568 | |
| 1569 | case 'prefs': |
| 1570 | |
| 1571 | if (!function_exists('user_get_id_name')) |
| 1572 | { |
| 1573 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 1574 | } |
| 1575 | |
| 1576 | $data = array( |
| 1577 | 'dateformat' => $request->variable('dateformat', $user_row['user_dateformat'], true), |
| 1578 | 'lang' => basename($request->variable('lang', $user_row['user_lang'])), |
| 1579 | 'tz' => $request->variable('tz', $user_row['user_timezone']), |
| 1580 | 'style' => $request->variable('style', $user_row['user_style']), |
| 1581 | 'viewemail' => $request->variable('viewemail', $user_row['user_allow_viewemail']), |
| 1582 | 'massemail' => $request->variable('massemail', $user_row['user_allow_massemail']), |
| 1583 | 'hideonline' => $request->variable('hideonline', !$user_row['user_allow_viewonline']), |
| 1584 | 'notifypm' => $request->variable('notifypm', $user_row['user_notify_pm']), |
| 1585 | 'allowpm' => $request->variable('allowpm', $user_row['user_allow_pm']), |
| 1586 | |
| 1587 | 'topic_sk' => $request->variable('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'), |
| 1588 | 'topic_sd' => $request->variable('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'), |
| 1589 | 'topic_st' => $request->variable('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0), |
| 1590 | |
| 1591 | 'post_sk' => $request->variable('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'), |
| 1592 | 'post_sd' => $request->variable('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'), |
| 1593 | 'post_st' => $request->variable('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0), |
| 1594 | |
| 1595 | 'view_images' => $request->variable('view_images', $this->optionget($user_row, 'viewimg')), |
| 1596 | 'view_smilies' => $request->variable('view_smilies', $this->optionget($user_row, 'viewsmilies')), |
| 1597 | 'view_sigs' => $request->variable('view_sigs', $this->optionget($user_row, 'viewsigs')), |
| 1598 | 'view_avatars' => $request->variable('view_avatars', $this->optionget($user_row, 'viewavatars')), |
| 1599 | 'view_wordcensor' => $request->variable('view_wordcensor', $this->optionget($user_row, 'viewcensors')), |
| 1600 | |
| 1601 | 'bbcode' => $request->variable('bbcode', $this->optionget($user_row, 'bbcode')), |
| 1602 | 'smilies' => $request->variable('smilies', $this->optionget($user_row, 'smilies')), |
| 1603 | 'sig' => $request->variable('sig', $this->optionget($user_row, 'attachsig')), |
| 1604 | 'notify' => $request->variable('notify', $user_row['user_notify']), |
| 1605 | ); |
| 1606 | |
| 1607 | /** |
| 1608 | * Modify users preferences data |
| 1609 | * |
| 1610 | * @event core.acp_users_prefs_modify_data |
| 1611 | * @var array data Array with users preferences data |
| 1612 | * @var array user_row Array with user data |
| 1613 | * @since 3.1.0-b3 |
| 1614 | */ |
| 1615 | $vars = array('data', 'user_row'); |
| 1616 | extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_data', compact($vars))); |
| 1617 | |
| 1618 | if ($submit) |
| 1619 | { |
| 1620 | $error = validate_data($data, array( |
| 1621 | 'dateformat' => array('string', false, 1, 64), |
| 1622 | 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'), |
| 1623 | 'tz' => array('timezone'), |
| 1624 | |
| 1625 | 'topic_sk' => array('string', false, 1, 1), |
| 1626 | 'topic_sd' => array('string', false, 1, 1), |
| 1627 | 'post_sk' => array('string', false, 1, 1), |
| 1628 | 'post_sd' => array('string', false, 1, 1), |
| 1629 | )); |
| 1630 | |
| 1631 | if (!check_form_key($form_name)) |
| 1632 | { |
| 1633 | $error[] = 'FORM_INVALID'; |
| 1634 | } |
| 1635 | |
| 1636 | if (!count($error)) |
| 1637 | { |
| 1638 | $this->optionset($user_row, 'viewimg', $data['view_images']); |
| 1639 | $this->optionset($user_row, 'viewsmilies', $data['view_smilies']); |
| 1640 | $this->optionset($user_row, 'viewsigs', $data['view_sigs']); |
| 1641 | $this->optionset($user_row, 'viewavatars', $data['view_avatars']); |
| 1642 | $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']); |
| 1643 | $this->optionset($user_row, 'bbcode', $data['bbcode']); |
| 1644 | $this->optionset($user_row, 'smilies', $data['smilies']); |
| 1645 | $this->optionset($user_row, 'attachsig', $data['sig']); |
| 1646 | |
| 1647 | $sql_ary = array( |
| 1648 | 'user_options' => $user_row['user_options'], |
| 1649 | |
| 1650 | 'user_allow_pm' => $data['allowpm'], |
| 1651 | 'user_allow_viewemail' => $data['viewemail'], |
| 1652 | 'user_allow_massemail' => $data['massemail'], |
| 1653 | 'user_allow_viewonline' => !$data['hideonline'], |
| 1654 | 'user_notify_pm' => $data['notifypm'], |
| 1655 | |
| 1656 | 'user_dateformat' => $data['dateformat'], |
| 1657 | 'user_lang' => $data['lang'], |
| 1658 | 'user_timezone' => $data['tz'], |
| 1659 | 'user_style' => $data['style'], |
| 1660 | |
| 1661 | 'user_topic_sortby_type' => $data['topic_sk'], |
| 1662 | 'user_post_sortby_type' => $data['post_sk'], |
| 1663 | 'user_topic_sortby_dir' => $data['topic_sd'], |
| 1664 | 'user_post_sortby_dir' => $data['post_sd'], |
| 1665 | |
| 1666 | 'user_topic_show_days' => $data['topic_st'], |
| 1667 | 'user_post_show_days' => $data['post_st'], |
| 1668 | |
| 1669 | 'user_notify' => $data['notify'], |
| 1670 | ); |
| 1671 | |
| 1672 | /** |
| 1673 | * Modify SQL query before users preferences are updated |
| 1674 | * |
| 1675 | * @event core.acp_users_prefs_modify_sql |
| 1676 | * @var array data Array with users preferences data |
| 1677 | * @var array user_row Array with user data |
| 1678 | * @var array sql_ary SQL array with users preferences data to update |
| 1679 | * @var array error Array with errors data |
| 1680 | * @since 3.1.0-b3 |
| 1681 | */ |
| 1682 | $vars = array('data', 'user_row', 'sql_ary', 'error'); |
| 1683 | extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_sql', compact($vars))); |
| 1684 | |
| 1685 | if (!count($error)) |
| 1686 | { |
| 1687 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 1688 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " |
| 1689 | WHERE user_id = $user_id"; |
| 1690 | $db->sql_query($sql); |
| 1691 | |
| 1692 | // Check if user has an active session |
| 1693 | if ($user_row['session_id']) |
| 1694 | { |
| 1695 | // We'll update the session if user_allow_viewonline has changed and the user is a bot |
| 1696 | // Or if it's a regular user and the admin set it to hide the session |
| 1697 | if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE |
| 1698 | || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline']) |
| 1699 | { |
| 1700 | // We also need to check if the user has the permission to cloak. |
| 1701 | $user_auth = new \phpbb\auth\auth(); |
| 1702 | $user_auth->acl($user_row); |
| 1703 | |
| 1704 | $session_sql_ary = array( |
| 1705 | 'session_viewonline' => ($user_auth->acl_get('u_hideonline')) ? $sql_ary['user_allow_viewonline'] : true, |
| 1706 | ); |
| 1707 | |
| 1708 | $sql = 'UPDATE ' . SESSIONS_TABLE . ' |
| 1709 | SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . " |
| 1710 | WHERE session_user_id = $user_id"; |
| 1711 | $db->sql_query($sql); |
| 1712 | |
| 1713 | unset($user_auth); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | // Replace "error" strings with their real, localised form |
| 1722 | $error = array_map(array($user, 'lang'), $error); |
| 1723 | } |
| 1724 | |
| 1725 | $dateformat_options = ''; |
| 1726 | foreach ($user->lang['dateformats'] as $format => $null) |
| 1727 | { |
| 1728 | $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>'; |
| 1729 | $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : ''); |
| 1730 | $dateformat_options .= '</option>'; |
| 1731 | } |
| 1732 | |
| 1733 | $s_custom = false; |
| 1734 | |
| 1735 | $dateformat_options .= '<option value="custom"'; |
| 1736 | if (!isset($user->lang['dateformats'][$data['dateformat']])) |
| 1737 | { |
| 1738 | $dateformat_options .= ' selected="selected"'; |
| 1739 | $s_custom = true; |
| 1740 | } |
| 1741 | $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>'; |
| 1742 | |
| 1743 | $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); |
| 1744 | |
| 1745 | // Topic ordering options |
| 1746 | $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 1747 | $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); |
| 1748 | |
| 1749 | // Post ordering options |
| 1750 | $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 1751 | $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); |
| 1752 | |
| 1753 | $_options = array('topic', 'post'); |
| 1754 | foreach ($_options as $sort_option) |
| 1755 | { |
| 1756 | ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">'; |
| 1757 | foreach (${'limit_' . $sort_option . '_days'} as $day => $text) |
| 1758 | { |
| 1759 | $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : ''; |
| 1760 | ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>'; |
| 1761 | } |
| 1762 | ${'s_limit_' . $sort_option . '_days'} .= '</select>'; |
| 1763 | |
| 1764 | ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">'; |
| 1765 | foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) |
| 1766 | { |
| 1767 | $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : ''; |
| 1768 | ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>'; |
| 1769 | } |
| 1770 | ${'s_sort_' . $sort_option . '_key'} .= '</select>'; |
| 1771 | |
| 1772 | ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">'; |
| 1773 | foreach ($sort_dir_text as $key => $value) |
| 1774 | { |
| 1775 | $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : ''; |
| 1776 | ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; |
| 1777 | } |
| 1778 | ${'s_sort_' . $sort_option . '_dir'} .= '</select>'; |
| 1779 | } |
| 1780 | |
| 1781 | $timezone_select = phpbb_timezone_select($user, $data['tz'], true); |
| 1782 | $lang_options = phpbb_language_select($db, $data['lang']); |
| 1783 | |
| 1784 | $user_prefs_data = array( |
| 1785 | 'S_PREFS' => true, |
| 1786 | |
| 1787 | 'VIEW_EMAIL' => $data['viewemail'], |
| 1788 | 'MASS_EMAIL' => $data['massemail'], |
| 1789 | 'ALLOW_PM' => $data['allowpm'], |
| 1790 | 'HIDE_ONLINE' => $data['hideonline'], |
| 1791 | 'NOTIFY_PM' => $data['notifypm'], |
| 1792 | 'BBCODE' => $data['bbcode'], |
| 1793 | 'SMILIES' => $data['smilies'], |
| 1794 | 'ATTACH_SIG' => $data['sig'], |
| 1795 | 'NOTIFY' => $data['notify'], |
| 1796 | 'VIEW_IMAGES' => $data['view_images'], |
| 1797 | 'VIEW_SMILIES' => $data['view_smilies'], |
| 1798 | 'VIEW_SIGS' => $data['view_sigs'], |
| 1799 | 'VIEW_AVATARS' => $data['view_avatars'], |
| 1800 | 'VIEW_WORDCENSOR' => $data['view_wordcensor'], |
| 1801 | |
| 1802 | 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, |
| 1803 | 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, |
| 1804 | 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, |
| 1805 | 'S_POST_SORT_DAYS' => $s_limit_post_days, |
| 1806 | 'S_POST_SORT_KEY' => $s_sort_post_key, |
| 1807 | 'S_POST_SORT_DIR' => $s_sort_post_dir, |
| 1808 | |
| 1809 | 'DATE_FORMAT' => $data['dateformat'], |
| 1810 | 'S_DATEFORMAT_OPTIONS' => $dateformat_options, |
| 1811 | 'S_CUSTOM_DATEFORMAT' => $s_custom, |
| 1812 | 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], |
| 1813 | 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), |
| 1814 | |
| 1815 | 'LANG_OPTIONS' => [ |
| 1816 | 'id' => 'lang', |
| 1817 | 'name' => 'lang', |
| 1818 | 'options' => $lang_options, |
| 1819 | ], |
| 1820 | 'S_STYLE_OPTIONS' => [ |
| 1821 | 'id' => 'style', |
| 1822 | 'name' => 'style', |
| 1823 | 'options' => style_select($data['style']) |
| 1824 | ], |
| 1825 | 'TIMEZONE_OPTIONS' => [ |
| 1826 | 'tag' => 'select', |
| 1827 | 'name' => 'tz', |
| 1828 | 'options' => $timezone_select, |
| 1829 | ], |
| 1830 | ); |
| 1831 | |
| 1832 | /** |
| 1833 | * Modify users preferences data before assigning it to the template |
| 1834 | * |
| 1835 | * @event core.acp_users_prefs_modify_template_data |
| 1836 | * @var array data Array with users preferences data |
| 1837 | * @var array user_row Array with user data |
| 1838 | * @var array user_prefs_data Array with users preferences data to be assigned to the template |
| 1839 | * @since 3.1.0-b3 |
| 1840 | */ |
| 1841 | $vars = array('data', 'user_row', 'user_prefs_data'); |
| 1842 | extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_template_data', compact($vars))); |
| 1843 | |
| 1844 | $template->assign_vars($user_prefs_data); |
| 1845 | |
| 1846 | break; |
| 1847 | |
| 1848 | case 'avatar': |
| 1849 | |
| 1850 | $avatars_enabled = false; |
| 1851 | /** @var \phpbb\avatar\manager $phpbb_avatar_manager */ |
| 1852 | $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); |
| 1853 | |
| 1854 | if ($config['allow_avatar']) |
| 1855 | { |
| 1856 | $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); |
| 1857 | |
| 1858 | // This is normalised data, without the user_ prefix |
| 1859 | $avatar_data = \phpbb\avatar\manager::clean_row($user_row, 'user'); |
| 1860 | |
| 1861 | if ($submit) |
| 1862 | { |
| 1863 | if (check_form_key($form_name)) |
| 1864 | { |
| 1865 | $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); |
| 1866 | |
| 1867 | if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) |
| 1868 | { |
| 1869 | $driver = $phpbb_avatar_manager->get_driver($driver_name); |
| 1870 | $result = $driver->process_form($request, $template, $user, $avatar_data, $error); |
| 1871 | |
| 1872 | if ($result && empty($error)) |
| 1873 | { |
| 1874 | // Success! Lets save the result in the database |
| 1875 | $result = array( |
| 1876 | 'user_avatar_type' => $driver_name, |
| 1877 | 'user_avatar' => $result['avatar'], |
| 1878 | 'user_avatar_width' => $result['avatar_width'], |
| 1879 | 'user_avatar_height' => $result['avatar_height'], |
| 1880 | ); |
| 1881 | |
| 1882 | /** |
| 1883 | * Modify users preferences data before assigning it to the template |
| 1884 | * |
| 1885 | * @event core.acp_users_avatar_sql |
| 1886 | * @var array user_row Array with user data |
| 1887 | * @var array result Array with user avatar data to be updated in the DB |
| 1888 | * @since 3.2.4-RC1 |
| 1889 | */ |
| 1890 | $vars = array('user_row', 'result'); |
| 1891 | extract($phpbb_dispatcher->trigger_event('core.acp_users_avatar_sql', compact($vars))); |
| 1892 | |
| 1893 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 1894 | SET ' . $db->sql_build_array('UPDATE', $result) . ' |
| 1895 | WHERE user_id = ' . (int) $user_id; |
| 1896 | $db->sql_query($sql); |
| 1897 | |
| 1898 | if ($request->is_ajax()) |
| 1899 | { |
| 1900 | $json_response = new \phpbb\json_response; |
| 1901 | $json_response->send([ |
| 1902 | 'success' => true, |
| 1903 | |
| 1904 | 'MESSAGE_TITLE' => $language->lang('INFORMATION'), |
| 1905 | 'MESSAGE_TEXT' => $language->lang('USER_AVATAR_UPDATED'), |
| 1906 | 'REFRESH_DATA' => [ |
| 1907 | 'time' => 3, |
| 1908 | 'url' => $this->u_action . '&u=' . $user_id, |
| 1909 | 'text' => $language->lang('BACK_TO_PREV'), |
| 1910 | ] |
| 1911 | ]); |
| 1912 | } |
| 1913 | else |
| 1914 | { |
| 1915 | trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | else |
| 1921 | { |
| 1922 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | // Handle deletion of avatars |
| 1927 | if ($request->is_set_post('avatar_delete')) |
| 1928 | { |
| 1929 | if (!confirm_box(true)) |
| 1930 | { |
| 1931 | confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array( |
| 1932 | 'avatar_delete' => true)) |
| 1933 | ); |
| 1934 | } |
| 1935 | else |
| 1936 | { |
| 1937 | $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_'); |
| 1938 | |
| 1939 | trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); |
| 1944 | |
| 1945 | // Assign min and max values before generating avatar driver html |
| 1946 | $template->assign_vars(array( |
| 1947 | 'AVATAR_MIN_WIDTH' => $config['avatar_min_width'], |
| 1948 | 'AVATAR_MAX_WIDTH' => $config['avatar_max_width'], |
| 1949 | 'AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], |
| 1950 | 'AVATAR_MAX_HEIGHT' => $config['avatar_max_height'], |
| 1951 | )); |
| 1952 | |
| 1953 | foreach ($avatar_drivers as $current_driver) |
| 1954 | { |
| 1955 | $driver = $phpbb_avatar_manager->get_driver($current_driver); |
| 1956 | |
| 1957 | $avatars_enabled = true; |
| 1958 | $template->set_filenames(array( |
| 1959 | 'avatar' => $driver->get_acp_template_name(), |
| 1960 | )); |
| 1961 | |
| 1962 | if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) |
| 1963 | { |
| 1964 | $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); |
| 1965 | $driver_upper = strtoupper($driver_name); |
| 1966 | |
| 1967 | $template->assign_block_vars('avatar_drivers', array( |
| 1968 | 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), |
| 1969 | 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), |
| 1970 | |
| 1971 | 'DRIVER' => $driver_name, |
| 1972 | 'SELECTED' => $current_driver == $selected_driver, |
| 1973 | 'OUTPUT' => $template->assign_display('avatar'), |
| 1974 | )); |
| 1975 | } |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | // Avatar manager is not initialized if avatars are disabled |
| 1980 | if (isset($phpbb_avatar_manager)) |
| 1981 | { |
| 1982 | // Replace "error" strings with their real, localised form |
| 1983 | $error = $phpbb_avatar_manager->localize_errors($user, $error); |
| 1984 | } |
| 1985 | |
| 1986 | /** @var \phpbb\avatar\helper $avatar_helper */ |
| 1987 | $avatar_helper = $phpbb_container->get('avatar.helper'); |
| 1988 | |
| 1989 | $avatar = $avatar_helper->get_user_avatar($user_row, 'USER_AVATAR', true); |
| 1990 | $template->assign_vars($avatar_helper->get_template_vars($avatar)); |
| 1991 | |
| 1992 | $template->assign_vars(array( |
| 1993 | 'S_AVATAR' => true, |
| 1994 | 'ERROR' => !empty($error) ? implode('<br />', $error) : '', |
| 1995 | |
| 1996 | 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', |
| 1997 | |
| 1998 | 'L_AVATAR_EXPLAIN' => $user->lang(($config['avatar_filesize'] == 0) ? 'AVATAR_EXPLAIN_NO_FILESIZE' : 'AVATAR_EXPLAIN', $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024), |
| 1999 | |
| 2000 | 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), |
| 2001 | )); |
| 2002 | |
| 2003 | break; |
| 2004 | |
| 2005 | case 'rank': |
| 2006 | |
| 2007 | if ($submit) |
| 2008 | { |
| 2009 | if (!check_form_key($form_name)) |
| 2010 | { |
| 2011 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2012 | } |
| 2013 | |
| 2014 | $rank_id = $request->variable('user_rank', 0); |
| 2015 | |
| 2016 | $sql = 'UPDATE ' . USERS_TABLE . " |
| 2017 | SET user_rank = $rank_id |
| 2018 | WHERE user_id = $user_id"; |
| 2019 | $db->sql_query($sql); |
| 2020 | |
| 2021 | trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 2022 | } |
| 2023 | |
| 2024 | $sql = 'SELECT * |
| 2025 | FROM ' . RANKS_TABLE . ' |
| 2026 | WHERE rank_special = 1 |
| 2027 | ORDER BY rank_title'; |
| 2028 | $result = $db->sql_query($sql); |
| 2029 | |
| 2030 | $s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>'; |
| 2031 | |
| 2032 | while ($row = $db->sql_fetchrow($result)) |
| 2033 | { |
| 2034 | $selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : ''; |
| 2035 | $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; |
| 2036 | } |
| 2037 | $db->sql_freeresult($result); |
| 2038 | |
| 2039 | $template->assign_vars(array( |
| 2040 | 'S_RANK' => true, |
| 2041 | 'S_RANK_OPTIONS' => $s_rank_options) |
| 2042 | ); |
| 2043 | |
| 2044 | break; |
| 2045 | |
| 2046 | case 'sig': |
| 2047 | |
| 2048 | if (!function_exists('display_custom_bbcodes')) |
| 2049 | { |
| 2050 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
| 2051 | } |
| 2052 | |
| 2053 | $enable_bbcode = ($config['allow_sig_bbcode']) ? $this->optionget($user_row, 'sig_bbcode') : false; |
| 2054 | $enable_smilies = ($config['allow_sig_smilies']) ? $this->optionget($user_row, 'sig_smilies') : false; |
| 2055 | $enable_urls = ($config['allow_sig_links']) ? $this->optionget($user_row, 'sig_links') : false; |
| 2056 | |
| 2057 | $bbcode_flags = ($enable_bbcode ? OPTION_FLAG_BBCODE : 0) + ($enable_smilies ? OPTION_FLAG_SMILIES : 0) + ($enable_urls ? OPTION_FLAG_LINKS : 0); |
| 2058 | |
| 2059 | $decoded_message = generate_text_for_edit($user_row['user_sig'], $user_row['user_sig_bbcode_uid'], $bbcode_flags); |
| 2060 | $signature = $request->variable('signature', $decoded_message['text'], true); |
| 2061 | $signature_preview = ''; |
| 2062 | |
| 2063 | if ($submit || $request->is_set_post('preview')) |
| 2064 | { |
| 2065 | $enable_bbcode = ($config['allow_sig_bbcode']) ? !$request->variable('disable_bbcode', false) : false; |
| 2066 | $enable_smilies = ($config['allow_sig_smilies']) ? !$request->variable('disable_smilies', false) : false; |
| 2067 | $enable_urls = ($config['allow_sig_links']) ? !$request->variable('disable_magic_url', false) : false; |
| 2068 | |
| 2069 | if (!check_form_key($form_name)) |
| 2070 | { |
| 2071 | $error[] = 'FORM_INVALID'; |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | $bbcode_uid = $bbcode_bitfield = $bbcode_flags = ''; |
| 2076 | $warn_msg = generate_text_for_storage( |
| 2077 | $signature, |
| 2078 | $bbcode_uid, |
| 2079 | $bbcode_bitfield, |
| 2080 | $bbcode_flags, |
| 2081 | $enable_bbcode, |
| 2082 | $enable_urls, |
| 2083 | $enable_smilies, |
| 2084 | $config['allow_sig_img'], |
| 2085 | true, |
| 2086 | $config['allow_sig_links'], |
| 2087 | 'sig' |
| 2088 | ); |
| 2089 | |
| 2090 | if (count($warn_msg)) |
| 2091 | { |
| 2092 | $error += $warn_msg; |
| 2093 | } |
| 2094 | |
| 2095 | if (!$submit) |
| 2096 | { |
| 2097 | // Parse it for displaying |
| 2098 | $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags); |
| 2099 | } |
| 2100 | else |
| 2101 | { |
| 2102 | if (!count($error)) |
| 2103 | { |
| 2104 | $this->optionset($user_row, 'sig_bbcode', $enable_bbcode); |
| 2105 | $this->optionset($user_row, 'sig_smilies', $enable_smilies); |
| 2106 | $this->optionset($user_row, 'sig_links', $enable_urls); |
| 2107 | |
| 2108 | $sql_ary = array( |
| 2109 | 'user_sig' => $signature, |
| 2110 | 'user_options' => $user_row['user_options'], |
| 2111 | 'user_sig_bbcode_uid' => $bbcode_uid, |
| 2112 | 'user_sig_bbcode_bitfield' => $bbcode_bitfield, |
| 2113 | ); |
| 2114 | |
| 2115 | /** |
| 2116 | * Modify user signature before it is stored in the DB |
| 2117 | * |
| 2118 | * @event core.acp_users_modify_signature_sql_ary |
| 2119 | * @var array user_row Array with user data |
| 2120 | * @var array sql_ary Array with user signature data to be updated in the DB |
| 2121 | * @since 3.2.4-RC1 |
| 2122 | */ |
| 2123 | $vars = array('user_row', 'sql_ary'); |
| 2124 | extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_signature_sql_ary', compact($vars))); |
| 2125 | |
| 2126 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 2127 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 2128 | WHERE user_id = ' . $user_id; |
| 2129 | $db->sql_query($sql); |
| 2130 | |
| 2131 | trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | // Replace "error" strings with their real, localised form |
| 2136 | $error = array_map(array($user, 'lang'), $error); |
| 2137 | |
| 2138 | if ($request->is_set_post('preview')) |
| 2139 | { |
| 2140 | $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_flags); |
| 2141 | } |
| 2142 | |
| 2143 | $template->assign_vars(array( |
| 2144 | 'S_SIGNATURE' => true, |
| 2145 | |
| 2146 | 'SIGNATURE' => $decoded_message['text'], |
| 2147 | 'SIGNATURE_PREVIEW' => $signature_preview, |
| 2148 | |
| 2149 | 'S_BBCODE_CHECKED' => (!$enable_bbcode) ? ' checked="checked"' : '', |
| 2150 | 'S_SMILIES_CHECKED' => (!$enable_smilies) ? ' checked="checked"' : '', |
| 2151 | 'S_MAGIC_URL_CHECKED' => (!$enable_urls) ? ' checked="checked"' : '', |
| 2152 | |
| 2153 | 'BBCODE_STATUS' => $user->lang(($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF'), '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</a>'), |
| 2154 | 'SMILIES_STATUS' => ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], |
| 2155 | 'IMG_STATUS' => ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], |
| 2156 | 'URL_STATUS' => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], |
| 2157 | |
| 2158 | 'L_SIGNATURE_EXPLAIN' => $user->lang('SIGNATURE_EXPLAIN', (int) $config['max_sig_chars']), |
| 2159 | |
| 2160 | 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], |
| 2161 | 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], |
| 2162 | 'S_BBCODE_IMG' => ($config['allow_sig_img']) ? true : false, |
| 2163 | 'S_LINKS_ALLOWED' => ($config['allow_sig_links']) ? true : false) |
| 2164 | ); |
| 2165 | |
| 2166 | // Assigning custom bbcodes |
| 2167 | display_custom_bbcodes(); |
| 2168 | |
| 2169 | break; |
| 2170 | |
| 2171 | case 'attach': |
| 2172 | /* @var $pagination \phpbb\pagination */ |
| 2173 | $pagination = $phpbb_container->get('pagination'); |
| 2174 | |
| 2175 | $start = $request->variable('start', 0); |
| 2176 | $deletemark = (isset($_POST['delmarked'])) ? true : false; |
| 2177 | $marked = $request->variable('mark', array(0)); |
| 2178 | |
| 2179 | // Sort keys |
| 2180 | $sort_key = $request->variable('sk', 'a'); |
| 2181 | $sort_dir = $request->variable('sd', 'd'); |
| 2182 | |
| 2183 | if ($deletemark && count($marked)) |
| 2184 | { |
| 2185 | $sql = 'SELECT attach_id |
| 2186 | FROM ' . ATTACHMENTS_TABLE . ' |
| 2187 | WHERE poster_id = ' . $user_id . ' |
| 2188 | AND is_orphan = 0 |
| 2189 | AND ' . $db->sql_in_set('attach_id', $marked); |
| 2190 | $result = $db->sql_query($sql); |
| 2191 | |
| 2192 | $marked = array(); |
| 2193 | while ($row = $db->sql_fetchrow($result)) |
| 2194 | { |
| 2195 | $marked[] = $row['attach_id']; |
| 2196 | } |
| 2197 | $db->sql_freeresult($result); |
| 2198 | } |
| 2199 | |
| 2200 | if ($deletemark && count($marked)) |
| 2201 | { |
| 2202 | if (confirm_box(true)) |
| 2203 | { |
| 2204 | $sql = 'SELECT real_filename |
| 2205 | FROM ' . ATTACHMENTS_TABLE . ' |
| 2206 | WHERE ' . $db->sql_in_set('attach_id', $marked); |
| 2207 | $result = $db->sql_query($sql); |
| 2208 | |
| 2209 | $log_attachments = array(); |
| 2210 | while ($row = $db->sql_fetchrow($result)) |
| 2211 | { |
| 2212 | $log_attachments[] = $row['real_filename']; |
| 2213 | } |
| 2214 | $db->sql_freeresult($result); |
| 2215 | |
| 2216 | /** @var \phpbb\attachment\manager $attachment_manager */ |
| 2217 | $attachment_manager = $phpbb_container->get('attachment.manager'); |
| 2218 | $attachment_manager->delete('attach', $marked); |
| 2219 | unset($attachment_manager); |
| 2220 | |
| 2221 | $message = (count($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']; |
| 2222 | |
| 2223 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode($user->lang['COMMA_SEPARATOR'], $log_attachments))); |
| 2224 | trigger_error($message . adm_back_link($this->u_action . '&u=' . $user_id)); |
| 2225 | } |
| 2226 | else |
| 2227 | { |
| 2228 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 2229 | 'u' => $user_id, |
| 2230 | 'i' => $id, |
| 2231 | 'mode' => $mode, |
| 2232 | 'action' => $action, |
| 2233 | 'delmarked' => true, |
| 2234 | 'mark' => $marked)) |
| 2235 | ); |
| 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']); |
| 2240 | $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title'); |
| 2241 | |
| 2242 | $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); |
| 2243 | |
| 2244 | $s_sort_key = ''; |
| 2245 | foreach ($sk_text as $key => $value) |
| 2246 | { |
| 2247 | $selected = ($sort_key == $key) ? ' selected="selected"' : ''; |
| 2248 | $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; |
| 2249 | } |
| 2250 | |
| 2251 | $s_sort_dir = ''; |
| 2252 | foreach ($sd_text as $key => $value) |
| 2253 | { |
| 2254 | $selected = ($sort_dir == $key) ? ' selected="selected"' : ''; |
| 2255 | $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; |
| 2256 | } |
| 2257 | |
| 2258 | if (!isset($sk_sql[$sort_key])) |
| 2259 | { |
| 2260 | $sort_key = 'a'; |
| 2261 | } |
| 2262 | |
| 2263 | $order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC'); |
| 2264 | |
| 2265 | $sql = 'SELECT COUNT(attach_id) as num_attachments |
| 2266 | FROM ' . ATTACHMENTS_TABLE . " |
| 2267 | WHERE poster_id = $user_id |
| 2268 | AND is_orphan = 0"; |
| 2269 | $result = $db->sql_query_limit($sql, 1); |
| 2270 | $num_attachments = (int) $db->sql_fetchfield('num_attachments'); |
| 2271 | $db->sql_freeresult($result); |
| 2272 | |
| 2273 | $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title |
| 2274 | FROM ' . ATTACHMENTS_TABLE . ' a |
| 2275 | LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id |
| 2276 | AND a.in_message = 0) |
| 2277 | LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id |
| 2278 | AND a.in_message = 1) |
| 2279 | WHERE a.poster_id = ' . $user_id . " |
| 2280 | AND a.is_orphan = 0 |
| 2281 | ORDER BY $order_by"; |
| 2282 | $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); |
| 2283 | |
| 2284 | while ($row = $db->sql_fetchrow($result)) |
| 2285 | { |
| 2286 | if ($row['in_message']) |
| 2287 | { |
| 2288 | $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&p={$row['post_msg_id']}"); |
| 2289 | } |
| 2290 | else |
| 2291 | { |
| 2292 | $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p={$row['post_msg_id']}") . '#p' . $row['post_msg_id']; |
| 2293 | } |
| 2294 | |
| 2295 | $template->assign_block_vars('attach', array( |
| 2296 | 'REAL_FILENAME' => $row['real_filename'], |
| 2297 | 'COMMENT' => nl2br($row['attach_comment']), |
| 2298 | 'EXTENSION' => $row['extension'], |
| 2299 | 'SIZE' => get_formatted_filesize($row['filesize']), |
| 2300 | 'DOWNLOAD_COUNT' => $row['download_count'], |
| 2301 | 'POST_TIME' => $user->format_date($row['filetime']), |
| 2302 | 'TOPIC_TITLE' => ($row['in_message']) ? $row['message_title'] : $row['topic_title'], |
| 2303 | |
| 2304 | 'ATTACH_ID' => $row['attach_id'], |
| 2305 | 'POST_ID' => $row['post_msg_id'], |
| 2306 | 'TOPIC_ID' => $row['topic_id'], |
| 2307 | |
| 2308 | 'S_IN_MESSAGE' => $row['in_message'], |
| 2309 | |
| 2310 | 'U_DOWNLOAD' => $controller_helper->route( |
| 2311 | 'phpbb_storage_attachment', |
| 2312 | [ |
| 2313 | 'id' => (int) $row['attach_id'], |
| 2314 | 'filename' => $row['real_filename'], |
| 2315 | ] |
| 2316 | ), |
| 2317 | 'U_VIEW_TOPIC' => $view_topic) |
| 2318 | ); |
| 2319 | } |
| 2320 | $db->sql_freeresult($result); |
| 2321 | |
| 2322 | $base_url = $this->u_action . "&u=$user_id&sk=$sort_key&sd=$sort_dir"; |
| 2323 | $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start); |
| 2324 | |
| 2325 | $template->assign_vars(array( |
| 2326 | 'S_ATTACHMENTS' => true, |
| 2327 | 'S_SORT_KEY' => $s_sort_key, |
| 2328 | 'S_SORT_DIR' => $s_sort_dir, |
| 2329 | )); |
| 2330 | |
| 2331 | break; |
| 2332 | |
| 2333 | case 'groups': |
| 2334 | |
| 2335 | if (!function_exists('group_user_attributes')) |
| 2336 | { |
| 2337 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 2338 | } |
| 2339 | |
| 2340 | $user->add_lang(array('groups', 'acp/groups')); |
| 2341 | $group_id = $request->variable('g', 0); |
| 2342 | |
| 2343 | if ($group_id) |
| 2344 | { |
| 2345 | // Check the founder only entry for this group to make sure everything is well |
| 2346 | $sql = 'SELECT group_founder_manage |
| 2347 | FROM ' . GROUPS_TABLE . ' |
| 2348 | WHERE group_id = ' . $group_id; |
| 2349 | $result = $db->sql_query($sql); |
| 2350 | $founder_manage = (int) $db->sql_fetchfield('group_founder_manage'); |
| 2351 | $db->sql_freeresult($result); |
| 2352 | |
| 2353 | if ($user->data['user_type'] != USER_FOUNDER && $founder_manage) |
| 2354 | { |
| 2355 | trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | switch ($action) |
| 2360 | { |
| 2361 | case 'demote': |
| 2362 | case 'promote': |
| 2363 | case 'default': |
| 2364 | if (!$group_id) |
| 2365 | { |
| 2366 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2367 | } |
| 2368 | |
| 2369 | if (!check_link_hash($request->variable('hash', ''), 'acp_users')) |
| 2370 | { |
| 2371 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); |
| 2372 | } |
| 2373 | |
| 2374 | group_user_attributes($action, $group_id, $user_id); |
| 2375 | |
| 2376 | if ($action == 'default') |
| 2377 | { |
| 2378 | $user_row['group_id'] = $group_id; |
| 2379 | } |
| 2380 | break; |
| 2381 | |
| 2382 | case 'delete': |
| 2383 | |
| 2384 | if (confirm_box(true)) |
| 2385 | { |
| 2386 | if (!$group_id) |
| 2387 | { |
| 2388 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2389 | } |
| 2390 | |
| 2391 | if ($error = group_user_del($group_id, $user_id)) |
| 2392 | { |
| 2393 | trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2394 | } |
| 2395 | |
| 2396 | $error = array(); |
| 2397 | |
| 2398 | // The delete action was successful - therefore update the user row... |
| 2399 | $sql = 'SELECT u.*, s.* |
| 2400 | FROM ' . USERS_TABLE . ' u |
| 2401 | LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) |
| 2402 | WHERE u.user_id = ' . $user_id . ' |
| 2403 | ORDER BY s.session_time DESC'; |
| 2404 | $result = $db->sql_query_limit($sql, 1); |
| 2405 | $user_row = $db->sql_fetchrow($result); |
| 2406 | $db->sql_freeresult($result); |
| 2407 | } |
| 2408 | else |
| 2409 | { |
| 2410 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 2411 | 'u' => $user_id, |
| 2412 | 'i' => $id, |
| 2413 | 'mode' => $mode, |
| 2414 | 'action' => $action, |
| 2415 | 'g' => $group_id)) |
| 2416 | ); |
| 2417 | } |
| 2418 | |
| 2419 | break; |
| 2420 | |
| 2421 | case 'approve': |
| 2422 | |
| 2423 | if (confirm_box(true)) |
| 2424 | { |
| 2425 | if (!$group_id) |
| 2426 | { |
| 2427 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2428 | } |
| 2429 | group_user_attributes($action, $group_id, $user_id); |
| 2430 | } |
| 2431 | else |
| 2432 | { |
| 2433 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 2434 | 'u' => $user_id, |
| 2435 | 'i' => $id, |
| 2436 | 'mode' => $mode, |
| 2437 | 'action' => $action, |
| 2438 | 'g' => $group_id)) |
| 2439 | ); |
| 2440 | } |
| 2441 | |
| 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | // Add user to group? |
| 2446 | if ($submit) |
| 2447 | { |
| 2448 | |
| 2449 | if (!check_form_key($form_name)) |
| 2450 | { |
| 2451 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2452 | } |
| 2453 | |
| 2454 | if (!$group_id) |
| 2455 | { |
| 2456 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2457 | } |
| 2458 | |
| 2459 | // Add user/s to group |
| 2460 | if ($error = group_user_add($group_id, $user_id)) |
| 2461 | { |
| 2462 | trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); |
| 2463 | } |
| 2464 | |
| 2465 | $error = array(); |
| 2466 | } |
| 2467 | |
| 2468 | /** @var \phpbb\group\helper $group_helper */ |
| 2469 | $group_helper = $phpbb_container->get('group_helper'); |
| 2470 | |
| 2471 | $sql = 'SELECT ug.*, g.* |
| 2472 | FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug |
| 2473 | WHERE ug.user_id = $user_id |
| 2474 | AND g.group_id = ug.group_id |
| 2475 | ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name"; |
| 2476 | $result = $db->sql_query($sql); |
| 2477 | |
| 2478 | $i = 0; |
| 2479 | $group_data = $id_ary = array(); |
| 2480 | while ($row = $db->sql_fetchrow($result)) |
| 2481 | { |
| 2482 | $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal'); |
| 2483 | |
| 2484 | $group_data[$type][$i]['group_id'] = $row['group_id']; |
| 2485 | $group_data[$type][$i]['group_name'] = $row['group_name']; |
| 2486 | $group_data[$type][$i]['group_leader'] = ($row['group_leader']) ? 1 : 0; |
| 2487 | |
| 2488 | $id_ary[] = $row['group_id']; |
| 2489 | |
| 2490 | $i++; |
| 2491 | } |
| 2492 | $db->sql_freeresult($result); |
| 2493 | |
| 2494 | // Select box for other groups |
| 2495 | $sql = 'SELECT group_id, group_name, group_type, group_founder_manage |
| 2496 | FROM ' . GROUPS_TABLE . ' |
| 2497 | ' . ((count($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . ' |
| 2498 | ORDER BY group_type DESC, group_name ASC'; |
| 2499 | $result = $db->sql_query($sql); |
| 2500 | |
| 2501 | $s_group_options = ''; |
| 2502 | while ($row = $db->sql_fetchrow($result)) |
| 2503 | { |
| 2504 | if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA') |
| 2505 | { |
| 2506 | continue; |
| 2507 | } |
| 2508 | |
| 2509 | // Do not display those groups not allowed to be managed |
| 2510 | if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage']) |
| 2511 | { |
| 2512 | continue; |
| 2513 | } |
| 2514 | |
| 2515 | $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>'; |
| 2516 | } |
| 2517 | $db->sql_freeresult($result); |
| 2518 | |
| 2519 | $current_type = ''; |
| 2520 | foreach ($group_data as $group_type => $data_ary) |
| 2521 | { |
| 2522 | if ($current_type != $group_type) |
| 2523 | { |
| 2524 | $template->assign_block_vars('group', array( |
| 2525 | 'S_NEW_GROUP_TYPE' => true, |
| 2526 | 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)]) |
| 2527 | ); |
| 2528 | } |
| 2529 | |
| 2530 | foreach ($data_ary as $data) |
| 2531 | { |
| 2532 | $template->assign_block_vars('group', array( |
| 2533 | 'U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=groups&mode=manage&action=edit&u=$user_id&g={$data['group_id']}&back_link=acp_users_groups"), |
| 2534 | 'U_DEFAULT' => $this->u_action . "&action=default&u=$user_id&g=" . $data['group_id'] . '&hash=' . generate_link_hash('acp_users'), |
| 2535 | 'U_DEMOTE_PROMOTE' => $this->u_action . '&action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&u=$user_id&g=" . $data['group_id'] . '&hash=' . generate_link_hash('acp_users'), |
| 2536 | 'U_DELETE' => count($id_ary) > 1 ? $this->u_action . "&action=delete&u=$user_id&g=" . $data['group_id'] : '', |
| 2537 | 'U_APPROVE' => ($group_type == 'pending') ? $this->u_action . "&action=approve&u=$user_id&g=" . $data['group_id'] : '', |
| 2538 | |
| 2539 | 'GROUP_NAME' => $group_helper->get_name($data['group_name']), |
| 2540 | 'L_DEMOTE_PROMOTE' => ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], |
| 2541 | |
| 2542 | 'S_IS_MEMBER' => ($group_type != 'pending') ? true : false, |
| 2543 | 'S_NO_DEFAULT' => ($user_row['group_id'] != $data['group_id']) ? true : false, |
| 2544 | 'S_SPECIAL_GROUP' => ($group_type == 'special') ? true : false, |
| 2545 | ) |
| 2546 | ); |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | $template->assign_vars(array( |
| 2551 | 'S_GROUPS' => true, |
| 2552 | 'S_GROUP_OPTIONS' => $s_group_options) |
| 2553 | ); |
| 2554 | |
| 2555 | break; |
| 2556 | |
| 2557 | case 'perm': |
| 2558 | |
| 2559 | if (!class_exists('auth_admin')) |
| 2560 | { |
| 2561 | include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); |
| 2562 | } |
| 2563 | |
| 2564 | $auth_admin = new auth_admin(); |
| 2565 | |
| 2566 | $user->add_lang('acp/permissions'); |
| 2567 | add_permission_language(); |
| 2568 | |
| 2569 | $forum_id = $request->variable('f', 0); |
| 2570 | |
| 2571 | // Global Permissions |
| 2572 | if (!$forum_id) |
| 2573 | { |
| 2574 | // Select auth options |
| 2575 | $sql = 'SELECT auth_option, is_local, is_global |
| 2576 | FROM ' . ACL_OPTIONS_TABLE . ' |
| 2577 | WHERE auth_option ' . $db->sql_like_expression($db->get_any_char() . '_') . ' |
| 2578 | AND is_global = 1 |
| 2579 | ORDER BY auth_option'; |
| 2580 | $result = $db->sql_query($sql); |
| 2581 | |
| 2582 | $hold_ary = array(); |
| 2583 | |
| 2584 | while ($row = $db->sql_fetchrow($result)) |
| 2585 | { |
| 2586 | $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER); |
| 2587 | $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false); |
| 2588 | } |
| 2589 | $db->sql_freeresult($result); |
| 2590 | |
| 2591 | unset($hold_ary); |
| 2592 | } |
| 2593 | else |
| 2594 | { |
| 2595 | $sql = 'SELECT auth_option, is_local, is_global |
| 2596 | FROM ' . ACL_OPTIONS_TABLE . " |
| 2597 | WHERE auth_option " . $db->sql_like_expression($db->get_any_char() . '_') . " |
| 2598 | AND is_local = 1 |
| 2599 | ORDER BY is_global DESC, auth_option"; |
| 2600 | $result = $db->sql_query($sql); |
| 2601 | |
| 2602 | while ($row = $db->sql_fetchrow($result)) |
| 2603 | { |
| 2604 | $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER); |
| 2605 | $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false); |
| 2606 | } |
| 2607 | $db->sql_freeresult($result); |
| 2608 | } |
| 2609 | |
| 2610 | $s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>'; |
| 2611 | $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false); |
| 2612 | |
| 2613 | $template->assign_vars(array( |
| 2614 | 'S_PERMISSIONS' => true, |
| 2615 | |
| 2616 | 'S_GLOBAL' => (!$forum_id) ? true : false, |
| 2617 | 'S_FORUM_OPTIONS' => $s_forum_options, |
| 2618 | |
| 2619 | 'U_ACTION' => $this->u_action . '&u=' . $user_id, |
| 2620 | 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&mode=setting_user_global&user_id[]=' . $user_id), |
| 2621 | 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&mode=setting_user_local&user_id[]=' . $user_id)) |
| 2622 | ); |
| 2623 | |
| 2624 | break; |
| 2625 | |
| 2626 | default: |
| 2627 | $u_action = $this->u_action; |
| 2628 | |
| 2629 | /** |
| 2630 | * Additional modes provided by extensions |
| 2631 | * |
| 2632 | * @event core.acp_users_mode_add |
| 2633 | * @var string mode New mode |
| 2634 | * @var int user_id User id of the user to manage |
| 2635 | * @var array user_row Array with user data |
| 2636 | * @var array error Array with errors data |
| 2637 | * @var string u_action The u_action link |
| 2638 | * @since 3.2.2-RC1 |
| 2639 | * @changed 3.2.10-RC1 Added u_action |
| 2640 | */ |
| 2641 | $vars = array('mode', 'user_id', 'user_row', 'error', 'u_action'); |
| 2642 | extract($phpbb_dispatcher->trigger_event('core.acp_users_mode_add', compact($vars))); |
| 2643 | |
| 2644 | unset($u_action); |
| 2645 | break; |
| 2646 | } |
| 2647 | |
| 2648 | // Assign general variables |
| 2649 | $template->assign_vars(array( |
| 2650 | 'S_ERROR' => (count($error)) ? true : false, |
| 2651 | 'ERROR_MSG' => (count($error)) ? implode('<br />', $error) : '') |
| 2652 | ); |
| 2653 | } |
| 2654 | |
| 2655 | /** |
| 2656 | * Set option bit field for user options in a user row array. |
| 2657 | * |
| 2658 | * Optionset replacement for this module based on $user->optionset. |
| 2659 | * |
| 2660 | * @param array $user_row Row from the users table. |
| 2661 | * @param int $key Option key, as defined in $user->keyoptions property. |
| 2662 | * @param bool $value True to set the option, false to clear the option. |
| 2663 | * @param int $data Current bit field value, or false to use $user_row['user_options'] |
| 2664 | * @return int|bool If $data is false, the bit field is modified and |
| 2665 | * written back to $user_row['user_options'], and |
| 2666 | * return value is true if the bit field changed and |
| 2667 | * false otherwise. If $data is not false, the new |
| 2668 | * bitfield value is returned. |
| 2669 | */ |
| 2670 | function optionset(&$user_row, $key, $value, $data = false) |
| 2671 | { |
| 2672 | global $user; |
| 2673 | |
| 2674 | $var = ($data !== false) ? $data : $user_row['user_options']; |
| 2675 | |
| 2676 | $new_var = phpbb_optionset($user->keyoptions[$key], $value, $var); |
| 2677 | |
| 2678 | if ($data === false) |
| 2679 | { |
| 2680 | if ($new_var != $var) |
| 2681 | { |
| 2682 | $user_row['user_options'] = $new_var; |
| 2683 | return true; |
| 2684 | } |
| 2685 | else |
| 2686 | { |
| 2687 | return false; |
| 2688 | } |
| 2689 | } |
| 2690 | else |
| 2691 | { |
| 2692 | return $new_var; |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * Get option bit field from user options in a user row array. |
| 2698 | * |
| 2699 | * Optionget replacement for this module based on $user->optionget. |
| 2700 | * |
| 2701 | * @param array $user_row Row from the users table. |
| 2702 | * @param int $key option key, as defined in $user->keyoptions property. |
| 2703 | * @param int $data bit field value to use, or false to use $user_row['user_options'] |
| 2704 | * @return bool true if the option is set in the bit field, false otherwise |
| 2705 | */ |
| 2706 | function optionget(&$user_row, $key, $data = false) |
| 2707 | { |
| 2708 | global $user; |
| 2709 | |
| 2710 | $var = ($data !== false) ? $data : $user_row['user_options']; |
| 2711 | return phpbb_optionget($user->keyoptions[$key], $var); |
| 2712 | } |
| 2713 | } |