[ Index ]

PHP Cross Reference of phpBB-3.3.0-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'], 0),
 848                              array('password')),
 849                          'password_confirm'    => array('string', true, $config['min_pass_chars'], 0),
 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 += ['user_email'        => $update_email];
 970  
 971                              $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array(
 972                                  'reportee_id' => $user_id,
 973                                  $user_row['username'],
 974                                  $user_row['user_email'],
 975                                  $update_email
 976                              ));
 977                          }
 978  
 979                          if ($update_password)
 980                          {
 981                              $sql_ary += array(
 982                                  'user_password'        => $passwords_manager->hash($data['new_password']),
 983                                  'user_passchg'        => time(),
 984                              );
 985  
 986                              $user->reset_login_keys($user_id);
 987  
 988                              $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array(
 989                                  'reportee_id' => $user_id,
 990                                  $user_row['username']
 991                              ));
 992                          }
 993  
 994                          if (count($sql_ary))
 995                          {
 996                              $sql = 'UPDATE ' . USERS_TABLE . '
 997                                  SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 998                                  WHERE user_id = ' . $user_id;
 999                              $db->sql_query($sql);
1000                          }
1001  
1002                          if ($update_username)
1003                          {
1004                              user_update_name($user_row['username'], $update_username);
1005                          }
1006  
1007                          // Let the users permissions being updated
1008                          $auth->acl_clear_prefetch($user_id);
1009  
1010                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_USER_UPDATE', false, array($data['username']));
1011  
1012                          trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
1013                      }
1014  
1015                      // Replace "error" strings with their real, localised form
1016                      $error = array_map(array($user, 'lang'), $error);
1017                  }
1018  
1019                  if ($user_id == $user->data['user_id'])
1020                  {
1021                      $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
1022                      if ($user_row['user_new'])
1023                      {
1024                          $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
1025                      }
1026                  }
1027                  else
1028                  {
1029                      $quick_tool_ary = array();
1030  
1031                      if ($user_row['user_type'] != USER_FOUNDER)
1032                      {
1033                          $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
1034                      }
1035  
1036                      if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
1037                      {
1038                          $quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
1039                      }
1040  
1041                      $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
1042  
1043                      if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
1044                      {
1045                          $quick_tool_ary['reactivate'] = 'FORCE';
1046                      }
1047  
1048                      if ($user_row['user_new'])
1049                      {
1050                          $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
1051                      }
1052                  }
1053  
1054                  if ($config['load_onlinetrack'])
1055                  {
1056                      $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
1057                          FROM ' . SESSIONS_TABLE . "
1058                          WHERE session_user_id = $user_id";
1059                      $result = $db->sql_query($sql);
1060                      $row = $db->sql_fetchrow($result);
1061                      $db->sql_freeresult($result);
1062  
1063                      $user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
1064                      $user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
1065                      unset($row);
1066                  }
1067  
1068                  /**
1069                  * Add additional quick tool options and overwrite user data
1070                  *
1071                  * @event core.acp_users_display_overview
1072                  * @var    array    user_row            Array with user data
1073                  * @var    array    quick_tool_ary        Ouick tool options
1074                  * @since 3.1.0-a1
1075                  */
1076                  $vars = array('user_row', 'quick_tool_ary');
1077                  extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars)));
1078  
1079                  $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
1080                  foreach ($quick_tool_ary as $value => $lang)
1081                  {
1082                      $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
1083                  }
1084  
1085                  $last_active = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
1086  
1087                  $inactive_reason = '';
1088                  if ($user_row['user_type'] == USER_INACTIVE)
1089                  {
1090                      $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
1091  
1092                      switch ($user_row['user_inactive_reason'])
1093                      {
1094                          case INACTIVE_REGISTER:
1095                              $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
1096                          break;
1097  
1098                          case INACTIVE_PROFILE:
1099                              $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
1100                          break;
1101  
1102                          case INACTIVE_MANUAL:
1103                              $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
1104                          break;
1105  
1106                          case INACTIVE_REMIND:
1107                              $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
1108                          break;
1109                      }
1110                  }
1111  
1112                  // Posts in Queue
1113                  $sql = 'SELECT COUNT(post_id) as posts_in_queue
1114                      FROM ' . POSTS_TABLE . '
1115                      WHERE poster_id = ' . $user_id . '
1116                          AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
1117                  $result = $db->sql_query($sql);
1118                  $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
1119                  $db->sql_freeresult($result);
1120  
1121                  $sql = 'SELECT post_id
1122                      FROM ' . POSTS_TABLE . '
1123                      WHERE poster_id = '. $user_id;
1124                  $result = $db->sql_query_limit($sql, 1);
1125                  $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id');
1126                  $db->sql_freeresult($result);
1127  
1128                  $template->assign_vars(array(
1129                      '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'])),
1130                      'L_CHANGE_PASSWORD_EXPLAIN'    => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars'])),
1131                      'L_POSTS_IN_QUEUE'            => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']),
1132                      'S_FOUNDER'                    => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
1133  
1134                      'S_OVERVIEW'        => true,
1135                      'S_USER_IP'            => ($user_row['user_ip']) ? true : false,
1136                      'S_USER_FOUNDER'    => ($user_row['user_type'] == USER_FOUNDER) ? true : false,
1137                      'S_ACTION_OPTIONS'    => $s_action_options,
1138                      'S_OWN_ACCOUNT'        => ($user_id == $user->data['user_id']) ? true : false,
1139                      'S_USER_INACTIVE'    => ($user_row['user_type'] == USER_INACTIVE) ? true : false,
1140  
1141                      'U_SHOW_IP'        => $this->u_action . "&amp;u=$user_id&amp;ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
1142                      'U_WHOIS'        => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}",
1143                      'U_MCP_QUEUE'    => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
1144                      '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") : '',
1145  
1146                      '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')) : '',
1147  
1148                      'POSTS_IN_QUEUE'    => $user_row['posts_in_queue'],
1149                      'USER'                => $user_row['username'],
1150                      'USER_REGISTERED'    => $user->format_date($user_row['user_regdate']),
1151                      'REGISTERED_IP'        => ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
1152                      'USER_LASTACTIVE'    => ($last_active) ? $user->format_date($last_active) : ' - ',
1153                      'USER_EMAIL'        => $user_row['user_email'],
1154                      'USER_WARNINGS'        => $user_row['user_warnings'],
1155                      'USER_POSTS'        => $user_row['user_posts'],
1156                      'USER_HAS_POSTS'    => $user_row['user_has_posts'],
1157                      'USER_INACTIVE_REASON'    => $inactive_reason,
1158                  ));
1159  
1160              break;
1161  
1162              case 'feedback':
1163  
1164                  $user->add_lang('mcp');
1165  
1166                  // Set up general vars
1167                  $start        = $request->variable('start', 0);
1168                  $deletemark = (isset($_POST['delmarked'])) ? true : false;
1169                  $deleteall    = (isset($_POST['delall'])) ? true : false;
1170                  $marked        = $request->variable('mark', array(0));
1171                  $message    = $request->variable('message', '', true);
1172  
1173                  /* @var $pagination \phpbb\pagination */
1174                  $pagination = $phpbb_container->get('pagination');
1175  
1176                  // Sort keys
1177                  $sort_days    = $request->variable('st', 0);
1178                  $sort_key    = $request->variable('sk', 't');
1179                  $sort_dir    = $request->variable('sd', 'd');
1180  
1181                  // Delete entries if requested and able
1182                  if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
1183                  {
1184                      if (!check_form_key($form_name))
1185                      {
1186                          trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
1187                      }
1188  
1189                      $where_sql = '';
1190                      if ($deletemark && $marked)
1191                      {
1192                          $sql_in = array();
1193                          foreach ($marked as $mark)
1194                          {
1195                              $sql_in[] = $mark;
1196                          }
1197                          $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
1198                          unset($sql_in);
1199                      }
1200  
1201                      if ($where_sql || $deleteall)
1202                      {
1203                          $sql = 'DELETE FROM ' . LOG_TABLE . '
1204                              WHERE log_type = ' . LOG_USERS . "
1205                              AND reportee_id = $user_id
1206                              $where_sql";
1207                          $db->sql_query($sql);
1208  
1209                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CLEAR_USER', false, array($user_row['username']));
1210                      }
1211                  }
1212  
1213                  if ($submit && $message)
1214                  {
1215                      if (!check_form_key($form_name))
1216                      {
1217                          trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
1218                      }
1219  
1220                      $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array($user_row['username']));
1221                      $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array(
1222                          'forum_id' => 0,
1223                          'topic_id' => 0,
1224                          $user_row['username']
1225                      ));
1226                      $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GENERAL', false, array(
1227                          'reportee_id' => $user_id,
1228                          $message
1229                      ));
1230  
1231                      trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
1232                  }
1233  
1234                  // Sorting
1235                  $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']);
1236                  $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
1237                  $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
1238  
1239                  $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
1240                  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);
1241  
1242                  // Define where and sort sql for use in displaying logs
1243                  $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
1244                  $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
1245  
1246                  // Grab log data
1247                  $log_data = array();
1248                  $log_count = 0;
1249                  $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
1250  
1251                  $base_url = $this->u_action . "&amp;u=$user_id&amp;$u_sort_param";
1252                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
1253  
1254                  $template->assign_vars(array(
1255                      'S_FEEDBACK'    => true,
1256  
1257                      'S_LIMIT_DAYS'    => $s_limit_days,
1258                      'S_SORT_KEY'    => $s_sort_key,
1259                      'S_SORT_DIR'    => $s_sort_dir,
1260                      'S_CLEARLOGS'    => $auth->acl_get('a_clearlogs'))
1261                  );
1262  
1263                  foreach ($log_data as $row)
1264                  {
1265                      $template->assign_block_vars('log', array(
1266                          'USERNAME'        => $row['username_full'],
1267                          'IP'            => $row['ip'],
1268                          'DATE'            => $user->format_date($row['time']),
1269                          'ACTION'        => nl2br($row['action']),
1270                          'ID'            => $row['id'])
1271                      );
1272                  }
1273  
1274              break;
1275  
1276              case 'warnings':
1277                  $user->add_lang('mcp');
1278  
1279                  // Set up general vars
1280                  $deletemark    = (isset($_POST['delmarked'])) ? true : false;
1281                  $deleteall    = (isset($_POST['delall'])) ? true : false;
1282                  $confirm    = (isset($_POST['confirm'])) ? true : false;
1283                  $marked        = $request->variable('mark', array(0));
1284  
1285                  // Delete entries if requested and able
1286                  if ($deletemark || $deleteall || $confirm)
1287                  {
1288                      if (confirm_box(true))
1289                      {
1290                          $where_sql = '';
1291                          $deletemark = $request->variable('delmarked', 0);
1292                          $deleteall = $request->variable('delall', 0);
1293                          if ($deletemark && $marked)
1294                          {
1295                              $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
1296                          }
1297  
1298                          if ($where_sql || $deleteall)
1299                          {
1300                              $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
1301                                  WHERE user_id = $user_id
1302                                      $where_sql";
1303                              $db->sql_query($sql);
1304  
1305                              if ($deleteall)
1306                              {
1307                                  $log_warnings = $deleted_warnings = 0;
1308                              }
1309                              else
1310                              {
1311                                  $num_warnings = (int) $db->sql_affectedrows();
1312                                  $deleted_warnings = ' user_warnings - ' . $num_warnings;
1313                                  $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings;
1314                              }
1315  
1316                              $sql = 'UPDATE ' . USERS_TABLE . "
1317                                  SET user_warnings = $deleted_warnings
1318                                  WHERE user_id = $user_id";
1319                              $db->sql_query($sql);
1320  
1321                              if ($log_warnings)
1322                              {
1323                                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED', false, array($user_row['username'], $num_warnings));
1324                              }
1325                              else
1326                              {
1327                                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED_ALL', false, array($user_row['username']));
1328                              }
1329                          }
1330                      }
1331                      else
1332                      {
1333                          $s_hidden_fields = array(
1334                              'i'                => $id,
1335                              'mode'            => $mode,
1336                              'u'                => $user_id,
1337                              'mark'            => $marked,
1338                          );
1339                          if (isset($_POST['delmarked']))
1340                          {
1341                              $s_hidden_fields['delmarked'] = 1;
1342                          }
1343                          if (isset($_POST['delall']))
1344                          {
1345                              $s_hidden_fields['delall'] = 1;
1346                          }
1347                          if (isset($_POST['delall']) || (isset($_POST['delmarked']) && count($marked)))
1348                          {
1349                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
1350                          }
1351                      }
1352                  }
1353  
1354                  $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
1355                      FROM ' . WARNINGS_TABLE . ' w
1356                      LEFT JOIN ' . LOG_TABLE . ' l
1357                          ON (w.log_id = l.log_id)
1358                      LEFT JOIN ' . USERS_TABLE . ' m
1359                          ON (l.user_id = m.user_id)
1360                      WHERE w.user_id = ' . $user_id . '
1361                      ORDER BY w.warning_time DESC';
1362                  $result = $db->sql_query($sql);
1363  
1364                  while ($row = $db->sql_fetchrow($result))
1365                  {
1366                      if (!$row['log_operation'])
1367                      {
1368                          // We do not have a log-entry anymore, so there is no data available
1369                          $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
1370                      }
1371                      else
1372                      {
1373                          $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
1374                          if (!empty($row['log_data']))
1375                          {
1376                              $log_data_ary = @unserialize($row['log_data']);
1377                              $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
1378  
1379                              if (isset($user->lang[$row['log_operation']]))
1380                              {
1381                                  // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
1382                                  // It doesn't matter if we add more arguments than placeholders
1383                                  if ((substr_count($row['action'], '%') - count($log_data_ary)) > 0)
1384                                  {
1385                                      $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - count($log_data_ary), ''));
1386                                  }
1387                                  $row['action'] = vsprintf($row['action'], $log_data_ary);
1388                                  $row['action'] = bbcode_nl2br(censor_text($row['action']));
1389                              }
1390                              else if (!empty($log_data_ary))
1391                              {
1392                                  $row['action'] .= '<br />' . implode('', $log_data_ary);
1393                              }
1394                          }
1395                      }
1396  
1397                      $template->assign_block_vars('warn', array(
1398                          'ID'        => $row['warning_id'],
1399                          'USERNAME'    => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-',
1400                          'ACTION'    => make_clickable($row['action']),
1401                          'DATE'        => $user->format_date($row['warning_time']),
1402                      ));
1403                  }
1404                  $db->sql_freeresult($result);
1405  
1406                  $template->assign_vars(array(
1407                      'S_WARNINGS'    => true,
1408                  ));
1409  
1410              break;
1411  
1412              case 'profile':
1413  
1414                  if (!function_exists('user_get_id_name'))
1415                  {
1416                      include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1417                  }
1418  
1419                  /* @var $cp \phpbb\profilefields\manager */
1420                  $cp = $phpbb_container->get('profilefields.manager');
1421  
1422                  $cp_data = $cp_error = array();
1423  
1424                  $sql = 'SELECT lang_id
1425                      FROM ' . LANG_TABLE . "
1426                      WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
1427                  $result = $db->sql_query($sql);
1428                  $row = $db->sql_fetchrow($result);
1429                  $db->sql_freeresult($result);
1430  
1431                  $user_row['iso_lang_id'] = $row['lang_id'];
1432  
1433                  $data = array(
1434                      'jabber'        => $request->variable('jabber', $user_row['user_jabber'], true),
1435                      'bday_day'        => 0,
1436                      'bday_month'    => 0,
1437                      'bday_year'        => 0,
1438                  );
1439  
1440                  if ($user_row['user_birthday'])
1441                  {
1442                      list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
1443                  }
1444  
1445                  $data['bday_day']        = $request->variable('bday_day', $data['bday_day']);
1446                  $data['bday_month']        = $request->variable('bday_month', $data['bday_month']);
1447                  $data['bday_year']        = $request->variable('bday_year', $data['bday_year']);
1448                  $data['user_birthday']    = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
1449  
1450                  /**
1451                  * Modify user data on editing profile in ACP
1452                  *
1453                  * @event core.acp_users_modify_profile
1454                  * @var    array    data        Array with user profile data
1455                  * @var    bool    submit        Flag indicating if submit button has been pressed
1456                  * @var    int        user_id        The user id
1457                  * @var    array    user_row    Array with the full user data
1458                  * @since 3.1.4-RC1
1459                  */
1460                  $vars = array('data', 'submit', 'user_id', 'user_row');
1461                  extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_profile', compact($vars)));
1462  
1463                  if ($submit)
1464                  {
1465                      $error = validate_data($data, array(
1466                          'jabber'        => array(
1467                              array('string', true, 5, 255),
1468                              array('jabber')),
1469                          'bday_day'        => array('num', true, 1, 31),
1470                          'bday_month'    => array('num', true, 1, 12),
1471                          'bday_year'        => array('num', true, 1901, gmdate('Y', time())),
1472                          'user_birthday'    => array('date', true),
1473                      ));
1474  
1475                      // validate custom profile fields
1476                      $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
1477  
1478                      if (count($cp_error))
1479                      {
1480                          $error = array_merge($error, $cp_error);
1481                      }
1482                      if (!check_form_key($form_name))
1483                      {
1484                          $error[] = 'FORM_INVALID';
1485                      }
1486  
1487                      /**
1488                      * Validate profile data in ACP before submitting to the database
1489                      *
1490                      * @event core.acp_users_profile_validate
1491                      * @var    array    data        Array with user profile data
1492                      * @var    int        user_id        The user id
1493                      * @var    array    user_row    Array with the full user data
1494                      * @var    array    error        Array with the form errors
1495                      * @since 3.1.4-RC1
1496                      * @changed 3.1.12-RC1        Removed submit, added user_id, user_row
1497                      */
1498                      $vars = array('data', 'user_id', 'user_row', 'error');
1499                      extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_validate', compact($vars)));
1500  
1501                      if (!count($error))
1502                      {
1503                          $sql_ary = array(
1504                              'user_jabber'    => $data['jabber'],
1505                              'user_birthday'    => $data['user_birthday'],
1506                          );
1507  
1508                          /**
1509                          * Modify profile data in ACP before submitting to the database
1510                          *
1511                          * @event core.acp_users_profile_modify_sql_ary
1512                          * @var    array    cp_data        Array with the user custom profile fields data
1513                          * @var    array    data        Array with user profile data
1514                          * @var    int        user_id        The user id
1515                          * @var    array    user_row    Array with the full user data
1516                          * @var    array    sql_ary        Array with sql data
1517                          * @since 3.1.4-RC1
1518                          */
1519                          $vars = array('cp_data', 'data', 'user_id', 'user_row', 'sql_ary');
1520                          extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_modify_sql_ary', compact($vars)));
1521  
1522                          $sql = 'UPDATE ' . USERS_TABLE . '
1523                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
1524                              WHERE user_id = $user_id";
1525                          $db->sql_query($sql);
1526  
1527                          // Update Custom Fields
1528                          $cp->update_profile_field_data($user_id, $cp_data);
1529  
1530                          trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
1531                      }
1532  
1533                      // Replace "error" strings with their real, localised form
1534                      $error = array_map(array($user, 'lang'), $error);
1535                  }
1536  
1537                  $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
1538                  for ($i = 1; $i < 32; $i++)
1539                  {
1540                      $selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
1541                      $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
1542                  }
1543  
1544                  $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
1545                  for ($i = 1; $i < 13; $i++)
1546                  {
1547                      $selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
1548                      $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
1549                  }
1550  
1551                  $now = getdate();
1552                  $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
1553                  for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
1554                  {
1555                      $selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
1556                      $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
1557                  }
1558                  unset($now);
1559  
1560                  $template->assign_vars(array(
1561                      'JABBER'        => $data['jabber'],
1562                      'S_BIRTHDAY_DAY_OPTIONS'    => $s_birthday_day_options,
1563                      'S_BIRTHDAY_MONTH_OPTIONS'    => $s_birthday_month_options,
1564                      'S_BIRTHDAY_YEAR_OPTIONS'    => $s_birthday_year_options,
1565  
1566                      'S_PROFILE'        => true)
1567                  );
1568  
1569                  // Get additional profile fields and assign them to the template block var 'profile_fields'
1570                  $user->get_profile_fields($user_id);
1571  
1572                  $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
1573  
1574              break;
1575  
1576              case 'prefs':
1577  
1578                  if (!function_exists('user_get_id_name'))
1579                  {
1580                      include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1581                  }
1582  
1583                  $data = array(
1584                      'dateformat'        => $request->variable('dateformat', $user_row['user_dateformat'], true),
1585                      'lang'                => basename($request->variable('lang', $user_row['user_lang'])),
1586                      'tz'                => $request->variable('tz', $user_row['user_timezone']),
1587                      'style'                => $request->variable('style', $user_row['user_style']),
1588                      'viewemail'            => $request->variable('viewemail', $user_row['user_allow_viewemail']),
1589                      'massemail'            => $request->variable('massemail', $user_row['user_allow_massemail']),
1590                      'hideonline'        => $request->variable('hideonline', !$user_row['user_allow_viewonline']),
1591                      'notifymethod'        => $request->variable('notifymethod', $user_row['user_notify_type']),
1592                      'notifypm'            => $request->variable('notifypm', $user_row['user_notify_pm']),
1593                      'allowpm'            => $request->variable('allowpm', $user_row['user_allow_pm']),
1594  
1595                      'topic_sk'            => $request->variable('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
1596                      'topic_sd'            => $request->variable('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
1597                      'topic_st'            => $request->variable('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),
1598  
1599                      'post_sk'            => $request->variable('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
1600                      'post_sd'            => $request->variable('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
1601                      'post_st'            => $request->variable('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),
1602  
1603                      'view_images'        => $request->variable('view_images', $this->optionget($user_row, 'viewimg')),
1604                      'view_flash'        => $request->variable('view_flash', $this->optionget($user_row, 'viewflash')),
1605                      'view_smilies'        => $request->variable('view_smilies', $this->optionget($user_row, 'viewsmilies')),
1606                      'view_sigs'            => $request->variable('view_sigs', $this->optionget($user_row, 'viewsigs')),
1607                      'view_avatars'        => $request->variable('view_avatars', $this->optionget($user_row, 'viewavatars')),
1608                      'view_wordcensor'    => $request->variable('view_wordcensor', $this->optionget($user_row, 'viewcensors')),
1609  
1610                      'bbcode'    => $request->variable('bbcode', $this->optionget($user_row, 'bbcode')),
1611                      'smilies'    => $request->variable('smilies', $this->optionget($user_row, 'smilies')),
1612                      'sig'        => $request->variable('sig', $this->optionget($user_row, 'attachsig')),
1613                      'notify'    => $request->variable('notify', $user_row['user_notify']),
1614                  );
1615  
1616                  /**
1617                  * Modify users preferences data
1618                  *
1619                  * @event core.acp_users_prefs_modify_data
1620                  * @var    array    data            Array with users preferences data
1621                  * @var    array    user_row        Array with user data
1622                  * @since 3.1.0-b3
1623                  */
1624                  $vars = array('data', 'user_row');
1625                  extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_data', compact($vars)));
1626  
1627                  if ($submit)
1628                  {
1629                      $error = validate_data($data, array(
1630                          'dateformat'    => array('string', false, 1, 64),
1631                          'lang'            => array('match', false, '#^[a-z_\-]{2,}$#i'),
1632                          'tz'            => array('timezone'),
1633  
1634                          'topic_sk'        => array('string', false, 1, 1),
1635                          'topic_sd'        => array('string', false, 1, 1),
1636                          'post_sk'        => array('string', false, 1, 1),
1637                          'post_sd'        => array('string', false, 1, 1),
1638                      ));
1639  
1640                      if (!check_form_key($form_name))
1641                      {
1642                          $error[] = 'FORM_INVALID';
1643                      }
1644  
1645                      if (!count($error))
1646                      {
1647                          $this->optionset($user_row, 'viewimg', $data['view_images']);
1648                          $this->optionset($user_row, 'viewflash', $data['view_flash']);
1649                          $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
1650                          $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
1651                          $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
1652                          $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
1653                          $this->optionset($user_row, 'bbcode', $data['bbcode']);
1654                          $this->optionset($user_row, 'smilies', $data['smilies']);
1655                          $this->optionset($user_row, 'attachsig', $data['sig']);
1656  
1657                          $sql_ary = array(
1658                              'user_options'            => $user_row['user_options'],
1659  
1660                              'user_allow_pm'            => $data['allowpm'],
1661                              'user_allow_viewemail'    => $data['viewemail'],
1662                              'user_allow_massemail'    => $data['massemail'],
1663                              'user_allow_viewonline'    => !$data['hideonline'],
1664                              'user_notify_type'        => $data['notifymethod'],
1665                              'user_notify_pm'        => $data['notifypm'],
1666  
1667                              'user_dateformat'        => $data['dateformat'],
1668                              'user_lang'                => $data['lang'],
1669                              'user_timezone'            => $data['tz'],
1670                              'user_style'            => $data['style'],
1671  
1672                              'user_topic_sortby_type'    => $data['topic_sk'],
1673                              'user_post_sortby_type'        => $data['post_sk'],
1674                              'user_topic_sortby_dir'        => $data['topic_sd'],
1675                              'user_post_sortby_dir'        => $data['post_sd'],
1676  
1677                              'user_topic_show_days'    => $data['topic_st'],
1678                              'user_post_show_days'    => $data['post_st'],
1679  
1680                              'user_notify'    => $data['notify'],
1681                          );
1682  
1683                          /**
1684                          * Modify SQL query before users preferences are updated
1685                          *
1686                          * @event core.acp_users_prefs_modify_sql
1687                          * @var    array    data            Array with users preferences data
1688                          * @var    array    user_row        Array with user data
1689                          * @var    array    sql_ary            SQL array with users preferences data to update
1690                          * @var    array    error            Array with errors data
1691                          * @since 3.1.0-b3
1692                          */
1693                          $vars = array('data', 'user_row', 'sql_ary', 'error');
1694                          extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_sql', compact($vars)));
1695  
1696                          if (!count($error))
1697                          {
1698                              $sql = 'UPDATE ' . USERS_TABLE . '
1699                                  SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
1700                                  WHERE user_id = $user_id";
1701                              $db->sql_query($sql);
1702  
1703                              // Check if user has an active session
1704                              if ($user_row['session_id'])
1705                              {
1706                                  // We'll update the session if user_allow_viewonline has changed and the user is a bot
1707                                  // Or if it's a regular user and the admin set it to hide the session
1708                                  if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE
1709                                      || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline'])
1710                                  {
1711                                      // We also need to check if the user has the permission to cloak.
1712                                      $user_auth = new \phpbb\auth\auth();
1713                                      $user_auth->acl($user_row);
1714  
1715                                      $session_sql_ary = array(
1716                                          'session_viewonline'    => ($user_auth->acl_get('u_hideonline')) ? $sql_ary['user_allow_viewonline'] : true,
1717                                      );
1718  
1719                                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
1720                                          SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "
1721                                          WHERE session_user_id = $user_id";
1722                                      $db->sql_query($sql);
1723  
1724                                      unset($user_auth);
1725                                  }
1726                              }
1727  
1728                              trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
1729                          }
1730                      }
1731  
1732                      // Replace "error" strings with their real, localised form
1733                      $error = array_map(array($user, 'lang'), $error);
1734                  }
1735  
1736                  $dateformat_options = '';
1737                  foreach ($user->lang['dateformats'] as $format => $null)
1738                  {
1739                      $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
1740                      $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
1741                      $dateformat_options .= '</option>';
1742                  }
1743  
1744                  $s_custom = false;
1745  
1746                  $dateformat_options .= '<option value="custom"';
1747                  if (!isset($user->lang['dateformats'][$data['dateformat']]))
1748                  {
1749                      $dateformat_options .= ' selected="selected"';
1750                      $s_custom = true;
1751                  }
1752                  $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
1753  
1754                  $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
1755  
1756                  // Topic ordering options
1757                  $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']);
1758                  $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']);
1759  
1760                  // Post ordering options
1761                  $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']);
1762                  $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
1763  
1764                  $_options = array('topic', 'post');
1765                  foreach ($_options as $sort_option)
1766                  {
1767                      ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
1768                      foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
1769                      {
1770                          $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
1771                          ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
1772                      }
1773                      ${'s_limit_' . $sort_option . '_days'} .= '</select>';
1774  
1775                      ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
1776                      foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
1777                      {
1778                          $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
1779                          ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
1780                      }
1781                      ${'s_sort_' . $sort_option . '_key'} .= '</select>';
1782  
1783                      ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
1784                      foreach ($sort_dir_text as $key => $value)
1785                      {
1786                          $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
1787                          ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1788                      }
1789                      ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
1790                  }
1791  
1792                  phpbb_timezone_select($template, $user, $data['tz'], true);
1793                  $user_prefs_data = array(
1794                      'S_PREFS'            => true,
1795                      'S_JABBER_DISABLED'    => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
1796  
1797                      'VIEW_EMAIL'        => $data['viewemail'],
1798                      'MASS_EMAIL'        => $data['massemail'],
1799                      'ALLOW_PM'            => $data['allowpm'],
1800                      'HIDE_ONLINE'        => $data['hideonline'],
1801                      'NOTIFY_EMAIL'        => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
1802                      'NOTIFY_IM'            => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
1803                      'NOTIFY_BOTH'        => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
1804                      'NOTIFY_PM'            => $data['notifypm'],
1805                      'BBCODE'            => $data['bbcode'],
1806                      'SMILIES'            => $data['smilies'],
1807                      'ATTACH_SIG'        => $data['sig'],
1808                      'NOTIFY'            => $data['notify'],
1809                      'VIEW_IMAGES'        => $data['view_images'],
1810                      'VIEW_FLASH'        => $data['view_flash'],
1811                      'VIEW_SMILIES'        => $data['view_smilies'],
1812                      'VIEW_SIGS'            => $data['view_sigs'],
1813                      'VIEW_AVATARS'        => $data['view_avatars'],
1814                      'VIEW_WORDCENSOR'    => $data['view_wordcensor'],
1815  
1816                      'S_TOPIC_SORT_DAYS'        => $s_limit_topic_days,
1817                      'S_TOPIC_SORT_KEY'        => $s_sort_topic_key,
1818                      'S_TOPIC_SORT_DIR'        => $s_sort_topic_dir,
1819                      'S_POST_SORT_DAYS'        => $s_limit_post_days,
1820                      'S_POST_SORT_KEY'        => $s_sort_post_key,
1821                      'S_POST_SORT_DIR'        => $s_sort_post_dir,
1822  
1823                      'DATE_FORMAT'            => $data['dateformat'],
1824                      'S_DATEFORMAT_OPTIONS'    => $dateformat_options,
1825                      'S_CUSTOM_DATEFORMAT'    => $s_custom,
1826                      'DEFAULT_DATEFORMAT'    => $config['default_dateformat'],
1827                      'A_DEFAULT_DATEFORMAT'    => addslashes($config['default_dateformat']),
1828  
1829                      'S_LANG_OPTIONS'    => language_select($data['lang']),
1830                      'S_STYLE_OPTIONS'    => style_select($data['style']),
1831                  );
1832  
1833                  /**
1834                  * Modify users preferences data before assigning it to the template
1835                  *
1836                  * @event core.acp_users_prefs_modify_template_data
1837                  * @var    array    data                Array with users preferences data
1838                  * @var    array    user_row            Array with user data
1839                  * @var    array    user_prefs_data        Array with users preferences data to be assigned to the template
1840                  * @since 3.1.0-b3
1841                  */
1842                  $vars = array('data', 'user_row', 'user_prefs_data');
1843                  extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_template_data', compact($vars)));
1844  
1845                  $template->assign_vars($user_prefs_data);
1846  
1847              break;
1848  
1849              case 'avatar':
1850  
1851                  $avatars_enabled = false;
1852                  /** @var \phpbb\avatar\manager $phpbb_avatar_manager */
1853                  $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
1854  
1855                  if ($config['allow_avatar'])
1856                  {
1857                      $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers();
1858  
1859                      // This is normalised data, without the user_ prefix
1860                      $avatar_data = \phpbb\avatar\manager::clean_row($user_row, 'user');
1861  
1862                      if ($submit)
1863                      {
1864                          if (check_form_key($form_name))
1865                          {
1866                              $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', ''));
1867  
1868                              if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete'))
1869                              {
1870                                  $driver = $phpbb_avatar_manager->get_driver($driver_name);
1871                                  $result = $driver->process_form($request, $template, $user, $avatar_data, $error);
1872  
1873                                  if ($result && empty($error))
1874                                  {
1875                                      // Success! Lets save the result in the database
1876                                      $result = array(
1877                                          'user_avatar_type' => $driver_name,
1878                                          'user_avatar' => $result['avatar'],
1879                                          'user_avatar_width' => $result['avatar_width'],
1880                                          'user_avatar_height' => $result['avatar_height'],
1881                                      );
1882  
1883                                      /**
1884                                      * Modify users preferences data before assigning it to the template
1885                                      *
1886                                      * @event core.acp_users_avatar_sql
1887                                      * @var    array    user_row    Array with user data
1888                                      * @var    array    result        Array with user avatar data to be updated in the DB
1889                                      * @since 3.2.4-RC1
1890                                      */
1891                                      $vars = array('user_row', 'result');
1892                                      extract($phpbb_dispatcher->trigger_event('core.acp_users_avatar_sql', compact($vars)));
1893  
1894                                      $sql = 'UPDATE ' . USERS_TABLE . '
1895                                          SET ' . $db->sql_build_array('UPDATE', $result) . '
1896                                          WHERE user_id = ' . (int) $user_id;
1897  
1898                                      $db->sql_query($sql);
1899                                      trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
1900                                  }
1901                              }
1902                          }
1903                          else
1904                          {
1905                              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
1906                          }
1907                      }
1908  
1909                      // Handle deletion of avatars
1910                      if ($request->is_set_post('avatar_delete'))
1911                      {
1912                          if (!confirm_box(true))
1913                          {
1914                              confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array(
1915                                      'avatar_delete'     => true))
1916                              );
1917                          }
1918                          else
1919                          {
1920                              $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_');
1921  
1922                              trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
1923                          }
1924                      }
1925  
1926                      $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type']));
1927  
1928                      // Assign min and max values before generating avatar driver html
1929                      $template->assign_vars(array(
1930                          'AVATAR_MIN_WIDTH'        => $config['avatar_min_width'],
1931                          'AVATAR_MAX_WIDTH'        => $config['avatar_max_width'],
1932                          'AVATAR_MIN_HEIGHT'        => $config['avatar_min_height'],
1933                          'AVATAR_MAX_HEIGHT'        => $config['avatar_max_height'],
1934                      ));
1935  
1936                      foreach ($avatar_drivers as $current_driver)
1937                      {
1938                          $driver = $phpbb_avatar_manager->get_driver($current_driver);
1939  
1940                          $avatars_enabled = true;
1941                          $template->set_filenames(array(
1942                              'avatar' => $driver->get_acp_template_name(),
1943                          ));
1944  
1945                          if ($driver->prepare_form($request, $template, $user, $avatar_data, $error))
1946                          {
1947                              $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver);
1948                              $driver_upper = strtoupper($driver_name);
1949  
1950                              $template->assign_block_vars('avatar_drivers', array(
1951                                  'L_TITLE' => $user->lang($driver_upper . '_TITLE'),
1952                                  'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'),
1953  
1954                                  'DRIVER' => $driver_name,
1955                                  'SELECTED' => $current_driver == $selected_driver,
1956                                  'OUTPUT' => $template->assign_display('avatar'),
1957                              ));
1958                          }
1959                      }
1960                  }
1961  
1962                  // Avatar manager is not initialized if avatars are disabled
1963                  if (isset($phpbb_avatar_manager))
1964                  {
1965                      // Replace "error" strings with their real, localised form
1966                      $error = $phpbb_avatar_manager->localize_errors($user, $error);
1967                  }
1968  
1969                  $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true);
1970  
1971                  $template->assign_vars(array(
1972                      'S_AVATAR'    => true,
1973                      'ERROR'            => (!empty($error)) ? implode('<br />', $error) : '',
1974                      'AVATAR'        => (empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar),
1975  
1976                      'S_FORM_ENCTYPE'    => ' enctype="multipart/form-data"',
1977  
1978                      '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),
1979  
1980                      'S_AVATARS_ENABLED'        => ($config['allow_avatar'] && $avatars_enabled),
1981                  ));
1982  
1983              break;
1984  
1985              case 'rank':
1986  
1987                  if ($submit)
1988                  {
1989                      if (!check_form_key($form_name))
1990                      {
1991                          trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
1992                      }
1993  
1994                      $rank_id = $request->variable('user_rank', 0);
1995  
1996                      $sql = 'UPDATE ' . USERS_TABLE . "
1997                          SET user_rank = $rank_id
1998                          WHERE user_id = $user_id";
1999                      $db->sql_query($sql);
2000  
2001                      trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
2002                  }
2003  
2004                  $sql = 'SELECT *
2005                      FROM ' . RANKS_TABLE . '
2006                      WHERE rank_special = 1
2007                      ORDER BY rank_title';
2008                  $result = $db->sql_query($sql);
2009  
2010                  $s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
2011  
2012                  while ($row = $db->sql_fetchrow($result))
2013                  {
2014                      $selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : '';
2015                      $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
2016                  }
2017                  $db->sql_freeresult($result);
2018  
2019                  $template->assign_vars(array(
2020                      'S_RANK'            => true,
2021                      'S_RANK_OPTIONS'    => $s_rank_options)
2022                  );
2023  
2024              break;
2025  
2026              case 'sig':
2027  
2028                  if (!function_exists('display_custom_bbcodes'))
2029                  {
2030                      include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
2031                  }
2032  
2033                  $enable_bbcode    = ($config['allow_sig_bbcode']) ? $this->optionget($user_row, 'sig_bbcode') : false;
2034                  $enable_smilies    = ($config['allow_sig_smilies']) ? $this->optionget($user_row, 'sig_smilies') : false;
2035                  $enable_urls    = ($config['allow_sig_links']) ? $this->optionget($user_row, 'sig_links') : false;
2036  
2037                  $bbcode_flags = ($enable_bbcode ? OPTION_FLAG_BBCODE : 0) + ($enable_smilies ? OPTION_FLAG_SMILIES : 0) + ($enable_urls ? OPTION_FLAG_LINKS : 0);
2038  
2039                  $decoded_message    = generate_text_for_edit($user_row['user_sig'], $user_row['user_sig_bbcode_uid'], $bbcode_flags);
2040                  $signature            = $request->variable('signature', $decoded_message['text'], true);
2041                  $signature_preview    = '';
2042  
2043                  if ($submit || $request->is_set_post('preview'))
2044                  {
2045                      $enable_bbcode    = ($config['allow_sig_bbcode']) ? !$request->variable('disable_bbcode', false) : false;
2046                      $enable_smilies    = ($config['allow_sig_smilies']) ? !$request->variable('disable_smilies', false) : false;
2047                      $enable_urls    = ($config['allow_sig_links']) ? !$request->variable('disable_magic_url', false) : false;
2048  
2049                      if (!check_form_key($form_name))
2050                      {
2051                          $error[] = 'FORM_INVALID';
2052                      }
2053                  }
2054  
2055                  $bbcode_uid = $bbcode_bitfield = $bbcode_flags = '';
2056                  $warn_msg = generate_text_for_storage(
2057                      $signature,
2058                      $bbcode_uid,
2059                      $bbcode_bitfield,
2060                      $bbcode_flags,
2061                      $enable_bbcode,
2062                      $enable_urls,
2063                      $enable_smilies,
2064                      $config['allow_sig_img'],
2065                      $config['allow_sig_flash'],
2066                      true,
2067                      $config['allow_sig_links'],
2068                      'sig'
2069                  );
2070  
2071                  if (count($warn_msg))
2072                  {
2073                      $error += $warn_msg;
2074                  }
2075  
2076                  if (!$submit)
2077                  {
2078                      // Parse it for displaying
2079                      $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags);
2080                  }
2081                  else
2082                  {
2083                      if (!count($error))
2084                      {
2085                          $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
2086                          $this->optionset($user_row, 'sig_smilies', $enable_smilies);
2087                          $this->optionset($user_row, 'sig_links', $enable_urls);
2088  
2089                          $sql_ary = array(
2090                              'user_sig'                    => $signature,
2091                              'user_options'                => $user_row['user_options'],
2092                              'user_sig_bbcode_uid'        => $bbcode_uid,
2093                              'user_sig_bbcode_bitfield'    => $bbcode_bitfield,
2094                          );
2095  
2096                          /**
2097                          * Modify user signature before it is stored in the DB
2098                          *
2099                          * @event core.acp_users_modify_signature_sql_ary
2100                          * @var    array    user_row    Array with user data
2101                          * @var    array    sql_ary        Array with user signature data to be updated in the DB
2102                          * @since 3.2.4-RC1
2103                          */
2104                          $vars = array('user_row', 'sql_ary');
2105                          extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_signature_sql_ary', compact($vars)));
2106  
2107                          $sql = 'UPDATE ' . USERS_TABLE . '
2108                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
2109                              WHERE user_id = ' . $user_id;
2110                          $db->sql_query($sql);
2111  
2112                          trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
2113                      }
2114                  }
2115  
2116                  // Replace "error" strings with their real, localised form
2117                  $error = array_map(array($user, 'lang'), $error);
2118  
2119                  if ($request->is_set_post('preview'))
2120                  {
2121                      $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_flags);
2122                  }
2123  
2124                  /** @var \phpbb\controller\helper $controller_helper */
2125                  $controller_helper = $phpbb_container->get('controller.helper');
2126  
2127                  $template->assign_vars(array(
2128                      'S_SIGNATURE'        => true,
2129  
2130                      'SIGNATURE'            => $decoded_message['text'],
2131                      'SIGNATURE_PREVIEW'    => $signature_preview,
2132  
2133                      'S_BBCODE_CHECKED'        => (!$enable_bbcode) ? ' checked="checked"' : '',
2134                      'S_SMILIES_CHECKED'        => (!$enable_smilies) ? ' checked="checked"' : '',
2135                      'S_MAGIC_URL_CHECKED'    => (!$enable_urls) ? ' checked="checked"' : '',
2136  
2137                      'BBCODE_STATUS'            => $user->lang(($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF'), '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</a>'),
2138                      'SMILIES_STATUS'        => ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
2139                      'IMG_STATUS'            => ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
2140                      'FLASH_STATUS'            => ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
2141                      'URL_STATUS'            => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
2142  
2143                      'L_SIGNATURE_EXPLAIN'    => $user->lang('SIGNATURE_EXPLAIN', (int) $config['max_sig_chars']),
2144  
2145                      'S_BBCODE_ALLOWED'        => $config['allow_sig_bbcode'],
2146                      'S_SMILIES_ALLOWED'        => $config['allow_sig_smilies'],
2147                      'S_BBCODE_IMG'            => ($config['allow_sig_img']) ? true : false,
2148                      'S_BBCODE_FLASH'        => ($config['allow_sig_flash']) ? true : false,
2149                      'S_LINKS_ALLOWED'        => ($config['allow_sig_links']) ? true : false)
2150                  );
2151  
2152                  // Assigning custom bbcodes
2153                  display_custom_bbcodes();
2154  
2155              break;
2156  
2157              case 'attach':
2158                  /* @var $pagination \phpbb\pagination */
2159                  $pagination = $phpbb_container->get('pagination');
2160  
2161                  $start        = $request->variable('start', 0);
2162                  $deletemark = (isset($_POST['delmarked'])) ? true : false;
2163                  $marked        = $request->variable('mark', array(0));
2164  
2165                  // Sort keys
2166                  $sort_key    = $request->variable('sk', 'a');
2167                  $sort_dir    = $request->variable('sd', 'd');
2168  
2169                  if ($deletemark && count($marked))
2170                  {
2171                      $sql = 'SELECT attach_id
2172                          FROM ' . ATTACHMENTS_TABLE . '
2173                          WHERE poster_id = ' . $user_id . '
2174                              AND is_orphan = 0
2175                              AND ' . $db->sql_in_set('attach_id', $marked);
2176                      $result = $db->sql_query($sql);
2177  
2178                      $marked = array();
2179                      while ($row = $db->sql_fetchrow($result))
2180                      {
2181                          $marked[] = $row['attach_id'];
2182                      }
2183                      $db->sql_freeresult($result);
2184                  }
2185  
2186                  if ($deletemark && count($marked))
2187                  {
2188                      if (confirm_box(true))
2189                      {
2190                          $sql = 'SELECT real_filename
2191                              FROM ' . ATTACHMENTS_TABLE . '
2192                              WHERE ' . $db->sql_in_set('attach_id', $marked);
2193                          $result = $db->sql_query($sql);
2194  
2195                          $log_attachments = array();
2196                          while ($row = $db->sql_fetchrow($result))
2197                          {
2198                              $log_attachments[] = $row['real_filename'];
2199                          }
2200                          $db->sql_freeresult($result);
2201  
2202                          /** @var \phpbb\attachment\manager $attachment_manager */
2203                          $attachment_manager = $phpbb_container->get('attachment.manager');
2204                          $attachment_manager->delete('attach', $marked);
2205                          unset($attachment_manager);
2206  
2207                          $message = (count($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
2208  
2209                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode($user->lang['COMMA_SEPARATOR'], $log_attachments)));
2210                          trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
2211                      }
2212                      else
2213                      {
2214                          confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
2215                              'u'                => $user_id,
2216                              'i'                => $id,
2217                              'mode'            => $mode,
2218                              'action'        => $action,
2219                              'delmarked'        => true,
2220                              'mark'            => $marked))
2221                          );
2222                      }
2223                  }
2224  
2225                  $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']);
2226                  $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
2227  
2228                  $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
2229  
2230                  $s_sort_key = '';
2231                  foreach ($sk_text as $key => $value)
2232                  {
2233                      $selected = ($sort_key == $key) ? ' selected="selected"' : '';
2234                      $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
2235                  }
2236  
2237                  $s_sort_dir = '';
2238                  foreach ($sd_text as $key => $value)
2239                  {
2240                      $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
2241                      $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
2242                  }
2243  
2244                  if (!isset($sk_sql[$sort_key]))
2245                  {
2246                      $sort_key = 'a';
2247                  }
2248  
2249                  $order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
2250  
2251                  $sql = 'SELECT COUNT(attach_id) as num_attachments
2252                      FROM ' . ATTACHMENTS_TABLE . "
2253                      WHERE poster_id = $user_id
2254                          AND is_orphan = 0";
2255                  $result = $db->sql_query_limit($sql, 1);
2256                  $num_attachments = (int) $db->sql_fetchfield('num_attachments');
2257                  $db->sql_freeresult($result);
2258  
2259                  $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
2260                      FROM ' . ATTACHMENTS_TABLE . ' a
2261                          LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
2262                              AND a.in_message = 0)
2263                          LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
2264                              AND a.in_message = 1)
2265                      WHERE a.poster_id = ' . $user_id . "
2266                          AND a.is_orphan = 0
2267                      ORDER BY $order_by";
2268                  $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
2269  
2270                  while ($row = $db->sql_fetchrow($result))
2271                  {
2272                      if ($row['in_message'])
2273                      {
2274                          $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
2275                      }
2276                      else
2277                      {
2278                          $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
2279                      }
2280  
2281                      $template->assign_block_vars('attach', array(
2282                          'REAL_FILENAME'        => $row['real_filename'],
2283                          'COMMENT'            => nl2br($row['attach_comment']),
2284                          'EXTENSION'            => $row['extension'],
2285                          'SIZE'                => get_formatted_filesize($row['filesize']),
2286                          'DOWNLOAD_COUNT'    => $row['download_count'],
2287                          'POST_TIME'            => $user->format_date($row['filetime']),
2288                          'TOPIC_TITLE'        => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
2289  
2290                          'ATTACH_ID'            => $row['attach_id'],
2291                          'POST_ID'            => $row['post_msg_id'],
2292                          'TOPIC_ID'            => $row['topic_id'],
2293  
2294                          'S_IN_MESSAGE'        => $row['in_message'],
2295  
2296                          'U_DOWNLOAD'        => append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . $row['attach_id']),
2297                          'U_VIEW_TOPIC'        => $view_topic)
2298                      );
2299                  }
2300                  $db->sql_freeresult($result);
2301  
2302                  $base_url = $this->u_action . "&amp;u=$user_id&amp;sk=$sort_key&amp;sd=$sort_dir";
2303                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
2304  
2305                  $template->assign_vars(array(
2306                      'S_ATTACHMENTS'        => true,
2307                      'S_SORT_KEY'        => $s_sort_key,
2308                      'S_SORT_DIR'        => $s_sort_dir,
2309                  ));
2310  
2311              break;
2312  
2313              case 'groups':
2314  
2315                  if (!function_exists('group_user_attributes'))
2316                  {
2317                      include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
2318                  }
2319  
2320                  $user->add_lang(array('groups', 'acp/groups'));
2321                  $group_id = $request->variable('g', 0);
2322  
2323                  if ($group_id)
2324                  {
2325                      // Check the founder only entry for this group to make sure everything is well
2326                      $sql = 'SELECT group_founder_manage
2327                          FROM ' . GROUPS_TABLE . '
2328                          WHERE group_id = ' . $group_id;
2329                      $result = $db->sql_query($sql);
2330                      $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
2331                      $db->sql_freeresult($result);
2332  
2333                      if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
2334                      {
2335                          trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2336                      }
2337                  }
2338  
2339                  switch ($action)
2340                  {
2341                      case 'demote':
2342                      case 'promote':
2343                      case 'default':
2344                          if (!$group_id)
2345                          {
2346                              trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2347                          }
2348  
2349                          if (!check_link_hash($request->variable('hash', ''), 'acp_users'))
2350                          {
2351                              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
2352                          }
2353  
2354                          group_user_attributes($action, $group_id, $user_id);
2355  
2356                          if ($action == 'default')
2357                          {
2358                              $user_row['group_id'] = $group_id;
2359                          }
2360                      break;
2361  
2362                      case 'delete':
2363  
2364                          if (confirm_box(true))
2365                          {
2366                              if (!$group_id)
2367                              {
2368                                  trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2369                              }
2370  
2371                              if ($error = group_user_del($group_id, $user_id))
2372                              {
2373                                  trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2374                              }
2375  
2376                              $error = array();
2377  
2378                              // The delete action was successful - therefore update the user row...
2379                              $sql = 'SELECT u.*, s.*
2380                                  FROM ' . USERS_TABLE . ' u
2381                                      LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
2382                                  WHERE u.user_id = ' . $user_id . '
2383                                  ORDER BY s.session_time DESC';
2384                              $result = $db->sql_query_limit($sql, 1);
2385                              $user_row = $db->sql_fetchrow($result);
2386                              $db->sql_freeresult($result);
2387                          }
2388                          else
2389                          {
2390                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
2391                                  'u'                => $user_id,
2392                                  'i'                => $id,
2393                                  'mode'            => $mode,
2394                                  'action'        => $action,
2395                                  'g'                => $group_id))
2396                              );
2397                          }
2398  
2399                      break;
2400  
2401                      case 'approve':
2402  
2403                          if (confirm_box(true))
2404                          {
2405                              if (!$group_id)
2406                              {
2407                                  trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2408                              }
2409                              group_user_attributes($action, $group_id, $user_id);
2410                          }
2411                          else
2412                          {
2413                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
2414                                  'u'                => $user_id,
2415                                  'i'                => $id,
2416                                  'mode'            => $mode,
2417                                  'action'        => $action,
2418                                  'g'                => $group_id))
2419                              );
2420                          }
2421  
2422                      break;
2423                  }
2424  
2425                  // Add user to group?
2426                  if ($submit)
2427                  {
2428  
2429                      if (!check_form_key($form_name))
2430                      {
2431                          trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2432                      }
2433  
2434                      if (!$group_id)
2435                      {
2436                          trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2437                      }
2438  
2439                      // Add user/s to group
2440                      if ($error = group_user_add($group_id, $user_id))
2441                      {
2442                          trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
2443                      }
2444  
2445                      $error = array();
2446                  }
2447  
2448                  /** @var \phpbb\group\helper $group_helper */
2449                  $group_helper = $phpbb_container->get('group_helper');
2450  
2451                  $sql = 'SELECT ug.*, g.*
2452                      FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
2453                      WHERE ug.user_id = $user_id
2454                          AND g.group_id = ug.group_id
2455                      ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
2456                  $result = $db->sql_query($sql);
2457  
2458                  $i = 0;
2459                  $group_data = $id_ary = array();
2460                  while ($row = $db->sql_fetchrow($result))
2461                  {
2462                      $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal');
2463  
2464                      $group_data[$type][$i]['group_id']        = $row['group_id'];
2465                      $group_data[$type][$i]['group_name']    = $row['group_name'];
2466                      $group_data[$type][$i]['group_leader']    = ($row['group_leader']) ? 1 : 0;
2467  
2468                      $id_ary[] = $row['group_id'];
2469  
2470                      $i++;
2471                  }
2472                  $db->sql_freeresult($result);
2473  
2474                  // Select box for other groups
2475                  $sql = 'SELECT group_id, group_name, group_type, group_founder_manage
2476                      FROM ' . GROUPS_TABLE . '
2477                      ' . ((count($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
2478                      ORDER BY group_type DESC, group_name ASC';
2479                  $result = $db->sql_query($sql);
2480  
2481                  $s_group_options = '';
2482                  while ($row = $db->sql_fetchrow($result))
2483                  {
2484                      if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
2485                      {
2486                          continue;
2487                      }
2488  
2489                      // Do not display those groups not allowed to be managed
2490                      if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
2491                      {
2492                          continue;
2493                      }
2494  
2495                      $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>';
2496                  }
2497                  $db->sql_freeresult($result);
2498  
2499                  $current_type = '';
2500                  foreach ($group_data as $group_type => $data_ary)
2501                  {
2502                      if ($current_type != $group_type)
2503                      {
2504                          $template->assign_block_vars('group', array(
2505                              'S_NEW_GROUP_TYPE'        => true,
2506                              'GROUP_TYPE'            => $user->lang['USER_GROUP_' . strtoupper($group_type)])
2507                          );
2508                      }
2509  
2510                      foreach ($data_ary as $data)
2511                      {
2512                          $template->assign_block_vars('group', array(
2513                              '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"),
2514                              'U_DEFAULT'            => $this->u_action . "&amp;action=default&amp;u=$user_id&amp;g=" . $data['group_id'] . '&amp;hash=' . generate_link_hash('acp_users'),
2515                              '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'),
2516                              'U_DELETE'            => $this->u_action . "&amp;action=delete&amp;u=$user_id&amp;g=" . $data['group_id'],
2517                              'U_APPROVE'            => ($group_type == 'pending') ? $this->u_action . "&amp;action=approve&amp;u=$user_id&amp;g=" . $data['group_id'] : '',
2518  
2519                              'GROUP_NAME'        => $group_helper->get_name($data['group_name']),
2520                              'L_DEMOTE_PROMOTE'    => ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],
2521  
2522                              'S_IS_MEMBER'        => ($group_type != 'pending') ? true : false,
2523                              'S_NO_DEFAULT'        => ($user_row['group_id'] != $data['group_id']) ? true : false,
2524                              'S_SPECIAL_GROUP'    => ($group_type == 'special') ? true : false,
2525                              )
2526                          );
2527                      }
2528                  }
2529  
2530                  $template->assign_vars(array(
2531                      'S_GROUPS'            => true,
2532                      'S_GROUP_OPTIONS'    => $s_group_options)
2533                  );
2534  
2535              break;
2536  
2537              case 'perm':
2538  
2539                  if (!class_exists('auth_admin'))
2540                  {
2541                      include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
2542                  }
2543  
2544                  $auth_admin = new auth_admin();
2545  
2546                  $user->add_lang('acp/permissions');
2547                  add_permission_language();
2548  
2549                  $forum_id = $request->variable('f', 0);
2550  
2551                  // Global Permissions
2552                  if (!$forum_id)
2553                  {
2554                      // Select auth options
2555                      $sql = 'SELECT auth_option, is_local, is_global
2556                          FROM ' . ACL_OPTIONS_TABLE . '
2557                          WHERE auth_option ' . $db->sql_like_expression($db->get_any_char() . '_') . '
2558                              AND is_global = 1
2559                          ORDER BY auth_option';
2560                      $result = $db->sql_query($sql);
2561  
2562                      $hold_ary = array();
2563  
2564                      while ($row = $db->sql_fetchrow($result))
2565                      {
2566                          $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
2567                          $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
2568                      }
2569                      $db->sql_freeresult($result);
2570  
2571                      unset($hold_ary);
2572                  }
2573                  else
2574                  {
2575                      $sql = 'SELECT auth_option, is_local, is_global
2576                          FROM ' . ACL_OPTIONS_TABLE . "
2577                          WHERE auth_option " . $db->sql_like_expression($db->get_any_char() . '_') . "
2578                              AND is_local = 1
2579                          ORDER BY is_global DESC, auth_option";
2580                      $result = $db->sql_query($sql);
2581  
2582                      while ($row = $db->sql_fetchrow($result))
2583                      {
2584                          $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
2585                          $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
2586                      }
2587                      $db->sql_freeresult($result);
2588                  }
2589  
2590                  $s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
2591                  $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
2592  
2593                  $template->assign_vars(array(
2594                      'S_PERMISSIONS'                => true,
2595  
2596                      'S_GLOBAL'                    => (!$forum_id) ? true : false,
2597                      'S_FORUM_OPTIONS'            => $s_forum_options,
2598  
2599                      'U_ACTION'                    => $this->u_action . '&amp;u=' . $user_id,
2600                      'U_USER_PERMISSIONS'        => append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id),
2601                      'U_USER_FORUM_PERMISSIONS'    => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id))
2602                  );
2603  
2604              break;
2605  
2606              default:
2607  
2608                  /**
2609                  * Additional modes provided by extensions
2610                  *
2611                  * @event core.acp_users_mode_add
2612                  * @var    string    mode            New mode
2613                  * @var    int        user_id            User id of the user to manage
2614                  * @var    array    user_row        Array with user data
2615                  * @var    array    error            Array with errors data
2616                  * @since 3.2.2-RC1
2617                  */
2618                  $vars = array('mode', 'user_id', 'user_row', 'error');
2619                  extract($phpbb_dispatcher->trigger_event('core.acp_users_mode_add', compact($vars)));
2620  
2621              break;
2622          }
2623  
2624          // Assign general variables
2625          $template->assign_vars(array(
2626              'S_ERROR'            => (count($error)) ? true : false,
2627              'ERROR_MSG'            => (count($error)) ? implode('<br />', $error) : '')
2628          );
2629      }
2630  
2631      /**
2632      * Set option bit field for user options in a user row array.
2633      *
2634      * Optionset replacement for this module based on $user->optionset.
2635      *
2636      * @param array $user_row Row from the users table.
2637      * @param int $key Option key, as defined in $user->keyoptions property.
2638      * @param bool $value True to set the option, false to clear the option.
2639      * @param int $data Current bit field value, or false to use $user_row['user_options']
2640      * @return int|bool If $data is false, the bit field is modified and
2641      *                  written back to $user_row['user_options'], and
2642      *                  return value is true if the bit field changed and
2643      *                  false otherwise. If $data is not false, the new
2644      *                  bitfield value is returned.
2645      */
2646  	function optionset(&$user_row, $key, $value, $data = false)
2647      {
2648          global $user;
2649  
2650          $var = ($data !== false) ? $data : $user_row['user_options'];
2651  
2652          $new_var = phpbb_optionset($user->keyoptions[$key], $value, $var);
2653  
2654          if ($data === false)
2655          {
2656              if ($new_var != $var)
2657              {
2658                  $user_row['user_options'] = $new_var;
2659                  return true;
2660              }
2661              else
2662              {
2663                  return false;
2664              }
2665          }
2666          else
2667          {
2668              return $new_var;
2669          }
2670      }
2671  
2672      /**
2673      * Get option bit field from user options in a user row array.
2674      *
2675      * Optionget replacement for this module based on $user->optionget.
2676      *
2677      * @param array $user_row Row from the users table.
2678      * @param int $key option key, as defined in $user->keyoptions property.
2679      * @param int $data bit field value to use, or false to use $user_row['user_options']
2680      * @return bool true if the option is set in the bit field, false otherwise
2681      */
2682  	function optionget(&$user_row, $key, $data = false)
2683      {
2684          global $user;
2685  
2686          $var = ($data !== false) ? $data : $user_row['user_options'];
2687          return phpbb_optionget($user->keyoptions[$key], $var);
2688      }
2689  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1