[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/includes/acp/ -> acp_users.php (source)

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


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1