[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

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

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  /**
  23  * ACP Permission/Auth class
  24  */
  25  class auth_admin extends \phpbb\auth\auth
  26  {
  27      /**
  28      * Init auth settings
  29      */
  30  	function auth_admin()
  31      {
  32          global $db, $cache;
  33  
  34          if (($this->acl_options = $cache->get('_acl_options')) === false)
  35          {
  36              $sql = 'SELECT auth_option_id, auth_option, is_global, is_local
  37                  FROM ' . ACL_OPTIONS_TABLE . '
  38                  ORDER BY auth_option_id';
  39              $result = $db->sql_query($sql);
  40  
  41              $global = $local = 0;
  42              $this->acl_options = array();
  43              while ($row = $db->sql_fetchrow($result))
  44              {
  45                  if ($row['is_global'])
  46                  {
  47                      $this->acl_options['global'][$row['auth_option']] = $global++;
  48                  }
  49  
  50                  if ($row['is_local'])
  51                  {
  52                      $this->acl_options['local'][$row['auth_option']] = $local++;
  53                  }
  54  
  55                  $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
  56                  $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
  57              }
  58              $db->sql_freeresult($result);
  59  
  60              $cache->put('_acl_options', $this->acl_options);
  61          }
  62      }
  63  
  64      /**
  65      * Get permission mask
  66      * This function only supports getting permissions of one type (for example a_)
  67      *
  68      * @param set|view $mode defines the permissions we get, view gets effective permissions (checking user AND group permissions), set only gets the user or group permission set alone
  69      * @param mixed $user_id user ids to search for (a user_id or a group_id has to be specified at least)
  70      * @param mixed $group_id group ids to search for, return group related settings (a user_id or a group_id has to be specified at least)
  71      * @param mixed $forum_id forum_ids to search for. Defining a forum id also means getting local settings
  72      * @param string $auth_option the auth_option defines the permission setting to look for (a_ for example)
  73      * @param local|global $scope the scope defines the permission scope. If local, a forum_id is additionally required
  74      * @param ACL_NEVER|ACL_NO|ACL_YES $acl_fill defines the mode those permissions not set are getting filled with
  75      */
  76  	function get_mask($mode, $user_id = false, $group_id = false, $forum_id = false, $auth_option = false, $scope = false, $acl_fill = ACL_NEVER)
  77      {
  78          global $db, $user;
  79  
  80          $hold_ary = array();
  81          $view_user_mask = ($mode == 'view' && $group_id === false) ? true : false;
  82  
  83          if ($auth_option === false || $scope === false)
  84          {
  85              return array();
  86          }
  87  
  88          $acl_user_function = ($mode == 'set') ? 'acl_user_raw_data' : 'acl_raw_data';
  89  
  90          if (!$view_user_mask)
  91          {
  92              if ($forum_id !== false)
  93              {
  94                  $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, $auth_option . '%', $forum_id) : $this->$acl_user_function($user_id, $auth_option . '%', $forum_id);
  95              }
  96              else
  97              {
  98                  $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, $auth_option . '%', ($scope == 'global') ? 0 : false) : $this->$acl_user_function($user_id, $auth_option . '%', ($scope == 'global') ? 0 : false);
  99              }
 100          }
 101  
 102          // Make sure hold_ary is filled with every setting (prevents missing forums/users/groups)
 103          $ug_id = ($group_id !== false) ? ((!is_array($group_id)) ? array($group_id) : $group_id) : ((!is_array($user_id)) ? array($user_id) : $user_id);
 104          $forum_ids = ($forum_id !== false) ? ((!is_array($forum_id)) ? array($forum_id) : $forum_id) : (($scope == 'global') ? array(0) : array());
 105  
 106          // Only those options we need
 107          $compare_options = array_diff(preg_replace('/^((?!' . $auth_option . ').+)|(' . $auth_option . ')$/', '', array_keys($this->acl_options[$scope])), array(''));
 108  
 109          // If forum_ids is false and the scope is local we actually want to have all forums within the array
 110          if ($scope == 'local' && !sizeof($forum_ids))
 111          {
 112              $sql = 'SELECT forum_id
 113                  FROM ' . FORUMS_TABLE;
 114              $result = $db->sql_query($sql, 120);
 115  
 116              while ($row = $db->sql_fetchrow($result))
 117              {
 118                  $forum_ids[] = (int) $row['forum_id'];
 119              }
 120              $db->sql_freeresult($result);
 121          }
 122  
 123          if ($view_user_mask)
 124          {
 125              $auth2 = null;
 126  
 127              $sql = 'SELECT user_id, user_permissions, user_type
 128                  FROM ' . USERS_TABLE . '
 129                  WHERE ' . $db->sql_in_set('user_id', $ug_id);
 130              $result = $db->sql_query($sql);
 131  
 132              while ($userdata = $db->sql_fetchrow($result))
 133              {
 134                  if ($user->data['user_id'] != $userdata['user_id'])
 135                  {
 136                      $auth2 = new \phpbb\auth\auth();
 137                      $auth2->acl($userdata);
 138                  }
 139                  else
 140                  {
 141                      global $auth;
 142                      $auth2 = &$auth;
 143                  }
 144  
 145                  $hold_ary[$userdata['user_id']] = array();
 146                  foreach ($forum_ids as $f_id)
 147                  {
 148                      $hold_ary[$userdata['user_id']][$f_id] = array();
 149                      foreach ($compare_options as $option)
 150                      {
 151                          $hold_ary[$userdata['user_id']][$f_id][$option] = $auth2->acl_get($option, $f_id);
 152                      }
 153                  }
 154              }
 155              $db->sql_freeresult($result);
 156  
 157              unset($userdata);
 158              unset($auth2);
 159          }
 160  
 161          foreach ($ug_id as $_id)
 162          {
 163              if (!isset($hold_ary[$_id]))
 164              {
 165                  $hold_ary[$_id] = array();
 166              }
 167  
 168              foreach ($forum_ids as $f_id)
 169              {
 170                  if (!isset($hold_ary[$_id][$f_id]))
 171                  {
 172                      $hold_ary[$_id][$f_id] = array();
 173                  }
 174              }
 175          }
 176  
 177          // Now, we need to fill the gaps with $acl_fill. ;)
 178  
 179          // Now switch back to keys
 180          if (sizeof($compare_options))
 181          {
 182              $compare_options = array_combine($compare_options, array_fill(1, sizeof($compare_options), $acl_fill));
 183          }
 184  
 185          // Defining the user-function here to save some memory
 186          $return_acl_fill = function () use ($acl_fill)
 187          {
 188              return $acl_fill;
 189          };
 190  
 191          // Actually fill the gaps
 192          if (sizeof($hold_ary))
 193          {
 194              foreach ($hold_ary as $ug_id => $row)
 195              {
 196                  foreach ($row as $id => $options)
 197                  {
 198                      // Do not include the global auth_option
 199                      unset($options[$auth_option]);
 200  
 201                      // Not a "fine" solution, but at all it's a 1-dimensional
 202                      // array_diff_key function filling the resulting array values with zeros
 203                      // The differences get merged into $hold_ary (all permissions having $acl_fill set)
 204                      $hold_ary[$ug_id][$id] = array_merge($options,
 205  
 206                          array_map($return_acl_fill,
 207                              array_flip(
 208                                  array_diff(
 209                                      array_keys($compare_options), array_keys($options)
 210                                  )
 211                              )
 212                          )
 213                      );
 214                  }
 215              }
 216          }
 217          else
 218          {
 219              $hold_ary[($group_id !== false) ? $group_id : $user_id][(int) $forum_id] = $compare_options;
 220          }
 221  
 222          return $hold_ary;
 223      }
 224  
 225      /**
 226      * Get permission mask for roles
 227      * This function only supports getting masks for one role
 228      */
 229  	function get_role_mask($role_id)
 230      {
 231          global $db;
 232  
 233          $hold_ary = array();
 234  
 235          // Get users having this role set...
 236          $sql = 'SELECT user_id, forum_id
 237              FROM ' . ACL_USERS_TABLE . '
 238              WHERE auth_role_id = ' . $role_id . '
 239              ORDER BY forum_id';
 240          $result = $db->sql_query($sql);
 241  
 242          while ($row = $db->sql_fetchrow($result))
 243          {
 244              $hold_ary[$row['forum_id']]['users'][] = $row['user_id'];
 245          }
 246          $db->sql_freeresult($result);
 247  
 248          // Now grab groups...
 249          $sql = 'SELECT group_id, forum_id
 250              FROM ' . ACL_GROUPS_TABLE . '
 251              WHERE auth_role_id = ' . $role_id . '
 252              ORDER BY forum_id';
 253          $result = $db->sql_query($sql);
 254  
 255          while ($row = $db->sql_fetchrow($result))
 256          {
 257              $hold_ary[$row['forum_id']]['groups'][] = $row['group_id'];
 258          }
 259          $db->sql_freeresult($result);
 260  
 261          return $hold_ary;
 262      }
 263  
 264      /**
 265      * Display permission mask (assign to template)
 266      */
 267  	function display_mask($mode, $permission_type, &$hold_ary, $user_mode = 'user', $local = false, $group_display = true)
 268      {
 269          global $template, $user, $db, $phpbb_root_path, $phpEx, $phpbb_container;
 270          $phpbb_permissions = $phpbb_container->get('acl.permissions');
 271  
 272          // Define names for template loops, might be able to be set
 273          $tpl_pmask = 'p_mask';
 274          $tpl_fmask = 'f_mask';
 275          $tpl_category = 'category';
 276          $tpl_mask = 'mask';
 277  
 278          $l_acl_type = $phpbb_permissions->get_type_lang($permission_type, (($local) ? 'local' : 'global'));
 279  
 280          // Allow trace for viewing permissions and in user mode
 281          $show_trace = ($mode == 'view' && $user_mode == 'user') ? true : false;
 282  
 283          // Get names
 284          if ($user_mode == 'user')
 285          {
 286              $sql = 'SELECT user_id as ug_id, username as ug_name
 287                  FROM ' . USERS_TABLE . '
 288                  WHERE ' . $db->sql_in_set('user_id', array_keys($hold_ary)) . '
 289                  ORDER BY username_clean ASC';
 290          }
 291          else
 292          {
 293              $sql = 'SELECT group_id as ug_id, group_name as ug_name, group_type
 294                  FROM ' . GROUPS_TABLE . '
 295                  WHERE ' . $db->sql_in_set('group_id', array_keys($hold_ary)) . '
 296                  ORDER BY group_type DESC, group_name ASC';
 297          }
 298          $result = $db->sql_query($sql);
 299  
 300          $ug_names_ary = array();
 301          while ($row = $db->sql_fetchrow($result))
 302          {
 303              $ug_names_ary[$row['ug_id']] = ($user_mode == 'user') ? $row['ug_name'] : (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['ug_name']] : $row['ug_name']);
 304          }
 305          $db->sql_freeresult($result);
 306  
 307          // Get used forums
 308          $forum_ids = array();
 309          foreach ($hold_ary as $ug_id => $row)
 310          {
 311              $forum_ids = array_merge($forum_ids, array_keys($row));
 312          }
 313          $forum_ids = array_unique($forum_ids);
 314  
 315          $forum_names_ary = array();
 316          if ($local)
 317          {
 318              $forum_names_ary = make_forum_select(false, false, true, false, false, false, true);
 319  
 320              // Remove the disabled ones, since we do not create an option field here...
 321              foreach ($forum_names_ary as $key => $value)
 322              {
 323                  if (!$value['disabled'])
 324                  {
 325                      continue;
 326                  }
 327                  unset($forum_names_ary[$key]);
 328              }
 329          }
 330          else
 331          {
 332              $forum_names_ary[0] = $l_acl_type;
 333          }
 334  
 335          // Get available roles
 336          $sql = 'SELECT *
 337              FROM ' . ACL_ROLES_TABLE . "
 338              WHERE role_type = '" . $db->sql_escape($permission_type) . "'
 339              ORDER BY role_order ASC";
 340          $result = $db->sql_query($sql);
 341  
 342          $roles = array();
 343          while ($row = $db->sql_fetchrow($result))
 344          {
 345              $roles[$row['role_id']] = $row;
 346          }
 347          $db->sql_freeresult($result);
 348  
 349          $cur_roles = $this->acl_role_data($user_mode, $permission_type, array_keys($hold_ary));
 350  
 351          // Build js roles array (role data assignments)
 352          $s_role_js_array = '';
 353  
 354          if (sizeof($roles))
 355          {
 356              $s_role_js_array = array();
 357  
 358              // Make sure every role (even if empty) has its array defined
 359              foreach ($roles as $_role_id => $null)
 360              {
 361                  $s_role_js_array[$_role_id] = "\n" . 'role_options[' . $_role_id . '] = new Array();' . "\n";
 362              }
 363  
 364              $sql = 'SELECT r.role_id, o.auth_option, r.auth_setting
 365                  FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o
 366                  WHERE o.auth_option_id = r.auth_option_id
 367                      AND ' . $db->sql_in_set('r.role_id', array_keys($roles));
 368              $result = $db->sql_query($sql);
 369  
 370              while ($row = $db->sql_fetchrow($result))
 371              {
 372                  $flag = substr($row['auth_option'], 0, strpos($row['auth_option'], '_') + 1);
 373                  if ($flag == $row['auth_option'])
 374                  {
 375                      continue;
 376                  }
 377  
 378                  $s_role_js_array[$row['role_id']] .= 'role_options[' . $row['role_id'] . '][\'' . addslashes($row['auth_option']) . '\'] = ' . $row['auth_setting'] . '; ';
 379              }
 380              $db->sql_freeresult($result);
 381  
 382              $s_role_js_array = implode('', $s_role_js_array);
 383          }
 384  
 385          $template->assign_var('S_ROLE_JS_ARRAY', $s_role_js_array);
 386          unset($s_role_js_array);
 387  
 388          // Now obtain memberships
 389          $user_groups_default = $user_groups_custom = array();
 390          if ($user_mode == 'user' && $group_display)
 391          {
 392              $sql = 'SELECT group_id, group_name, group_type
 393                  FROM ' . GROUPS_TABLE . '
 394                  ORDER BY group_type DESC, group_name ASC';
 395              $result = $db->sql_query($sql);
 396  
 397              $groups = array();
 398              while ($row = $db->sql_fetchrow($result))
 399              {
 400                  $groups[$row['group_id']] = $row;
 401              }
 402              $db->sql_freeresult($result);
 403  
 404              $memberships = group_memberships(false, array_keys($hold_ary), false);
 405  
 406              // User is not a member of any group? Bad admin, bad bad admin...
 407              if ($memberships)
 408              {
 409                  foreach ($memberships as $row)
 410                  {
 411                      if ($groups[$row['group_id']]['group_type'] == GROUP_SPECIAL)
 412                      {
 413                          $user_groups_default[$row['user_id']][] = $user->lang['G_' . $groups[$row['group_id']]['group_name']];
 414                      }
 415                      else
 416                      {
 417                          $user_groups_custom[$row['user_id']][] = $groups[$row['group_id']]['group_name'];
 418                      }
 419                  }
 420              }
 421              unset($memberships, $groups);
 422          }
 423  
 424          // If we only have one forum id to display or being in local mode and more than one user/group to display,
 425          // we switch the complete interface to group by user/usergroup instead of grouping by forum
 426          // To achieve this, we need to switch the array a bit
 427          if (sizeof($forum_ids) == 1 || ($local && sizeof($ug_names_ary) > 1))
 428          {
 429              $hold_ary_temp = $hold_ary;
 430              $hold_ary = array();
 431              foreach ($hold_ary_temp as $ug_id => $row)
 432              {
 433                  foreach ($forum_names_ary as $forum_id => $forum_row)
 434                  {
 435                      if (isset($row[$forum_id]))
 436                      {
 437                          $hold_ary[$forum_id][$ug_id] = $row[$forum_id];
 438                      }
 439                  }
 440              }
 441              unset($hold_ary_temp);
 442  
 443              foreach ($hold_ary as $forum_id => $forum_array)
 444              {
 445                  $content_array = $categories = array();
 446                  $this->build_permission_array($hold_ary[$forum_id], $content_array, $categories, array_keys($ug_names_ary));
 447  
 448                  $template->assign_block_vars($tpl_pmask, array(
 449                      'NAME'            => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],
 450                      'PADDING'        => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],
 451  
 452                      'CATEGORIES'    => implode('</th><th>', $categories),
 453  
 454                      'L_ACL_TYPE'    => $l_acl_type,
 455  
 456                      'S_LOCAL'        => ($local) ? true : false,
 457                      'S_GLOBAL'        => (!$local) ? true : false,
 458                      'S_NUM_CATS'    => sizeof($categories),
 459                      'S_VIEW'        => ($mode == 'view') ? true : false,
 460                      'S_NUM_OBJECTS'    => sizeof($content_array),
 461                      'S_USER_MODE'    => ($user_mode == 'user') ? true : false,
 462                      'S_GROUP_MODE'    => ($user_mode == 'group') ? true : false)
 463                  );
 464  
 465                  @reset($content_array);
 466                  while (list($ug_id, $ug_array) = each($content_array))
 467                  {
 468                      // Build role dropdown options
 469                      $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
 470  
 471                      $s_role_options = '';
 472  
 473                      @reset($roles);
 474                      while (list($role_id, $role_row) = each($roles))
 475                      {
 476                          $role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);
 477                          $role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
 478  
 479                          $title = ($role_description) ? ' title="' . $role_description . '"' : '';
 480                          $s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_name . '</option>';
 481                      }
 482  
 483                      if ($s_role_options)
 484                      {
 485                          $s_role_options = '<option value="0"' . ((!$current_role_id) ? ' selected="selected"' : '') . ' title="' . htmlspecialchars($user->lang['NO_ROLE_ASSIGNED_EXPLAIN']) . '">' . $user->lang['NO_ROLE_ASSIGNED'] . '</option>' . $s_role_options;
 486                      }
 487  
 488                      if (!$current_role_id && $mode != 'view')
 489                      {
 490                          $s_custom_permissions = false;
 491  
 492                          foreach ($ug_array as $key => $value)
 493                          {
 494                              if ($value['S_NEVER'] || $value['S_YES'])
 495                              {
 496                                  $s_custom_permissions = true;
 497                                  break;
 498                              }
 499                          }
 500                      }
 501                      else
 502                      {
 503                          $s_custom_permissions = false;
 504                      }
 505  
 506                      $template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(
 507                          'NAME'                => $ug_names_ary[$ug_id],
 508                          'S_ROLE_OPTIONS'    => $s_role_options,
 509                          'UG_ID'                => $ug_id,
 510                          'S_CUSTOM'            => $s_custom_permissions,
 511                          'FORUM_ID'            => $forum_id)
 512                      );
 513  
 514                      $this->assign_cat_array($ug_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, ($mode == 'view'), $show_trace);
 515  
 516                      unset($content_array[$ug_id]);
 517                  }
 518  
 519                  unset($hold_ary[$forum_id]);
 520              }
 521          }
 522          else
 523          {
 524              foreach ($ug_names_ary as $ug_id => $ug_name)
 525              {
 526                  if (!isset($hold_ary[$ug_id]))
 527                  {
 528                      continue;
 529                  }
 530  
 531                  $content_array = $categories = array();
 532                  $this->build_permission_array($hold_ary[$ug_id], $content_array, $categories, array_keys($forum_names_ary));
 533  
 534                  $template->assign_block_vars($tpl_pmask, array(
 535                      'NAME'            => $ug_name,
 536                      'CATEGORIES'    => implode('</th><th>', $categories),
 537  
 538                      'USER_GROUPS_DEFAULT'    => ($user_mode == 'user' && isset($user_groups_default[$ug_id]) && sizeof($user_groups_default[$ug_id])) ? implode($user->lang['COMMA_SEPARATOR'], $user_groups_default[$ug_id]) : '',
 539                      'USER_GROUPS_CUSTOM'    => ($user_mode == 'user' && isset($user_groups_custom[$ug_id]) && sizeof($user_groups_custom[$ug_id])) ? implode($user->lang['COMMA_SEPARATOR'], $user_groups_custom[$ug_id]) : '',
 540                      'L_ACL_TYPE'            => $l_acl_type,
 541  
 542                      'S_LOCAL'        => ($local) ? true : false,
 543                      'S_GLOBAL'        => (!$local) ? true : false,
 544                      'S_NUM_CATS'    => sizeof($categories),
 545                      'S_VIEW'        => ($mode == 'view') ? true : false,
 546                      'S_NUM_OBJECTS'    => sizeof($content_array),
 547                      'S_USER_MODE'    => ($user_mode == 'user') ? true : false,
 548                      'S_GROUP_MODE'    => ($user_mode == 'group') ? true : false)
 549                  );
 550  
 551                  @reset($content_array);
 552                  while (list($forum_id, $forum_array) = each($content_array))
 553                  {
 554                      // Build role dropdown options
 555                      $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
 556  
 557                      $s_role_options = '';
 558  
 559                      @reset($roles);
 560                      while (list($role_id, $role_row) = each($roles))
 561                      {
 562                          $role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);
 563                          $role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
 564  
 565                          $title = ($role_description) ? ' title="' . $role_description . '"' : '';
 566                          $s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_name . '</option>';
 567                      }
 568  
 569                      if ($s_role_options)
 570                      {
 571                          $s_role_options = '<option value="0"' . ((!$current_role_id) ? ' selected="selected"' : '') . ' title="' . htmlspecialchars($user->lang['NO_ROLE_ASSIGNED_EXPLAIN']) . '">' . $user->lang['NO_ROLE_ASSIGNED'] . '</option>' . $s_role_options;
 572                      }
 573  
 574                      if (!$current_role_id && $mode != 'view')
 575                      {
 576                          $s_custom_permissions = false;
 577  
 578                          foreach ($forum_array as $key => $value)
 579                          {
 580                              if ($value['S_NEVER'] || $value['S_YES'])
 581                              {
 582                                  $s_custom_permissions = true;
 583                                  break;
 584                              }
 585                          }
 586                      }
 587                      else
 588                      {
 589                          $s_custom_permissions = false;
 590                      }
 591  
 592                      $template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(
 593                          'NAME'                => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],
 594                          'PADDING'            => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],
 595                          'S_ROLE_OPTIONS'    => $s_role_options,
 596                          'S_CUSTOM'            => $s_custom_permissions,
 597                          'UG_ID'                => $ug_id,
 598                          'FORUM_ID'            => $forum_id)
 599                      );
 600  
 601                      $this->assign_cat_array($forum_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, ($mode == 'view'), $show_trace);
 602                  }
 603  
 604                  unset($hold_ary[$ug_id], $ug_names_ary[$ug_id]);
 605              }
 606          }
 607      }
 608  
 609      /**
 610      * Display permission mask for roles
 611      */
 612  	function display_role_mask(&$hold_ary)
 613      {
 614          global $db, $template, $user, $phpbb_root_path, $phpbb_admin_path, $phpEx;
 615  
 616          if (!sizeof($hold_ary))
 617          {
 618              return;
 619          }
 620  
 621          // Get forum names
 622          $sql = 'SELECT forum_id, forum_name
 623              FROM ' . FORUMS_TABLE . '
 624              WHERE ' . $db->sql_in_set('forum_id', array_keys($hold_ary)) . '
 625              ORDER BY left_id';
 626          $result = $db->sql_query($sql);
 627  
 628          // If the role is used globally, then reflect that
 629          $forum_names = (isset($hold_ary[0])) ? array(0 => '') : array();
 630          while ($row = $db->sql_fetchrow($result))
 631          {
 632              $forum_names[$row['forum_id']] = $row['forum_name'];
 633          }
 634          $db->sql_freeresult($result);
 635  
 636          foreach ($forum_names as $forum_id => $forum_name)
 637          {
 638              $auth_ary = $hold_ary[$forum_id];
 639  
 640              $template->assign_block_vars('role_mask', array(
 641                  'NAME'                => ($forum_id == 0) ? $user->lang['GLOBAL_MASK'] : $forum_name,
 642                  'FORUM_ID'            => $forum_id)
 643              );
 644  
 645              if (isset($auth_ary['users']) && sizeof($auth_ary['users']))
 646              {
 647                  $sql = 'SELECT user_id, username
 648                      FROM ' . USERS_TABLE . '
 649                      WHERE ' . $db->sql_in_set('user_id', $auth_ary['users']) . '
 650                      ORDER BY username_clean ASC';
 651                  $result = $db->sql_query($sql);
 652  
 653                  while ($row = $db->sql_fetchrow($result))
 654                  {
 655                      $template->assign_block_vars('role_mask.users', array(
 656                          'USER_ID'        => $row['user_id'],
 657                          'USERNAME'        => get_username_string('username', $row['user_id'], $row['username']),
 658                          'U_PROFILE'        => get_username_string('profile', $row['user_id'], $row['username']),
 659                      ));
 660                  }
 661                  $db->sql_freeresult($result);
 662              }
 663  
 664              if (isset($auth_ary['groups']) && sizeof($auth_ary['groups']))
 665              {
 666                  $sql = 'SELECT group_id, group_name, group_type
 667                      FROM ' . GROUPS_TABLE . '
 668                      WHERE ' . $db->sql_in_set('group_id', $auth_ary['groups']) . '
 669                      ORDER BY group_type ASC, group_name';
 670                  $result = $db->sql_query($sql);
 671  
 672                  while ($row = $db->sql_fetchrow($result))
 673                  {
 674                      $template->assign_block_vars('role_mask.groups', array(
 675                          'GROUP_ID'        => $row['group_id'],
 676                          'GROUP_NAME'    => ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
 677                          'U_PROFILE'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=group&amp;g={$row['group_id']}"))
 678                      );
 679                  }
 680                  $db->sql_freeresult($result);
 681              }
 682          }
 683      }
 684  
 685      /**
 686      * NOTE: this function is not in use atm
 687      * Add a new option to the list ... $options is a hash of form ->
 688      * $options = array(
 689      *    'local'        => array('option1', 'option2', ...),
 690      *    'global'    => array('optionA', 'optionB', ...)
 691      * );
 692      */
 693  	function acl_add_option($options)
 694      {
 695          global $db, $cache;
 696  
 697          if (!is_array($options))
 698          {
 699              return false;
 700          }
 701  
 702          $cur_options = array();
 703  
 704          // Determine current options
 705          $sql = 'SELECT auth_option, is_global, is_local
 706              FROM ' . ACL_OPTIONS_TABLE . '
 707              ORDER BY auth_option_id';
 708          $result = $db->sql_query($sql);
 709  
 710          while ($row = $db->sql_fetchrow($result))
 711          {
 712              $cur_options[$row['auth_option']] = ($row['is_global'] && $row['is_local']) ? 'both' : (($row['is_global']) ? 'global' : 'local');
 713          }
 714          $db->sql_freeresult($result);
 715  
 716          // Here we need to insert new options ... this requires discovering whether
 717          // an options is global, local or both and whether we need to add an permission
 718          // set flag (x_)
 719          $new_options = array('local' => array(), 'global' => array());
 720  
 721          foreach ($options as $type => $option_ary)
 722          {
 723              $option_ary = array_unique($option_ary);
 724  
 725              foreach ($option_ary as $option_value)
 726              {
 727                  $new_options[$type][] = $option_value;
 728  
 729                  $flag = substr($option_value, 0, strpos($option_value, '_') + 1);
 730  
 731                  if (!in_array($flag, $new_options[$type]))
 732                  {
 733                      $new_options[$type][] = $flag;
 734                  }
 735              }
 736          }
 737          unset($options);
 738  
 739          $options = array();
 740          $options['local'] = array_diff($new_options['local'], $new_options['global']);
 741          $options['global'] = array_diff($new_options['global'], $new_options['local']);
 742          $options['both'] = array_intersect($new_options['local'], $new_options['global']);
 743  
 744          // Now check which options to add/update
 745          $add_options = $update_options = array();
 746  
 747          // First local ones...
 748          foreach ($options as $type => $option_ary)
 749          {
 750              foreach ($option_ary as $option)
 751              {
 752                  if (!isset($cur_options[$option]))
 753                  {
 754                      $add_options[] = array(
 755                          'auth_option'    => (string) $option,
 756                          'is_global'        => ($type == 'global' || $type == 'both') ? 1 : 0,
 757                          'is_local'        => ($type == 'local' || $type == 'both') ? 1 : 0
 758                      );
 759  
 760                      continue;
 761                  }
 762  
 763                  // Else, update existing entry if it is changed...
 764                  if ($type === $cur_options[$option])
 765                  {
 766                      continue;
 767                  }
 768  
 769                  // New type is always both:
 770                  // If is now both, we set both.
 771                  // If it was global the new one is local and we need to set it to both
 772                  // If it was local the new one is global and we need to set it to both
 773                  $update_options[] = $option;
 774              }
 775          }
 776  
 777          if (!empty($add_options))
 778          {
 779              $db->sql_multi_insert(ACL_OPTIONS_TABLE, $add_options);
 780          }
 781  
 782          if (!empty($update_options))
 783          {
 784              $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
 785                  SET is_global = 1, is_local = 1
 786                  WHERE ' . $db->sql_in_set('auth_option', $update_options);
 787              $db->sql_query($sql);
 788          }
 789  
 790          $cache->destroy('_acl_options');
 791          $this->acl_clear_prefetch();
 792  
 793          // Because we just changed the options and also purged the options cache, we instantly update/regenerate it for later calls to succeed.
 794          $this->acl_options = array();
 795          $this->auth_admin();
 796  
 797          return true;
 798      }
 799  
 800      /**
 801      * Set a user or group ACL record
 802      */
 803  	function acl_set($ug_type, $forum_id, $ug_id, $auth, $role_id = 0, $clear_prefetch = true)
 804      {
 805          global $db;
 806  
 807          // One or more forums
 808          if (!is_array($forum_id))
 809          {
 810              $forum_id = array($forum_id);
 811          }
 812  
 813          // One or more users
 814          if (!is_array($ug_id))
 815          {
 816              $ug_id = array($ug_id);
 817          }
 818  
 819          $ug_id_sql = $db->sql_in_set($ug_type . '_id', array_map('intval', $ug_id));
 820          $forum_sql = $db->sql_in_set('forum_id', array_map('intval', $forum_id));
 821  
 822          // Instead of updating, inserting, removing we just remove all current settings and re-set everything...
 823          $table = ($ug_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
 824          $id_field = $ug_type . '_id';
 825  
 826          // Get any flags as required
 827          reset($auth);
 828          $flag = key($auth);
 829          $flag = substr($flag, 0, strpos($flag, '_') + 1);
 830  
 831          // This ID (the any-flag) is set if one or more permissions are true...
 832          $any_option_id = (int) $this->acl_options['id'][$flag];
 833  
 834          // Remove any-flag from auth ary
 835          if (isset($auth[$flag]))
 836          {
 837              unset($auth[$flag]);
 838          }
 839  
 840          // Remove current auth options...
 841          $auth_option_ids = array((int) $any_option_id);
 842          foreach ($auth as $auth_option => $auth_setting)
 843          {
 844              $auth_option_ids[] = (int) $this->acl_options['id'][$auth_option];
 845          }
 846  
 847          $sql = "DELETE FROM $table
 848              WHERE $forum_sql
 849                  AND $ug_id_sql
 850                  AND " . $db->sql_in_set('auth_option_id', $auth_option_ids);
 851          $db->sql_query($sql);
 852  
 853          // Remove those having a role assigned... the correct type of course...
 854          $sql = 'SELECT role_id
 855              FROM ' . ACL_ROLES_TABLE . "
 856              WHERE role_type = '" . $db->sql_escape($flag) . "'";
 857          $result = $db->sql_query($sql);
 858  
 859          $role_ids = array();
 860          while ($row = $db->sql_fetchrow($result))
 861          {
 862              $role_ids[] = $row['role_id'];
 863          }
 864          $db->sql_freeresult($result);
 865  
 866          if (sizeof($role_ids))
 867          {
 868              $sql = "DELETE FROM $table
 869                  WHERE $forum_sql
 870                      AND $ug_id_sql
 871                      AND auth_option_id = 0
 872                      AND " . $db->sql_in_set('auth_role_id', $role_ids);
 873              $db->sql_query($sql);
 874          }
 875  
 876          // Ok, include the any-flag if one or more auth options are set to yes...
 877          foreach ($auth as $auth_option => $setting)
 878          {
 879              if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))
 880              {
 881                  $auth[$flag] = ACL_YES;
 882              }
 883          }
 884  
 885          $sql_ary = array();
 886          foreach ($forum_id as $forum)
 887          {
 888              $forum = (int) $forum;
 889  
 890              if ($role_id)
 891              {
 892                  foreach ($ug_id as $id)
 893                  {
 894                      $sql_ary[] = array(
 895                          $id_field            => (int) $id,
 896                          'forum_id'            => (int) $forum,
 897                          'auth_option_id'    => 0,
 898                          'auth_setting'        => 0,
 899                          'auth_role_id'        => (int) $role_id,
 900                      );
 901                  }
 902              }
 903              else
 904              {
 905                  foreach ($auth as $auth_option => $setting)
 906                  {
 907                      $auth_option_id = (int) $this->acl_options['id'][$auth_option];
 908  
 909                      if ($setting != ACL_NO)
 910                      {
 911                          foreach ($ug_id as $id)
 912                          {
 913                              $sql_ary[] = array(
 914                                  $id_field            => (int) $id,
 915                                  'forum_id'            => (int) $forum,
 916                                  'auth_option_id'    => (int) $auth_option_id,
 917                                  'auth_setting'        => (int) $setting
 918                              );
 919                          }
 920                      }
 921                  }
 922              }
 923          }
 924  
 925          $db->sql_multi_insert($table, $sql_ary);
 926  
 927          if ($clear_prefetch)
 928          {
 929              $this->acl_clear_prefetch();
 930          }
 931      }
 932  
 933      /**
 934      * Set a role-specific ACL record
 935      */
 936  	function acl_set_role($role_id, $auth)
 937      {
 938          global $db;
 939  
 940          // Get any-flag as required
 941          reset($auth);
 942          $flag = key($auth);
 943          $flag = substr($flag, 0, strpos($flag, '_') + 1);
 944  
 945          // Remove any-flag from auth ary
 946          if (isset($auth[$flag]))
 947          {
 948              unset($auth[$flag]);
 949          }
 950  
 951          // Re-set any flag...
 952          foreach ($auth as $auth_option => $setting)
 953          {
 954              if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))
 955              {
 956                  $auth[$flag] = ACL_YES;
 957              }
 958          }
 959  
 960          $sql_ary = array();
 961          foreach ($auth as $auth_option => $setting)
 962          {
 963              $auth_option_id = (int) $this->acl_options['id'][$auth_option];
 964  
 965              if ($setting != ACL_NO)
 966              {
 967                  $sql_ary[] = array(
 968                      'role_id'            => (int) $role_id,
 969                      'auth_option_id'    => (int) $auth_option_id,
 970                      'auth_setting'        => (int) $setting
 971                  );
 972              }
 973          }
 974  
 975          // If no data is there, we set the any-flag to ACL_NEVER...
 976          if (!sizeof($sql_ary))
 977          {
 978              $sql_ary[] = array(
 979                  'role_id'            => (int) $role_id,
 980                  'auth_option_id'    => (int) $this->acl_options['id'][$flag],
 981                  'auth_setting'        => ACL_NEVER
 982              );
 983          }
 984  
 985          // Remove current auth options...
 986          $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
 987              WHERE role_id = ' . $role_id;
 988          $db->sql_query($sql);
 989  
 990          // Now insert the new values
 991          $db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);
 992  
 993          $this->acl_clear_prefetch();
 994      }
 995  
 996      /**
 997      * Remove local permission
 998      */
 999  	function acl_delete($mode, $ug_id = false, $forum_id = false, $permission_type = false)
