Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_permissions.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 40.19 KiB


0001  <?php
0002  /**
0003  *
0004  * This file is part of the phpBB Forum Software package.
0005  *
0006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
0007  * @license GNU General Public License, version 2 (GPL-2.0)
0008  *
0009  * For full copyright and license information, please see
0010  * the docs/CREDITS.txt file.
0011  *
0012  */
0013   
0014  /**
0015  * @ignore
0016  */
0017  if (!defined('IN_PHPBB'))
0018  {
0019      exit;
0020  }
0021   
0022  class acp_permissions
0023  {
0024      var $u_action;
0025      var $permission_dropdown;
0026   
0027      /**
0028       * @var $phpbb_permissions \phpbb\permissions
0029       */
0030      protected $permissions;
0031   
0032      function main($id, $mode)
0033      {
0034          global $db, $user, $auth, $template, $phpbb_container, $request;
0035          global $config, $phpbb_root_path, $phpEx;
0036   
0037          if (!function_exists('user_get_id_name'))
0038          {
0039              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
0040          }
0041   
0042          if (!class_exists('auth_admin'))
0043          {
0044              include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
0045          }
0046   
0047          $this->permissions = $phpbb_container->get('acl.permissions');
0048   
0049          $auth_admin = new auth_admin();
0050   
0051          $user->add_lang('acp/permissions');
0052          add_permission_language();
0053   
0054          $this->tpl_name = 'acp_permissions';
0055   
0056          // Trace has other vars
0057          if ($mode == 'trace')
0058          {
0059              $user_id = $request->variable('u', 0);
0060              $forum_id = $request->variable('f', 0);
0061              $permission = $request->variable('auth', '');
0062   
0063              $this->tpl_name = 'permission_trace';
0064   
0065              if ($user_id && isset($auth_admin->acl_options['id'][$permission]) && $auth->acl_get('a_viewauth'))
0066              {
0067                  $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $this->permissions->get_permission_lang($permission));
0068                  $this->permission_trace($user_id, $forum_id, $permission);
0069                  return;
0070              }
0071              trigger_error('NO_MODE', E_USER_ERROR);
0072          }
0073   
0074          // Copy forum permissions
0075          if ($mode == 'setting_forum_copy')
0076          {
0077              $this->tpl_name = 'permission_forum_copy';
0078   
0079              if ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
0080              {
0081                  $this->page_title = 'ACP_FORUM_PERMISSIONS_COPY';
0082                  $this->copy_forum_permissions();
0083                  return;
0084              }
0085   
0086              trigger_error('NO_MODE', E_USER_ERROR);
0087          }
0088   
0089          // Set some vars
0090          $action = $request->variable('action', array('' => 0));
0091          $action = key($action);
0092          $action = (isset($_POST['psubmit'])) ? 'apply_permissions' : $action;
0093   
0094          $all_forums = $request->variable('all_forums', 0);
0095          $subforum_id = $request->variable('subforum_id', 0);
0096          $forum_id = $request->variable('forum_id', array(0));
0097   
0098          $username = $request->variable('username', array(''), true);
0099          $usernames = $request->variable('usernames', '', true);
0100          $user_id = $request->variable('user_id', array(0));
0101   
0102          $group_id = $request->variable('group_id', array(0));
0103          $select_all_groups = $request->variable('select_all_groups', 0);
0104   
0105          $form_name = 'acp_permissions';
0106          add_form_key($form_name);
0107   
0108          // If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen)
0109          if ($select_all_groups)
0110          {
0111              // Add default groups to selection
0112              $sql_and = (!$config['coppa_enable']) ? " AND group_name <> 'REGISTERED_COPPA'" : '';
0113   
0114              $sql = 'SELECT group_id
0115                  FROM ' . GROUPS_TABLE . '
0116                  WHERE group_type = ' . GROUP_SPECIAL . "
0117                  $sql_and";
0118              $result = $db->sql_query($sql);
0119   
0120              while ($row = $db->sql_fetchrow($result))
0121              {
0122                  $group_id[] = $row['group_id'];
0123              }
0124              $db->sql_freeresult($result);
0125          }
0126   
0127          // Map usernames to ids and vice versa
0128          if ($usernames)
0129          {
0130              $username = explode("\n", $usernames);
0131          }
0132          unset($usernames);
0133   
0134          if (sizeof($username) && !sizeof($user_id))
0135          {
0136              user_get_id_name($user_id, $username);
0137   
0138              if (!sizeof($user_id))
0139              {
0140                  trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
0141              }
0142          }
0143          unset($username);
0144   
0145          // Build forum ids (of all forums are checked or subforum listing used)
0146          if ($all_forums)
0147          {
0148              $sql = 'SELECT forum_id
0149                  FROM ' . FORUMS_TABLE . '
0150                  ORDER BY left_id';
0151              $result = $db->sql_query($sql);
0152   
0153              $forum_id = array();
0154              while ($row = $db->sql_fetchrow($result))
0155              {
0156                  $forum_id[] = (int) $row['forum_id'];
0157              }
0158              $db->sql_freeresult($result);
0159          }
0160          else if ($subforum_id)
0161          {
0162              $forum_id = array();
0163              foreach (get_forum_branch($subforum_id, 'children') as $row)
0164              {
0165                  $forum_id[] = (int) $row['forum_id'];
0166              }
0167          }
0168   
0169          // Define some common variables for every mode
0170          $permission_scope = (strpos($mode, '_global') !== false) ? 'global' : 'local';
0171   
0172          // Showing introductionary page?
0173          if ($mode == 'intro')
0174          {
0175              $this->page_title = 'ACP_PERMISSIONS';
0176   
0177              $template->assign_vars(array(
0178                  'S_INTRO'        => true)
0179              );
0180   
0181              return;
0182          }
0183   
0184          switch ($mode)
0185          {
0186              case 'setting_user_global':
0187              case 'setting_group_global':
0188                  $this->permission_dropdown = array('u_', 'm_', 'a_');
0189                  $permission_victim = ($mode == 'setting_user_global') ? array('user') : array('group');
0190                  $this->page_title = ($mode == 'setting_user_global') ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS';
0191              break;
0192   
0193              case 'setting_user_local':
0194              case 'setting_group_local':
0195                  $this->permission_dropdown = array('f_', 'm_');
0196                  $permission_victim = ($mode == 'setting_user_local') ? array('user', 'forums') : array('group', 'forums');
0197                  $this->page_title = ($mode == 'setting_user_local') ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS';
0198              break;
0199   
0200              case 'setting_admin_global':
0201              case 'setting_mod_global':
0202                  $this->permission_dropdown = (strpos($mode, '_admin_') !== false) ? array('a_') : array('m_');
0203                  $permission_victim = array('usergroup');
0204                  $this->page_title = ($mode == 'setting_admin_global') ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS';
0205              break;
0206   
0207              case 'setting_mod_local':
0208              case 'setting_forum_local':
0209                  $this->permission_dropdown = ($mode == 'setting_mod_local') ? array('m_') : array('f_');
0210                  $permission_victim = array('forums', 'usergroup');
0211                  $this->page_title = ($mode == 'setting_mod_local') ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS';
0212              break;
0213   
0214              case 'view_admin_global':
0215              case 'view_user_global':
0216              case 'view_mod_global':
0217                  $this->permission_dropdown = ($mode == 'view_admin_global') ? array('a_') : (($mode == 'view_user_global') ? array('u_') : array('m_'));
0218                  $permission_victim = array('usergroup_view');
0219                  $this->page_title = ($mode == 'view_admin_global') ? 'ACP_VIEW_ADMIN_PERMISSIONS' : (($mode == 'view_user_global') ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS');
0220              break;
0221   
0222              case 'view_mod_local':
0223              case 'view_forum_local':
0224                  $this->permission_dropdown = ($mode == 'view_mod_local') ? array('m_') : array('f_');
0225                  $permission_victim = array('forums', 'usergroup_view');
0226                  $this->page_title = ($mode == 'view_mod_local') ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS';
0227              break;
0228   
0229              default:
0230                  trigger_error('NO_MODE', E_USER_ERROR);
0231              break;
0232          }
0233   
0234          $template->assign_vars(array(
0235              'L_TITLE'        => $user->lang[$this->page_title],
0236              'L_EXPLAIN'        => $user->lang[$this->page_title . '_EXPLAIN'])
0237          );
0238   
0239          // Get permission type
0240          $permission_type = $request->variable('type', $this->permission_dropdown[0]);
0241   
0242          if (!in_array($permission_type, $this->permission_dropdown))
0243          {
0244              trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
0245          }
0246   
0247          // Handle actions
0248          if (strpos($mode, 'setting_') === 0 && $action)
0249          {
0250              switch ($action)
0251              {
0252                  case 'delete':
0253                      if (confirm_box(true))
0254                      {
0255                          // All users/groups selected?
0256                          $all_users = (isset($_POST['all_users'])) ? true : false;
0257                          $all_groups = (isset($_POST['all_groups'])) ? true : false;
0258   
0259                          if ($all_users || $all_groups)
0260                          {
0261                              $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
0262   
0263                              if ($all_users && sizeof($items['user_ids']))
0264                              {
0265                                  $user_id = $items['user_ids'];
0266                              }
0267                              else if ($all_groups && sizeof($items['group_ids']))
0268                              {
0269                                  $group_id = $items['group_ids'];
0270                              }
0271                          }
0272   
0273                          if (sizeof($user_id) || sizeof($group_id))
0274                          {
0275                              $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id);
0276                          }
0277                          else
0278                          {
0279                              trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
0280                          }
0281                      }
0282                      else
0283                      {
0284                          if (isset($_POST['cancel']))
0285                          {
0286                              $u_redirect = $this->u_action . '&amp;type=' . $permission_type;
0287                              foreach ($forum_id as $fid)
0288                              {
0289                                  $u_redirect .= '&amp;forum_id[]=' . $fid;
0290                              }
0291                              redirect($u_redirect);
0292                          }
0293   
0294                          $s_hidden_fields = array(
0295                              'i'                => $id,
0296                              'mode'            => $mode,
0297                              'action'        => array($action => 1),
0298                              'user_id'        => $user_id,
0299                              'group_id'        => $group_id,
0300                              'forum_id'        => $forum_id,
0301                              'type'            => $permission_type,
0302                          );
0303                          if (isset($_POST['all_users']))
0304                          {
0305                              $s_hidden_fields['all_users'] = 1;
0306                          }
0307                          if (isset($_POST['all_groups']))
0308                          {
0309                              $s_hidden_fields['all_groups'] = 1;
0310                          }
0311                          confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
0312                      }
0313                  break;
0314   
0315                  case 'apply_permissions':
0316                      if (!isset($_POST['setting']))
0317                      {
0318                          send_status_line(403, 'Forbidden');
0319                          trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
0320                      }
0321                      if (!check_form_key($form_name))
0322                      {
0323                          trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0324                      }
0325   
0326                      $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id);
0327                  break;
0328   
0329                  case 'apply_all_permissions':
0330                      if (!isset($_POST['setting']))
0331                      {
0332                          send_status_line(403, 'Forbidden');
0333                          trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
0334                      }
0335                      if (!check_form_key($form_name))
0336                      {
0337                          trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0338                      }
0339   
0340                      $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id);
0341                  break;
0342              }
0343          }
0344   
0345          // Go through the screens/options needed and present them in correct order
0346          foreach ($permission_victim as $victim)
0347          {
0348              switch ($victim)
0349              {
0350                  case 'forum_dropdown':
0351   
0352                      if (sizeof($forum_id))
0353                      {
0354                          $this->check_existence('forum', $forum_id);
0355                          continue 2;
0356                      }
0357   
0358                      $template->assign_vars(array(
0359                          'S_SELECT_FORUM'        => true,
0360                          'S_FORUM_OPTIONS'        => make_forum_select(false, false, true, false, false))
0361                      );
0362   
0363                  break;
0364   
0365                  case 'forums':
0366   
0367                      if (sizeof($forum_id))
0368                      {
0369                          $this->check_existence('forum', $forum_id);
0370                          continue 2;
0371                      }
0372   
0373                      $forum_list = make_forum_select(false, false, true, false, false, false, true);
0374   
0375                      // Build forum options
0376                      $s_forum_options = '';
0377                      foreach ($forum_list as $f_id => $f_row)
0378                      {
0379                          $s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
0380                      }
0381   
0382                      // Build subforum options
0383                      $s_subforum_options = $this->build_subforum_options($forum_list);
0384   
0385                      $template->assign_vars(array(
0386                          'S_SELECT_FORUM'        => true,
0387                          'S_FORUM_OPTIONS'        => $s_forum_options,
0388                          'S_SUBFORUM_OPTIONS'    => $s_subforum_options,
0389                          'S_FORUM_ALL'            => true,
0390                          'S_FORUM_MULTIPLE'        => true)
0391                      );
0392   
0393                  break;
0394   
0395                  case 'user':
0396   
0397                      if (sizeof($user_id))
0398                      {
0399                          $this->check_existence('user', $user_id);
0400                          continue 2;
0401                      }
0402   
0403                      $template->assign_vars(array(
0404                          'S_SELECT_USER'            => true,
0405                          'U_FIND_USERNAME'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=select_victim&amp;field=username&amp;select_single=true'),
0406                      ));
0407   
0408                  break;
0409   
0410                  case 'group':
0411   
0412                      if (sizeof($group_id))
0413                      {
0414                          $this->check_existence('group', $group_id);
0415                          continue 2;
0416                      }
0417   
0418                      $template->assign_vars(array(
0419                          'S_SELECT_GROUP'        => true,
0420                          'S_GROUP_OPTIONS'        => group_select_options(false, false, false), // Show all groups
0421                      ));
0422   
0423                  break;
0424   
0425                  case 'usergroup':
0426                  case 'usergroup_view':
0427   
0428                      $all_users = (isset($_POST['all_users'])) ? true : false;
0429                      $all_groups = (isset($_POST['all_groups'])) ? true : false;
0430   
0431                      if ((sizeof($user_id) && !$all_users) || (sizeof($group_id) && !$all_groups))
0432                      {
0433                          if (sizeof($user_id))
0434                          {
0435                              $this->check_existence('user', $user_id);
0436                          }
0437   
0438                          if (sizeof($group_id))
0439                          {
0440                              $this->check_existence('group', $group_id);
0441                          }
0442   
0443                          continue 2;
0444                      }
0445   
0446                      // Now we check the users... because the "all"-selection is different here (all defined users/groups)
0447                      $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
0448   
0449                      if ($all_users && sizeof($items['user_ids']))
0450                      {
0451                          $user_id = $items['user_ids'];
0452                          continue 2;
0453                      }
0454   
0455                      if ($all_groups && sizeof($items['group_ids']))
0456                      {
0457                          $group_id = $items['group_ids'];
0458                          continue 2;
0459                      }
0460   
0461                      $template->assign_vars(array(
0462                          'S_SELECT_USERGROUP'        => ($victim == 'usergroup') ? true : false,
0463                          'S_SELECT_USERGROUP_VIEW'    => ($victim == 'usergroup_view') ? true : false,
0464                          'S_DEFINED_USER_OPTIONS'    => $items['user_ids_options'],
0465                          'S_DEFINED_GROUP_OPTIONS'    => $items['group_ids_options'],
0466                          'S_ADD_GROUP_OPTIONS'        => group_select_options(false, $items['group_ids'], false),    // Show all groups
0467                          'U_FIND_USERNAME'            => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=add_user&amp;field=username&amp;select_single=true'),
0468                      ));
0469   
0470                  break;
0471              }
0472   
0473              // The S_ALLOW_SELECT parameter below is a measure to lower memory usage.
0474              // If there are more than 5 forums selected the admin is not able to select all users/groups too.
0475              // We need to see if the number of forums can be increased or need to be decreased.
0476   
0477              // Setting permissions screen
0478              $s_hidden_fields = build_hidden_fields(array(
0479                      'user_id'        => $user_id,
0480                      'group_id'        => $group_id,
0481                      'forum_id'        => $forum_id,
0482                      'type'            => $permission_type,
0483              ));
0484   
0485              $template->assign_vars(array(
0486                  'U_ACTION'                => $this->u_action,
0487                  'ANONYMOUS_USER_ID'        => ANONYMOUS,
0488   
0489                  'S_SELECT_VICTIM'        => true,
0490                  'S_ALLOW_ALL_SELECT'    => (sizeof($forum_id) > 5) ? false : true,
0491                  'S_CAN_SELECT_USER'        => ($auth->acl_get('a_authusers')) ? true : false,
0492                  'S_CAN_SELECT_GROUP'    => ($auth->acl_get('a_authgroups')) ? true : false,
0493                  'S_HIDDEN_FIELDS'        => $s_hidden_fields)
0494              );
0495   
0496              // Let the forum names being displayed
0497              if (sizeof($forum_id))
0498              {
0499                  $sql = 'SELECT forum_name
0500                      FROM ' . FORUMS_TABLE . '
0501                      WHERE ' . $db->sql_in_set('forum_id', $forum_id) . '
0502                      ORDER BY left_id ASC';
0503                  $result = $db->sql_query($sql);
0504   
0505                  $forum_names = array();
0506                  while ($row = $db->sql_fetchrow($result))
0507                  {
0508                      $forum_names[] = $row['forum_name'];
0509                  }
0510                  $db->sql_freeresult($result);
0511   
0512                  $template->assign_vars(array(
0513                      'S_FORUM_NAMES'        => (sizeof($forum_names)) ? true : false,
0514                      'FORUM_NAMES'        => implode($user->lang['COMMA_SEPARATOR'], $forum_names))
0515                  );
0516              }
0517   
0518              return;
0519          }
0520   
0521          // Setting permissions screen
0522          $s_hidden_fields = build_hidden_fields(array(
0523                  'user_id'        => $user_id,
0524                  'group_id'        => $group_id,
0525                  'forum_id'        => $forum_id,
0526                  'type'            => $permission_type,
0527          ));
0528   
0529          // Do not allow forum_ids being set and no other setting defined (will bog down the server too much)
0530          if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id))
0531          {
0532              trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action), E_USER_WARNING);
0533          }
0534   
0535          $template->assign_vars(array(
0536              'S_PERMISSION_DROPDOWN'        => (sizeof($this->permission_dropdown) > 1) ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type, $permission_scope) : false,
0537              'L_PERMISSION_TYPE'            => $this->permissions->get_type_lang($permission_type),
0538   
0539              'U_ACTION'                    => $this->u_action,
0540              'S_HIDDEN_FIELDS'            => $s_hidden_fields)
0541          );
0542   
0543          if (strpos($mode, 'setting_') === 0)
0544          {
0545              $template->assign_vars(array(
0546                  'S_SETTING_PERMISSIONS'        => true)
0547              );
0548   
0549              $hold_ary = $auth_admin->get_mask('set', (sizeof($user_id)) ? $user_id : false, (sizeof($group_id)) ? $group_id : false, (sizeof($forum_id)) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO);
0550              $auth_admin->display_mask('set', $permission_type, $hold_ary, ((sizeof($user_id)) ? 'user' : 'group'), (($permission_scope == 'local') ? true : false));
0551          }
0552          else
0553          {
0554              $template->assign_vars(array(
0555                  'S_VIEWING_PERMISSIONS'        => true)
0556              );
0557   
0558              $hold_ary = $auth_admin->get_mask('view', (sizeof($user_id)) ? $user_id : false, (sizeof($group_id)) ? $group_id : false, (sizeof($forum_id)) ? $forum_id : false, $permission_type, $permission_scope, ACL_NEVER);
0559              $auth_admin->display_mask('view', $permission_type, $hold_ary, ((sizeof($user_id)) ? 'user' : 'group'), (($permission_scope == 'local') ? true : false));
0560          }
0561      }
0562   
0563      /**
0564      * Build +subforum options
0565      */
0566      function build_subforum_options($forum_list)
0567      {
0568          global $user;
0569   
0570          $s_options = '';
0571   
0572          $forum_list = array_merge($forum_list);
0573   
0574          foreach ($forum_list as $key => $row)
0575          {
0576              if ($row['disabled'])
0577              {
0578                  continue;
0579              }
0580   
0581              $s_options .= '<option value="' . $row['forum_id'] . '"' . (($row['selected']) ? ' selected="selected"' : '') . '>' . $row['padding'] . $row['forum_name'];
0582   
0583              // We check if a branch is there...
0584              $branch_there = false;
0585   
0586              foreach (array_slice($forum_list, $key + 1) as $temp_row)
0587              {
0588                  if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id'])
0589                  {
0590                      $branch_there = true;
0591                      break;
0592                  }
0593                  continue;
0594              }
0595   
0596              if ($branch_there)
0597              {
0598                  $s_options .= ' [' . $user->lang['PLUS_SUBFORUMS'] . ']';
0599              }
0600   
0601              $s_options .= '</option>';
0602          }
0603   
0604          return $s_options;
0605      }
0606   
0607      /**
0608      * Build dropdown field for changing permission types
0609      */
0610      function build_permission_dropdown($options, $default_option, $permission_scope)
0611      {
0612          global $auth;
0613   
0614          $s_dropdown_options = '';
0615          foreach ($options as $setting)
0616          {
0617              if (!$auth->acl_get('a_' . str_replace('_', '', $setting) . 'auth'))
0618              {
0619                  continue;
0620              }
0621   
0622              $selected = ($setting == $default_option) ? ' selected="selected"' : '';
0623              $l_setting = $this->permissions->get_type_lang($setting, $permission_scope);
0624              $s_dropdown_options .= '<option value="' . $setting . '"' . $selected . '>' . $l_setting . '</option>';
0625          }
0626   
0627          return $s_dropdown_options;
0628      }
0629   
0630      /**
0631      * Check if selected items exist. Remove not found ids and if empty return error.
0632      */
0633      function check_existence($mode, &$ids)
0634      {
0635          global $db, $user;
0636   
0637          switch ($mode)
0638          {
0639              case 'user':
0640                  $table = USERS_TABLE;
0641                  $sql_id = 'user_id';
0642              break;
0643   
0644              case 'group':
0645                  $table = GROUPS_TABLE;
0646                  $sql_id = 'group_id';
0647              break;
0648   
0649              case 'forum':
0650                  $table = FORUMS_TABLE;
0651                  $sql_id = 'forum_id';
0652              break;
0653          }
0654   
0655          if (sizeof($ids))
0656          {
0657              $sql = "SELECT $sql_id
0658                  FROM $table
0659                  WHERE " . $db->sql_in_set($sql_id, $ids);
0660              $result = $db->sql_query($sql);
0661   
0662              $ids = array();
0663              while ($row = $db->sql_fetchrow($result))
0664              {
0665                  $ids[] = (int) $row[$sql_id];
0666              }
0667              $db->sql_freeresult($result);
0668          }
0669   
0670          if (!sizeof($ids))
0671          {
0672              trigger_error($user->lang['SELECTED_' . strtoupper($mode) . '_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
0673          }
0674      }
0675   
0676      /**
0677      * Apply permissions
0678      */
0679      function set_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id)
0680      {
0681          global $db, $cache, $user, $auth;
0682          global $request;
0683   
0684          $psubmit = $request->variable('psubmit', array(0 => array(0 => 0)));
0685   
0686          // User or group to be set?
0687          $ug_type = (sizeof($user_id)) ? 'user' : 'group';
0688   
0689          // Check the permission setting again
0690          if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
0691          {
0692              send_status_line(403, 'Forbidden');
0693              trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
0694          }
0695   
0696          // We loop through the auth settings defined in our submit
0697          list($ug_id, ) = each($psubmit);
0698          list($forum_id, ) = each($psubmit[$ug_id]);
0699   
0700          $settings = $request->variable('setting', array(0 => array(0 => array('' => 0))), false, \phpbb\request\request_interface::POST);
0701          if (empty($settings) || empty($settings[$ug_id]) || empty($settings[$ug_id][$forum_id]))
0702          {
0703              trigger_error('WRONG_PERMISSION_SETTING_FORMAT', E_USER_WARNING);
0704          }
0705   
0706          $auth_settings = $settings[$ug_id][$forum_id];
0707   
0708          // Do we have a role we want to set?
0709          $roles = $request->variable('role', array(0 => array(0 => 0)), false, \phpbb\request\request_interface::POST);
0710          $assigned_role = (isset($roles[$ug_id][$forum_id])) ? (int) $roles[$ug_id][$forum_id] : 0;
0711   
0712          // Do the admin want to set these permissions to other items too?
0713          $inherit = $request->variable('inherit', array(0 => array(0)));
0714   
0715          $ug_id = array($ug_id);
0716          $forum_id = array($forum_id);
0717   
0718          if (sizeof($inherit))
0719          {
0720              foreach ($inherit as $_ug_id => $forum_id_ary)
0721              {
0722                  // Inherit users/groups?
0723                  if (!in_array($_ug_id, $ug_id))
0724                  {
0725                      $ug_id[] = $_ug_id;
0726                  }
0727   
0728                  // Inherit forums?
0729                  $forum_id = array_merge($forum_id, array_keys($forum_id_ary));
0730              }
0731          }
0732   
0733          $forum_id = array_unique($forum_id);
0734   
0735          // If the auth settings differ from the assigned role, then do not set a role...
0736          if ($assigned_role)
0737          {
0738              if (!$this->check_assigned_role($assigned_role, $auth_settings))
0739              {
0740                  $assigned_role = 0;
0741              }
0742          }
0743   
0744          // Update the permission set...
0745          $auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_settings, $assigned_role);
0746   
0747          // Do we need to recache the moderator lists?
0748          if ($permission_type == 'm_')
0749          {
0750              phpbb_cache_moderators($db, $cache, $auth);
0751          }
0752   
0753          // Remove users who are now moderators or admins from everyones foes list
0754          if ($permission_type == 'm_' || $permission_type == 'a_')
0755          {
0756              phpbb_update_foes($db, $auth, $group_id, $user_id);
0757          }
0758   
0759          $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_id, $forum_id);
0760   
0761          meta_refresh(5, $this->u_action);
0762          trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
0763      }
0764   
0765      /**
0766      * Apply all permissions
0767      */
0768      function set_all_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id)
0769      {
0770          global $db, $cache, $user, $auth;
0771          global $request;
0772   
0773          // User or group to be set?
0774          $ug_type = (sizeof($user_id)) ? 'user' : 'group';
0775   
0776          // Check the permission setting again
0777          if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
0778          {
0779              send_status_line(403, 'Forbidden');
0780              trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
0781          }
0782   
0783          $auth_settings = $request->variable('setting', array(0 => array(0 => array('' => 0))), false, \phpbb\request\request_interface::POST);
0784          $auth_roles = $request->variable('role', array(0 => array(0 => 0)), false, \phpbb\request\request_interface::POST);
0785          $ug_ids = $forum_ids = array();
0786   
0787          // We need to go through the auth settings
0788          foreach ($auth_settings as $ug_id => $forum_auth_row)
0789          {
0790              $ug_id = (int) $ug_id;
0791              $ug_ids[] = $ug_id;
0792   
0793              foreach ($forum_auth_row as $forum_id => $auth_options)
0794              {
0795                  $forum_id = (int) $forum_id;
0796                  $forum_ids[] = $forum_id;
0797   
0798                  // Check role...
0799                  $assigned_role = (isset($auth_roles[$ug_id][$forum_id])) ? (int) $auth_roles[$ug_id][$forum_id] : 0;
0800   
0801                  // If the auth settings differ from the assigned role, then do not set a role...
0802                  if ($assigned_role)
0803                  {
0804                      if (!$this->check_assigned_role($assigned_role, $auth_options))
0805                      {
0806                          $assigned_role = 0;
0807                      }
0808                  }
0809   
0810                  // Update the permission set...
0811                  $auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_options, $assigned_role, false);
0812              }
0813          }
0814   
0815          $auth_admin->acl_clear_prefetch();
0816   
0817          // Do we need to recache the moderator lists?
0818          if ($permission_type == 'm_')
0819          {
0820              phpbb_cache_moderators($db, $cache, $auth);
0821          }
0822   
0823          // Remove users who are now moderators or admins from everyones foes list
0824          if ($permission_type == 'm_' || $permission_type == 'a_')
0825          {
0826              phpbb_update_foes($db, $auth, $group_id, $user_id);
0827          }
0828   
0829          $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_ids, $forum_ids);
0830   
0831          if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local')
0832          {
0833              meta_refresh(5, $this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_ids));
0834              trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_ids)));
0835          }
0836          else
0837          {
0838              meta_refresh(5, $this->u_action);
0839              trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
0840          }
0841      }
0842   
0843      /**
0844      * Compare auth settings with auth settings from role
0845      * returns false if they differ, true if they are equal
0846      */
0847      function check_assigned_role($role_id, &$auth_settings)
0848      {
0849          global $db;
0850   
0851          $sql = 'SELECT o.auth_option, r.auth_setting
0852              FROM ' . ACL_OPTIONS_TABLE . ' o, ' . ACL_ROLES_DATA_TABLE . ' r
0853              WHERE o.auth_option_id = r.auth_option_id
0854                  AND r.role_id = ' . $role_id;
0855          $result = $db->sql_query($sql);
0856   
0857          $test_auth_settings = array();
0858          while ($row = $db->sql_fetchrow($result))
0859          {
0860              $test_auth_settings[$row['auth_option']] = $row['auth_setting'];
0861          }
0862          $db->sql_freeresult($result);
0863   
0864          // We need to add any ACL_NO setting from auth_settings to compare correctly
0865          foreach ($auth_settings as $option => $setting)
0866          {
0867              if ($setting == ACL_NO)
0868              {
0869                  $test_auth_settings[$option] = $setting;
0870              }
0871          }
0872   
0873          if (sizeof(array_diff_assoc($auth_settings, $test_auth_settings)))
0874          {
0875              return false;
0876          }
0877   
0878          return true;
0879      }
0880   
0881      /**
0882      * Remove permissions
0883      */
0884      function remove_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id, &$forum_id)
0885      {
0886          global $user, $db, $cache, $auth;
0887   
0888          // User or group to be set?
0889          $ug_type = (sizeof($user_id)) ? 'user' : 'group';
0890   
0891          // Check the permission setting again
0892          if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
0893          {
0894              send_status_line(403, 'Forbidden');
0895              trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
0896          }
0897   
0898          $auth_admin->acl_delete($ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : false), $permission_type);
0899   
0900          // Do we need to recache the moderator lists?
0901          if ($permission_type == 'm_')
0902          {
0903              phpbb_cache_moderators($db, $cache, $auth);
0904          }
0905   
0906          $this->log_action($mode, 'del', $permission_type, $ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : array(0 => 0)));
0907   
0908          if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local')
0909          {
0910              meta_refresh(5, $this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_id));
0911              trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_id)));
0912          }
0913          else
0914          {
0915              meta_refresh(5, $this->u_action);
0916              trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
0917          }
0918      }
0919   
0920      /**
0921      * Log permission changes
0922      */
0923      function log_action($mode, $action, $permission_type, $ug_type, $ug_id, $forum_id)
0924      {
0925          global $db, $user, $phpbb_log, $phpbb_container;
0926   
0927          if (!is_array($ug_id))
0928          {
0929              $ug_id = array($ug_id);
0930          }
0931   
0932          if (!is_array($forum_id))
0933          {
0934              $forum_id = array($forum_id);
0935          }
0936   
0937          // Logging ... first grab user or groupnames ...
0938          $sql = ($ug_type == 'group') ? 'SELECT group_name as name, group_type FROM ' . GROUPS_TABLE . ' WHERE ' : 'SELECT username as name FROM ' . USERS_TABLE . ' WHERE ';
0939          $sql .= $db->sql_in_set(($ug_type == 'group') ? 'group_id' : 'user_id', array_map('intval', $ug_id));
0940          $result = $db->sql_query($sql);
0941   
0942          /** @var \phpbb\group\helper $group_helper */
0943          $group_helper = $phpbb_container->get('group_helper');
0944   
0945          $l_ug_list = '';
0946          while ($row = $db->sql_fetchrow($result))
0947          {
0948              $group_name = $group_helper->get_name($row['name']);
0949              $l_ug_list .= (($l_ug_list != '') ? ', ' : '') . ((isset($row['group_type']) && $row['group_type'] == GROUP_SPECIAL) ? '<span class="sep">' . $group_name . '</span>' : $group_name);
0950          }
0951          $db->sql_freeresult($result);
0952   
0953          $mode = str_replace('setting_', '', $mode);
0954   
0955          if ($forum_id[0] == 0)
0956          {
0957              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ACL_' . strtoupper($action) . '_' . strtoupper($mode) . '_' . strtoupper($permission_type), false, array($l_ug_list));
0958          }
0959          else
0960          {
0961              // Grab the forum details if non-zero forum_id
0962              $sql = 'SELECT forum_name
0963                  FROM ' . FORUMS_TABLE . '
0964                  WHERE ' . $db->sql_in_set('forum_id', $forum_id);
0965              $result = $db->sql_query($sql);
0966   
0967              $l_forum_list = '';
0968              while ($row = $db->sql_fetchrow($result))
0969              {
0970                  $l_forum_list .= (($l_forum_list != '') ? ', ' : '') . $row['forum_name'];
0971              }
0972              $db->sql_freeresult($result);
0973   
0974              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ACL_' . strtoupper($action) . '_' . strtoupper($mode) . '_' . strtoupper($permission_type), false, array($l_forum_list, $l_ug_list));
0975          }
0976      }
0977   
0978      /**
0979      * Display a complete trace tree for the selected permission to determine where settings are set/unset
0980      */
0981      function permission_trace($user_id, $forum_id, $permission)
0982      {
0983          global $db, $template, $user, $auth, $request, $phpbb_container;
0984   
0985          if ($user_id != $user->data['user_id'])
0986          {
0987              $userdata = $auth->obtain_user_data($user_id);
0988          }
0989          else
0990          {
0991              $userdata = $user->data;
0992          }
0993   
0994          if (!$userdata)
0995          {
0996              trigger_error('NO_USERS', E_USER_ERROR);
0997          }
0998   
0999          /** @var \phpbb\group\helper $group_helper */
1000          $group_helper = $phpbb_container->get('group_helper');
1001   
1002          $forum_name = false;
1003   
1004          if ($forum_id)
1005          {
1006              $sql = 'SELECT forum_name
1007                  FROM ' . FORUMS_TABLE . "
1008                  WHERE forum_id = $forum_id";
1009              $result = $db->sql_query($sql, 3600);
1010              $forum_name = $db->sql_fetchfield('forum_name');
1011              $db->sql_freeresult($result);
1012          }
1013   
1014          $back = $request->variable('back', 0);
1015   
1016          $template->assign_vars(array(
1017              'PERMISSION'            => $this->permissions->get_permission_lang($permission),
1018              'PERMISSION_USERNAME'    => $userdata['username'],
1019              'FORUM_NAME'            => $forum_name,
1020   
1021              'S_GLOBAL_TRACE'        => ($forum_id) ? false : true,
1022   
1023              'U_BACK'                => ($back) ? build_url(array('f', 'back')) . "&amp;f=$back" : '')
1024          );
1025   
1026          $template->assign_block_vars('trace', array(
1027              'WHO'            => $user->lang['DEFAULT'],
1028              'INFORMATION'    => $user->lang['TRACE_DEFAULT'],
1029   
1030              'S_SETTING_NO'        => true,
1031              'S_TOTAL_NO'        => true)
1032          );
1033   
1034          $sql = 'SELECT DISTINCT g.group_name, g.group_id, g.group_type
1035              FROM ' . GROUPS_TABLE . ' g
1036                  LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.group_id = g.group_id)
1037              WHERE ug.user_id = ' . $user_id . '
1038                  AND ug.user_pending = 0
1039                  AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
1040              ORDER BY g.group_type DESC, g.group_id DESC';
1041          $result = $db->sql_query($sql);
1042   
1043          $groups = array();
1044          while ($row = $db->sql_fetchrow($result))
1045          {
1046              $groups[$row['group_id']] = array(
1047                  'auth_setting'        => ACL_NO,
1048                  'group_name'        => $group_helper->get_name($row['group_name']),
1049              );
1050          }
1051          $db->sql_freeresult($result);
1052   
1053          $total = ACL_NO;
1054          $add_key = (($forum_id) ? '_LOCAL' : '');
1055   
1056          if (sizeof($groups))
1057          {
1058              // Get group auth settings
1059              $hold_ary = $auth->acl_group_raw_data(array_keys($groups), $permission, $forum_id);
1060   
1061              foreach ($hold_ary as $group_id => $forum_ary)
1062              {
1063                  $groups[$group_id]['auth_setting'] = $hold_ary[$group_id][$forum_id][$permission];
1064              }
1065              unset($hold_ary);
1066   
1067              foreach ($groups as $id => $row)
1068              {
1069                  switch ($row['auth_setting'])
1070                  {
1071                      case ACL_NO:
1072                          $information = $user->lang['TRACE_GROUP_NO' . $add_key];
1073                      break;
1074   
1075                      case ACL_YES:
1076                          $information = ($total == ACL_YES) ? $user->lang['TRACE_GROUP_YES_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_GROUP_YES_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_GROUP_YES_TOTAL_NO' . $add_key]);
1077                          $total = ($total == ACL_NO) ? ACL_YES : $total;
1078                      break;
1079   
1080                      case ACL_NEVER:
1081                          $information = ($total == ACL_YES) ? $user->lang['TRACE_GROUP_NEVER_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_GROUP_NEVER_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_GROUP_NEVER_TOTAL_NO' . $add_key]);
1082                          $total = ACL_NEVER;
1083                      break;
1084                  }
1085   
1086                  $template->assign_block_vars('trace', array(
1087                      'WHO'            => $row['group_name'],
1088                      'INFORMATION'    => $information,
1089   
1090                      'S_SETTING_NO'        => ($row['auth_setting'] == ACL_NO) ? true : false,
1091                      'S_SETTING_YES'        => ($row['auth_setting'] == ACL_YES) ? true : false,
1092                      'S_SETTING_NEVER'    => ($row['auth_setting'] == ACL_NEVER) ? true : false,
1093                      'S_TOTAL_NO'        => ($total == ACL_NO) ? true : false,
1094                      'S_TOTAL_YES'        => ($total == ACL_YES) ? true : false,
1095                      'S_TOTAL_NEVER'        => ($total == ACL_NEVER) ? true : false)
1096                  );
1097              }
1098          }
1099   
1100          // Get user specific permission... globally or for this forum
1101          $hold_ary = $auth->acl_user_raw_data($user_id, $permission, $forum_id);
1102          $auth_setting = (!sizeof($hold_ary)) ? ACL_NO : $hold_ary[$user_id][$forum_id][$permission];
1103   
1104          switch ($auth_setting)
1105          {
1106              case ACL_NO:
1107                  $information = ($total == ACL_NO) ? $user->lang['TRACE_USER_NO_TOTAL_NO' . $add_key] : $user->lang['TRACE_USER_KEPT' . $add_key];
1108                  $total = ($total == ACL_NO) ? ACL_NEVER : $total;
1109              break;
1110   
1111              case ACL_YES:
1112                  $information = ($total == ACL_YES) ? $user->lang['TRACE_USER_YES_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_USER_YES_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_USER_YES_TOTAL_NO' . $add_key]);
1113                  $total = ($total == ACL_NO) ? ACL_YES : $total;
1114              break;
1115   
1116              case ACL_NEVER:
1117                  $information = ($total == ACL_YES) ? $user->lang['TRACE_USER_NEVER_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_USER_NEVER_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_USER_NEVER_TOTAL_NO' . $add_key]);
1118                  $total = ACL_NEVER;
1119              break;
1120          }
1121   
1122          $template->assign_block_vars('trace', array(
1123              'WHO'            => $userdata['username'],
1124              'INFORMATION'    => $information,
1125   
1126              'S_SETTING_NO'        => ($auth_setting == ACL_NO) ? true : false,
1127              'S_SETTING_YES'        => ($auth_setting == ACL_YES) ? true : false,
1128              'S_SETTING_NEVER'    => ($auth_setting == ACL_NEVER) ? true : false,
1129              'S_TOTAL_NO'        => false,
1130              'S_TOTAL_YES'        => ($total == ACL_YES) ? true : false,
1131              'S_TOTAL_NEVER'        => ($total == ACL_NEVER) ? true : false)
1132          );
1133   
1134          if ($forum_id != 0 && isset($auth->acl_options['global'][$permission]))
1135          {
1136              if ($user_id != $user->data['user_id'])
1137              {
1138                  $auth2 = new \phpbb\auth\auth();
1139                  $auth2->acl($userdata);
1140                  $auth_setting = $auth2->acl_get($permission);
1141              }
1142              else
1143              {
1144                  $auth_setting = $auth->acl_get($permission);
1145              }
1146   
1147              if ($auth_setting)
1148              {
1149                  $information = ($total == ACL_YES) ? $user->lang['TRACE_USER_GLOBAL_YES_TOTAL_YES'] : $user->lang['TRACE_USER_GLOBAL_YES_TOTAL_NEVER'];
1150                  $total = ACL_YES;
1151              }
1152              else
1153              {
1154                  $information = $user->lang['TRACE_USER_GLOBAL_NEVER_TOTAL_KEPT'];
1155              }
1156   
1157              // If there is no auth information we do not need to worry the user by showing non-relevant data.
1158              if ($auth_setting)
1159              {
1160                  $template->assign_block_vars('trace', array(
1161                      'WHO'            => sprintf($user->lang['TRACE_GLOBAL_SETTING'], $userdata['username']),
1162                      'INFORMATION'    => sprintf($information, '<a href="' . $this->u_action . "&amp;u=$user_id&amp;f=0&amp;auth=$permission&amp;back=$forum_id\">", '</a>'),
1163   
1164                      'S_SETTING_NO'        => false,
1165                      'S_SETTING_YES'        => $auth_setting,
1166                      'S_SETTING_NEVER'    => !$auth_setting,
1167                      'S_TOTAL_NO'        => false,
1168                      'S_TOTAL_YES'        => ($total == ACL_YES) ? true : false,
1169                      'S_TOTAL_NEVER'        => ($total == ACL_NEVER) ? true : false)
1170                  );
1171              }
1172          }
1173   
1174          // Take founder status into account, overwriting the default values
1175          if ($userdata['user_type'] == USER_FOUNDER && strpos($permission, 'a_') === 0)
1176          {
1177              $template->assign_block_vars('trace', array(
1178                  'WHO'            => $userdata['username'],
1179                  'INFORMATION'    => $user->lang['TRACE_USER_FOUNDER'],
1180   
1181                  'S_SETTING_NO'        => ($auth_setting == ACL_NO) ? true : false,
1182                  'S_SETTING_YES'        => ($auth_setting == ACL_YES) ? true : false,
1183                  'S_SETTING_NEVER'    => ($auth_setting == ACL_NEVER) ? true : false,
1184                  'S_TOTAL_NO'        => false,
1185                  'S_TOTAL_YES'        => true,
1186                  'S_TOTAL_NEVER'        => false)
1187              );
1188   
1189              $total = ACL_YES;
1190          }
1191   
1192          // Total value...
1193          $template->assign_vars(array(
1194              'S_RESULT_NO'        => ($total == ACL_NO) ? true : false,
1195              'S_RESULT_YES'        => ($total == ACL_YES) ? true : false,
1196              'S_RESULT_NEVER'    => ($total == ACL_NEVER) ? true : false,
1197          ));
1198      }
1199   
1200      /**
1201      * Handles copying permissions from one forum to others
1202      */
1203      function copy_forum_permissions()
1204      {
1205          global $db, $auth, $cache, $template, $user, $request;
1206   
1207          $user->add_lang('acp/forums');
1208   
1209          $submit = isset($_POST['submit']) ? true : false;
1210   
1211          if ($submit)
1212          {
1213              $src = $request->variable('src_forum_id', 0);
1214              $dest = $request->variable('dest_forum_ids', array(0));
1215   
1216              if (confirm_box(true))
1217              {
1218                  if (copy_forum_permissions($src, $dest))
1219                  {
1220                      phpbb_cache_moderators($db, $cache, $auth);
1221   
1222                      $auth->acl_clear_prefetch();
1223                      $cache->destroy('sql', FORUMS_TABLE);
1224   
1225                      trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
1226                  }
1227                  else
1228                  {
1229                      trigger_error($user->lang['SELECTED_FORUM_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
1230                  }
1231              }
1232              else
1233              {
1234                  $s_hidden_fields = array(
1235                      'submit'            => $submit,
1236                      'src_forum_id'        => $src,
1237                      'dest_forum_ids'    => $dest,
1238                  );
1239   
1240                  $s_hidden_fields = build_hidden_fields($s_hidden_fields);
1241   
1242                  confirm_box(false, $user->lang['COPY_PERMISSIONS_CONFIRM'], $s_hidden_fields);
1243              }
1244          }
1245   
1246          $template->assign_vars(array(
1247              'S_FORUM_OPTIONS' => make_forum_select(false, false, false, false, false),
1248          ));
1249      }
1250   
1251      /**
1252      * Get already assigned users/groups
1253      */
1254      function retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type)
1255      {
1256          global $db, $phpbb_container;
1257   
1258          /** @var \phpbb\group\helper $group_helper */
1259          $group_helper = $phpbb_container->get('group_helper');
1260   
1261          $sql_forum_id = ($permission_scope == 'global') ? 'AND a.forum_id = 0' : ((sizeof($forum_id)) ? 'AND ' . $db->sql_in_set('a.forum_id', $forum_id) : 'AND a.forum_id <> 0');
1262   
1263          // Permission options are only able to be a permission set... therefore we will pre-fetch the possible options and also the possible roles
1264          $option_ids = $role_ids = array();
1265   
1266          $sql = 'SELECT auth_option_id
1267              FROM ' . ACL_OPTIONS_TABLE . '
1268              WHERE auth_option ' . $db->sql_like_expression($permission_type . $db->get_any_char());
1269          $result = $db->sql_query($sql);
1270   
1271          while ($row = $db->sql_fetchrow($result))
1272          {
1273              $option_ids[] = (int) $row['auth_option_id'];
1274          }
1275          $db->sql_freeresult($result);
1276   
1277          if (sizeof($option_ids))
1278          {
1279              $sql = 'SELECT DISTINCT role_id
1280                  FROM ' . ACL_ROLES_DATA_TABLE . '
1281                  WHERE ' . $db->sql_in_set('auth_option_id', $option_ids);
1282              $result = $db->sql_query($sql);
1283   
1284              while ($row = $db->sql_fetchrow($result))
1285              {
1286                  $role_ids[] = (int) $row['role_id'];
1287              }
1288              $db->sql_freeresult($result);
1289          }
1290   
1291          if (sizeof($option_ids) && sizeof($role_ids))
1292          {
1293              $sql_where = 'AND (' . $db->sql_in_set('a.auth_option_id', $option_ids) . ' OR ' . $db->sql_in_set('a.auth_role_id', $role_ids) . ')';
1294          }
1295          else if (sizeof($role_ids))
1296          {
1297              $sql_where = 'AND ' . $db->sql_in_set('a.auth_role_id', $role_ids);
1298          }
1299          else if (sizeof($option_ids))
1300          {
1301              $sql_where = 'AND ' . $db->sql_in_set('a.auth_option_id', $option_ids);
1302          }
1303   
1304          // Not ideal, due to the filesort, non-use of indexes, etc.
1305          $sql = 'SELECT DISTINCT u.user_id, u.username, u.username_clean, u.user_regdate
1306              FROM ' . USERS_TABLE . ' u, ' . ACL_USERS_TABLE . " a
1307              WHERE u.user_id = a.user_id
1308                  $sql_forum_id
1309                  $sql_where
1310              ORDER BY u.username_clean, u.user_regdate ASC";
1311          $result = $db->sql_query($sql);
1312   
1313          $s_defined_user_options = '';
1314          $defined_user_ids = array();
1315          while ($row = $db->sql_fetchrow($result))
1316          {
1317              $s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>';
1318              $defined_user_ids[] = $row['user_id'];
1319          }
1320          $db->sql_freeresult($result);
1321   
1322          $sql = 'SELECT DISTINCT g.group_type, g.group_name, g.group_id
1323              FROM ' . GROUPS_TABLE . ' g, ' . ACL_GROUPS_TABLE . " a
1324              WHERE g.group_id = a.group_id
1325                  $sql_forum_id
1326                  $sql_where
1327              ORDER BY g.group_type DESC, g.group_name ASC";
1328          $result = $db->sql_query($sql);
1329   
1330          $s_defined_group_options = '';
1331          $defined_group_ids = array();
1332          while ($row = $db->sql_fetchrow($result))
1333          {
1334              $s_defined_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>';
1335              $defined_group_ids[] = $row['group_id'];
1336          }
1337          $db->sql_freeresult($result);
1338   
1339          return array(
1340              'group_ids'            => $defined_group_ids,
1341              'group_ids_options'    => $s_defined_group_options,
1342              'user_ids'            => $defined_user_ids,
1343              'user_ids_options'    => $s_defined_user_options
1344          );
1345      }
1346  }
1347