Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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