1000      {
1001          global $db;
1002  
1003          if ($ug_id === false && $forum_id === false)
1004          {
1005              return;
1006          }
1007  
1008          $option_id_ary = array();
1009          $table = ($mode == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
1010          $id_field = $mode . '_id';
1011  
1012          $where_sql = array();
1013  
1014          if ($forum_id !== false)
1015          {
1016              $where_sql[] = (!is_array($forum_id)) ? 'forum_id = ' . (int) $forum_id : $db->sql_in_set('forum_id', array_map('intval', $forum_id));
1017          }
1018  
1019          if ($ug_id !== false)
1020          {
1021              $where_sql[] = (!is_array($ug_id)) ? $id_field . ' = ' . (int) $ug_id : $db->sql_in_set($id_field, array_map('intval', $ug_id));
1022          }
1023  
1024          // There seem to be auth options involved, therefore we need to go through the list and make sure we capture roles correctly
1025          if ($permission_type !== false)
1026          {
1027              // Get permission type
1028              $sql = 'SELECT auth_option, auth_option_id
1029                  FROM ' . ACL_OPTIONS_TABLE . "
1030                  WHERE auth_option " . $db->sql_like_expression($permission_type . $db->get_any_char());
1031              $result = $db->sql_query($sql);
1032  
1033              $auth_id_ary = array();
1034              while ($row = $db->sql_fetchrow($result))
1035              {
1036                  $option_id_ary[] = $row['auth_option_id'];
1037                  $auth_id_ary[$row['auth_option']] = ACL_NO;
1038              }
1039              $db->sql_freeresult($result);
1040  
1041              // First of all, lets grab the items having roles with the specified auth options assigned
1042              $sql = "SELECT auth_role_id, $id_field, forum_id
1043                  FROM $table, " . ACL_ROLES_TABLE . " r
1044                  WHERE auth_role_id <> 0
1045                      AND auth_role_id = r.role_id
1046                      AND r.role_type = '{$permission_type}'
1047                      AND " . implode(' AND ', $where_sql) . '
1048                  ORDER BY auth_role_id';
1049              $result = $db->sql_query($sql);
1050  
1051              $cur_role_auth = array();
1052              while ($row = $db->sql_fetchrow($result))
1053              {
1054                  $cur_role_auth[$row['auth_role_id']][$row['forum_id']][] = $row[$id_field];
1055              }
1056              $db->sql_freeresult($result);
1057  
1058              // Get role data for resetting data
1059              if (sizeof($cur_role_auth))
1060              {
1061                  $sql = 'SELECT ao.auth_option, rd.role_id, rd.auth_setting
1062                      FROM ' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_ROLES_DATA_TABLE . ' rd
1063                      WHERE ao.auth_option_id = rd.auth_option_id
1064                          AND ' . $db->sql_in_set('rd.role_id', array_keys($cur_role_auth));
1065                  $result = $db->sql_query($sql);
1066  
1067                  $auth_settings = array();
1068                  while ($row = $db->sql_fetchrow($result))
1069                  {
1070                      // We need to fill all auth_options, else setting it will fail...
1071                      if (!isset($auth_settings[$row['role_id']]))
1072                      {
1073                          $auth_settings[$row['role_id']] = $auth_id_ary;
1074                      }
1075                      $auth_settings[$row['role_id']][$row['auth_option']] = $row['auth_setting'];
1076                  }
1077                  $db->sql_freeresult($result);
1078  
1079                  // Set the options
1080                  foreach ($cur_role_auth as $role_id => $auth_row)
1081                  {
1082                      foreach ($auth_row as $f_id => $ug_row)
1083                      {
1084                          $this->acl_set($mode, $f_id, $ug_row, $auth_settings[$role_id], 0, false);
1085                      }
1086                  }
1087              }
1088          }
1089  
1090          // Now, normally remove permissions...
1091          if ($permission_type !== false)
1092          {
1093              $where_sql[] = $db->sql_in_set('auth_option_id', array_map('intval', $option_id_ary));
1094          }
1095  
1096          $sql = "DELETE FROM $table
1097              WHERE " . implode(' AND ', $where_sql);
1098          $db->sql_query($sql);
1099  
1100          $this->acl_clear_prefetch();
1101      }
1102  
1103      /**
1104      * Assign category to template
1105      * used by display_mask()
1106      */
1107  	function assign_cat_array(&$category_array, $tpl_cat, $tpl_mask, $ug_id, $forum_id, $s_view, $show_trace = false)
1108      {
1109          global $template, $user, $phpbb_admin_path, $phpEx, $phpbb_container;
1110  
1111          $phpbb_permissions = $phpbb_container->get('acl.permissions');
1112  
1113          @reset($category_array);
1114          while (list($cat, $cat_array) = each($category_array))
1115          {
1116              if (!$phpbb_permissions->category_defined($cat))
1117              {
1118                  continue;
1119              }
1120  
1121              $template->assign_block_vars($tpl_cat, array(
1122                  'S_YES'        => ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,
1123                  'S_NEVER'    => ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,
1124                  'S_NO'        => ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false,
1125  
1126                  'CAT_NAME'    => $phpbb_permissions->get_category_lang($cat),
1127              ));
1128  
1129              /*    Sort permissions by name (more naturaly and user friendly than sorting by a primary key)
1130              *    Commented out due to it's memory consumption and time needed
1131              *
1132              $key_array = array_intersect(array_keys($user->lang), array_map(create_function('$a', 'return "acl_" . $a;'), array_keys($cat_array['permissions'])));
1133              $values_array = $cat_array['permissions'];
1134  
1135              $cat_array['permissions'] = array();
1136  
1137              foreach ($key_array as $key)
1138              {
1139                  $key = str_replace('acl_', '', $key);
1140                  $cat_array['permissions'][$key] = $values_array[$key];
1141              }
1142              unset($key_array, $values_array);
1143  */
1144              @reset($cat_array['permissions']);
1145              while (list($permission, $allowed) = each($cat_array['permissions']))
1146              {
1147                  if (!$phpbb_permissions->permission_defined($permission))
1148                  {
1149                      continue;
1150                  }
1151  
1152                  if ($s_view)
1153                  {
1154                      $template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(
1155                          'S_YES'        => ($allowed == ACL_YES) ? true : false,
1156                          'S_NEVER'    => ($allowed == ACL_NEVER) ? true : false,
1157  
1158                          'UG_ID'            => $ug_id,
1159                          'FORUM_ID'        => $forum_id,
1160                          'FIELD_NAME'    => $permission,
1161                          'S_FIELD_NAME'    => 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',
1162  
1163                          'U_TRACE'        => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&amp;mode=trace&amp;u=$ug_id&amp;f=$forum_id&amp;auth=$permission") : '',
1164                          'UA_TRACE'        => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',
1165  
1166                          'PERMISSION'    => $phpbb_permissions->get_permission_lang($permission),
1167                      ));
1168                  }
1169                  else
1170                  {
1171                      $template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(
1172                          'S_YES'        => ($allowed == ACL_YES) ? true : false,
1173                          'S_NEVER'    => ($allowed == ACL_NEVER) ? true : false,
1174                          'S_NO'        => ($allowed == ACL_NO) ? true : false,
1175  
1176                          'UG_ID'            => $ug_id,
1177                          'FORUM_ID'        => $forum_id,
1178                          'FIELD_NAME'    => $permission,
1179                          'S_FIELD_NAME'    => 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',
1180  
1181                          'U_TRACE'        => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&amp;mode=trace&amp;u=$ug_id&amp;f=$forum_id&amp;auth=$permission") : '',
1182                          'UA_TRACE'        => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',
1183  
1184                          'PERMISSION'    => $phpbb_permissions->get_permission_lang($permission),
1185                      ));
1186                  }
1187              }
1188          }
1189      }
1190  
1191      /**
1192      * Building content array from permission rows with explicit key ordering
1193      * used by display_mask()
1194      */
1195  	function build_permission_array(&$permission_row, &$content_array, &$categories, $key_sort_array)
1196      {
1197          global $user, $phpbb_container;
1198  
1199          $phpbb_permissions = $phpbb_container->get('acl.permissions');
1200  
1201          foreach ($key_sort_array as $forum_id)
1202          {
1203              if (!isset($permission_row[$forum_id]))
1204              {
1205                  continue;
1206              }
1207  
1208              $permissions = $permission_row[$forum_id];
1209              ksort($permissions);
1210  
1211              @reset($permissions);
1212              while (list($permission, $auth_setting) = each($permissions))
1213              {
1214                  $cat = $phpbb_permissions->get_permission_category($permission);
1215  
1216                  // Build our categories array
1217                  if (!isset($categories[$cat]))
1218                  {
1219                      $categories[$cat] = $phpbb_permissions->get_category_lang($cat);
1220                  }
1221  
1222                  // Build our content array
1223                  if (!isset($content_array[$forum_id]))
1224                  {
1225                      $content_array[$forum_id] = array();
1226                  }
1227  
1228                  if (!isset($content_array[$forum_id][$cat]))
1229                  {
1230                      $content_array[$forum_id][$cat] = array(
1231                          'S_YES'            => false,
1232                          'S_NEVER'        => false,
1233                          'S_NO'            => false,
1234                          'permissions'    => array(),
1235                      );
1236                  }
1237  
1238                  $content_array[$forum_id][$cat]['S_YES'] |= ($auth_setting == ACL_YES) ? true : false;
1239                  $content_array[$forum_id][$cat]['S_NEVER'] |= ($auth_setting == ACL_NEVER) ? true : false;
1240                  $content_array[$forum_id][$cat]['S_NO'] |= ($auth_setting == ACL_NO) ? true : false;
1241  
1242                  $content_array[$forum_id][$cat]['permissions'][$permission] = $auth_setting;
1243              }
1244          }
1245      }
1246  
1247      /**
1248      * Use permissions from another user. This transferes a permission set from one user to another.
1249      * The other user is always able to revert back to his permission set.
1250      * This function does not check for lower/higher permissions, it is possible for the user to gain
1251      * "more" permissions by this.
1252      * Admin permissions will not be copied.
1253      */
1254  	function ghost_permissions($from_user_id, $to_user_id)
1255      {
1256          global $db;
1257  
1258          if ($to_user_id == ANONYMOUS)
1259          {
1260              return false;
1261          }
1262  
1263          $hold_ary = $this->acl_raw_data_single_user($from_user_id);
1264  
1265          // Key 0 in $hold_ary are global options, all others are forum_ids
1266  
1267          // We disallow copying admin permissions
1268          foreach ($this->acl_options['global'] as $opt => $id)
1269          {
1270              if (strpos($opt, 'a_') === 0)
1271              {
1272                  $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_NEVER;
1273              }
1274          }
1275  
1276          // Force a_switchperm to be allowed
1277          $hold_ary[0][$this->acl_options['id']['a_switchperm']] = ACL_YES;
1278  
1279          $user_permissions = $this->build_bitstring($hold_ary);
1280  
1281          if (!$user_permissions)
1282          {
1283              return false;
1284          }
1285  
1286          $sql = 'UPDATE ' . USERS_TABLE . "
1287              SET user_permissions = '" . $db->sql_escape($user_permissions) . "',
1288                  user_perm_from = $from_user_id
1289              WHERE user_id = " . $to_user_id;
1290          $db->sql_query($sql);
1291  
1292          return true;
1293      }
1294  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1