|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
*
|
|
|
f2e824 |
* @package phpBB3
|
|
|
f2e824 |
* @version $Id: auth.php 8479 2008-03-29 00:22:48Z naderman $
|
|
|
f2e824 |
* @copyright (c) 2005 phpBB Group
|
|
|
f2e824 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
f2e824 |
*
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* @ignore
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
if (!defined('IN_PHPBB'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
exit;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* ACP Permission/Auth class
|
|
|
f2e824 |
* @package phpBB3
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
class auth_admin extends auth
|
|
|
f2e824 |
{
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Init auth settings
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function auth_admin()
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db, $cache;
|
|
|
f2e824 |
|
|
|
f2e824 |
if (($this->acl_options = $cache->get('_acl_options')) === false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT auth_option_id, auth_option, is_global, is_local
|
|
|
f2e824 |
FROM ' . ACL_OPTIONS_TABLE . '
|
|
|
f2e824 |
ORDER BY auth_option_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$global = $local = 0;
|
|
|
f2e824 |
$this->acl_options = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($row['is_global'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$this->acl_options['global'][$row['auth_option']] = $global++;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['is_local'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$this->acl_options['local'][$row['auth_option']] = $local++;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
|
|
|
f2e824 |
$this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
$cache->put('_acl_options', $this->acl_options);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Get permission mask
|
|
|
f2e824 |
* This function only supports getting permissions of one type (for example a_)
|
|
|
f2e824 |
*
|
|
|
f2e824 |
* @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
|
|
|
f2e824 |
* @param mixed $user_id user ids to search for (a user_id or a group_id has to be specified at least)
|
|
|
f2e824 |
* @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)
|
|
|
f2e824 |
* @param mixed $forum_id forum_ids to search for. Defining a forum id also means getting local settings
|
|
|
f2e824 |
* @param string $auth_option the auth_option defines the permission setting to look for (a_ for example)
|
|
|
f2e824 |
* @param local|global $scope the scope defines the permission scope. If local, a forum_id is additionally required
|
|
|
f2e824 |
* @param ACL_NEVER|ACL_NO|ACL_YES $acl_fill defines the mode those permissions not set are getting filled with
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function get_mask($mode, $user_id = false, $group_id = false, $forum_id = false, $auth_option = false, $scope = false, $acl_fill = ACL_NEVER)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db, $user;
|
|
|
f2e824 |
|
|
|
f2e824 |
$hold_ary = array();
|
|
|
f2e824 |
$view_user_mask = ($mode == 'view' && $group_id === false) ? true : false;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($auth_option === false || $scope === false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
return array();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$acl_user_function = ($mode == 'set') ? 'acl_user_raw_data' : 'acl_raw_data';
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$view_user_mask)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($forum_id !== false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$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);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$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);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Make sure hold_ary is filled with every setting (prevents missing forums/users/groups)
|
|
|
f2e824 |
$ug_id = ($group_id !== false) ? ((!is_array($group_id)) ? array($group_id) : $group_id) : ((!is_array($user_id)) ? array($user_id) : $user_id);
|
|
|
f2e824 |
$forum_ids = ($forum_id !== false) ? ((!is_array($forum_id)) ? array($forum_id) : $forum_id) : (($scope == 'global') ? array(0) : array());
|
|
|
f2e824 |
|
|
|
f2e824 |
// Only those options we need
|
|
|
f2e824 |
$compare_options = array_diff(preg_replace('/^((?!' . $auth_option . ').+)|(' . $auth_option . ')$/', '', array_keys($this->acl_options[$scope])), array(''));
|
|
|
f2e824 |
|
|
|
f2e824 |
// If forum_ids is false and the scope is local we actually want to have all forums within the array
|
|
|
f2e824 |
if ($scope == 'local' && !sizeof($forum_ids))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT forum_id
|
|
|
f2e824 |
FROM ' . FORUMS_TABLE;
|
|
|
f2e824 |
$result = $db->sql_query($sql, 120);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_ids[] = (int) $row['forum_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($view_user_mask)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth2 = null;
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT user_id, user_permissions, user_type
|
|
|
f2e824 |
FROM ' . USERS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('user_id', $ug_id);
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($userdata = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($user->data['user_id'] != $userdata['user_id'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth2 = new auth();
|
|
|
f2e824 |
$auth2->acl($userdata);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $auth;
|
|
|
f2e824 |
$auth2 = &$auth;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
|
|
|
f2e824 |
$hold_ary[$userdata['user_id']] = array();
|
|
|
f2e824 |
foreach ($forum_ids as $f_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$userdata['user_id']][$f_id] = array();
|
|
|
f2e824 |
foreach ($compare_options as $option)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$userdata['user_id']][$f_id][$option] = $auth2->acl_get($option, $f_id);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
unset($userdata);
|
|
|
f2e824 |
unset($auth2);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($ug_id as $_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!isset($hold_ary[$_id]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$_id] = array();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($forum_ids as $f_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!isset($hold_ary[$_id][$f_id]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$_id][$f_id] = array();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Now, we need to fill the gaps with $acl_fill. ;)
|
|
|
f2e824 |
|
|
|
f2e824 |
// Now switch back to keys
|
|
|
f2e824 |
if (sizeof($compare_options))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$compare_options = array_combine($compare_options, array_fill(1, sizeof($compare_options), $acl_fill));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Defining the user-function here to save some memory
|
|
|
f2e824 |
$return_acl_fill = create_function('$value', 'return ' . $acl_fill . ';');
|
|
|
f2e824 |
|
|
|
f2e824 |
// Actually fill the gaps
|
|
|
f2e824 |
if (sizeof($hold_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($hold_ary as $ug_id => $row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($row as $id => $options)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Do not include the global auth_option
|
|
|
f2e824 |
unset($options[$auth_option]);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Not a "fine" solution, but at all it's a 1-dimensional
|
|
|
f2e824 |
// array_diff_key function filling the resulting array values with zeros
|
|
|
f2e824 |
// The differences get merged into $hold_ary (all permissions having $acl_fill set)
|
|
|
f2e824 |
$hold_ary[$ug_id][$id] = array_merge($options,
|
|
|
f2e824 |
|
|
|
f2e824 |
array_map($return_acl_fill,
|
|
|
f2e824 |
array_flip(
|
|
|
f2e824 |
array_diff(
|
|
|
f2e824 |
array_keys($compare_options), array_keys($options)
|
|
|
f2e824 |
)
|
|
|
f2e824 |
)
|
|
|
f2e824 |
)
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[($group_id !== false) ? $group_id : $user_id][(int) $forum_id] = $compare_options;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
return $hold_ary;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Get permission mask for roles
|
|
|
f2e824 |
* This function only supports getting masks for one role
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function get_role_mask($role_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db;
|
|
|
f2e824 |
|
|
|
f2e824 |
$hold_ary = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get users having this role set...
|
|
|
f2e824 |
$sql = 'SELECT user_id, forum_id
|
|
|
f2e824 |
FROM ' . ACL_USERS_TABLE . '
|
|
|
f2e824 |
WHERE auth_role_id = ' . $role_id . '
|
|
|
f2e824 |
ORDER BY forum_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$row['forum_id']]['users'][] = $row['user_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Now grab groups...
|
|
|
f2e824 |
$sql = 'SELECT group_id, forum_id
|
|
|
f2e824 |
FROM ' . ACL_GROUPS_TABLE . '
|
|
|
f2e824 |
WHERE auth_role_id = ' . $role_id . '
|
|
|
f2e824 |
ORDER BY forum_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$row['forum_id']]['groups'][] = $row['group_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
return $hold_ary;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Display permission mask (assign to template)
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function display_mask($mode, $permission_type, &$hold_ary, $user_mode = 'user', $local = false, $group_display = true)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $template, $user, $db, $phpbb_root_path, $phpEx;
|
|
|
f2e824 |
|
|
|
f2e824 |
// Define names for template loops, might be able to be set
|
|
|
f2e824 |
$tpl_pmask = 'p_mask';
|
|
|
f2e824 |
$tpl_fmask = 'f_mask';
|
|
|
f2e824 |
$tpl_category = 'category';
|
|
|
f2e824 |
$tpl_mask = 'mask';
|
|
|
f2e824 |
|
|
|
f2e824 |
$l_acl_type = (isset($user->lang['ACL_TYPE_' . (($local) ? 'LOCAL' : 'GLOBAL') . '_' . strtoupper($permission_type)])) ? $user->lang['ACL_TYPE_' . (($local) ? 'LOCAL' : 'GLOBAL') . '_' . strtoupper($permission_type)] : 'ACL_TYPE_' . (($local) ? 'LOCAL' : 'GLOBAL') . '_' . strtoupper($permission_type);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Allow trace for viewing permissions and in user mode
|
|
|
f2e824 |
$show_trace = ($mode == 'view' && $user_mode == 'user') ? true : false;
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get names
|
|
|
f2e824 |
if ($user_mode == 'user')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT user_id as ug_id, username as ug_name
|
|
|
f2e824 |
FROM ' . USERS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('user_id', array_keys($hold_ary)) . '
|
|
|
f2e824 |
ORDER BY username_clean ASC';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT group_id as ug_id, group_name as ug_name, group_type
|
|
|
f2e824 |
FROM ' . GROUPS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('group_id', array_keys($hold_ary)) . '
|
|
|
f2e824 |
ORDER BY group_type DESC, group_name ASC';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$ug_names_ary = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$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']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get used forums
|
|
|
f2e824 |
$forum_ids = array();
|
|
|
f2e824 |
foreach ($hold_ary as $ug_id => $row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_ids = array_merge($forum_ids, array_keys($row));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$forum_ids = array_unique($forum_ids);
|
|
|
f2e824 |
|
|
|
f2e824 |
$forum_names_ary = array();
|
|
|
f2e824 |
if ($local)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_names_ary = make_forum_select(false, false, true, false, false, false, true);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Remove the disabled ones, since we do not create an option field here...
|
|
|
f2e824 |
foreach ($forum_names_ary as $key => $value)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!$value['disabled'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($forum_names_ary[$key]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_names_ary[0] = $l_acl_type;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get available roles
|
|
|
f2e824 |
$sql = 'SELECT *
|
|
|
f2e824 |
FROM ' . ACL_ROLES_TABLE . "
|
|
|
f2e824 |
WHERE role_type = '" . $db->sql_escape($permission_type) . "'
|
|
|
f2e824 |
ORDER BY role_order ASC";
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$roles = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$roles[$row['role_id']] = $row;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
$cur_roles = $this->acl_role_data($user_mode, $permission_type, array_keys($hold_ary));
|
|
|
f2e824 |
|
|
|
f2e824 |
// Build js roles array (role data assignments)
|
|
|
f2e824 |
$s_role_js_array = '';
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($roles))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_role_js_array = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
// Make sure every role (even if empty) has its array defined
|
|
|
f2e824 |
foreach ($roles as $_role_id => $null)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_role_js_array[$_role_id] = "\n" . 'role_options[' . $_role_id . '] = new Array();' . "\n";
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT r.role_id, o.auth_option, r.auth_setting
|
|
|
f2e824 |
FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o
|
|
|
f2e824 |
WHERE o.auth_option_id = r.auth_option_id
|
|
|
f2e824 |
AND ' . $db->sql_in_set('r.role_id', array_keys($roles));
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$flag = substr($row['auth_option'], 0, strpos($row['auth_option'], '_') + 1);
|
|
|
f2e824 |
if ($flag == $row['auth_option'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$s_role_js_array[$row['role_id']] .= 'role_options[' . $row['role_id'] . '][\'' . addslashes($row['auth_option']) . '\'] = ' . $row['auth_setting'] . '; ';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
$s_role_js_array = implode('', $s_role_js_array);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_var('S_ROLE_JS_ARRAY', $s_role_js_array);
|
|
|
f2e824 |
unset($s_role_js_array);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Now obtain memberships
|
|
|
f2e824 |
$user_groups_default = $user_groups_custom = array();
|
|
|
f2e824 |
if ($user_mode == 'user' && $group_display)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT group_id, group_name, group_type
|
|
|
f2e824 |
FROM ' . GROUPS_TABLE . '
|
|
|
f2e824 |
ORDER BY group_type DESC, group_name ASC';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$groups = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$groups[$row['group_id']] = $row;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
$memberships = group_memberships(false, array_keys($hold_ary), false);
|
|
|
f2e824 |
|
|
|
f2e824 |
// User is not a member of any group? Bad admin, bad bad admin...
|
|
|
f2e824 |
if ($memberships)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($memberships as $row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($groups[$row['group_id']]['group_type'] == GROUP_SPECIAL)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$user_groups_default[$row['user_id']][] = $user->lang['G_' . $groups[$row['group_id']]['group_name']];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$user_groups_custom[$row['user_id']][] = $groups[$row['group_id']]['group_name'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($memberships, $groups);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// If we only have one forum id to display or being in local mode and more than one user/group to display,
|
|
|
f2e824 |
// we switch the complete interface to group by user/usergroup instead of grouping by forum
|
|
|
f2e824 |
// To achieve this, we need to switch the array a bit
|
|
|
f2e824 |
if (sizeof($forum_ids) == 1 || ($local && sizeof($ug_names_ary) > 1))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary_temp = $hold_ary;
|
|
|
f2e824 |
$hold_ary = array();
|
|
|
f2e824 |
foreach ($hold_ary_temp as $ug_id => $row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($forum_names_ary as $forum_id => $forum_row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (isset($row[$forum_id]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[$forum_id][$ug_id] = $row[$forum_id];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($hold_ary_temp);
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($hold_ary as $forum_id => $forum_array)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$content_array = $categories = array();
|
|
|
f2e824 |
$this->build_permission_array($hold_ary[$forum_id], $content_array, $categories, array_keys($ug_names_ary));
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars($tpl_pmask, array(
|
|
|
f2e824 |
'NAME' => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],
|
|
|
f2e824 |
'PADDING' => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],
|
|
|
f2e824 |
|
|
|
f2e824 |
'CATEGORIES' => implode('', $categories),
|
|
|
f2e824 |
|
|
|
f2e824 |
'L_ACL_TYPE' => $l_acl_type,
|
|
|
f2e824 |
|
|
|
f2e824 |
'S_LOCAL' => ($local) ? true : false,
|
|
|
f2e824 |
'S_GLOBAL' => (!$local) ? true : false,
|
|
|
f2e824 |
'S_NUM_CATS' => sizeof($categories),
|
|
|
f2e824 |
'S_VIEW' => ($mode == 'view') ? true : false,
|
|
|
f2e824 |
'S_NUM_OBJECTS' => sizeof($content_array),
|
|
|
f2e824 |
'S_USER_MODE' => ($user_mode == 'user') ? true : false,
|
|
|
f2e824 |
'S_GROUP_MODE' => ($user_mode == 'group') ? true : false)
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
@reset($content_array);
|
|
|
f2e824 |
while (list($ug_id, $ug_array) = each($content_array))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Build role dropdown options
|
|
|
f2e824 |
$current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
|
|
|
f2e824 |
|
|
|
f2e824 |
$s_role_options = '';
|
|
|
f2e824 |
|
|
|
f2e824 |
@reset($roles);
|
|
|
f2e824 |
while (list($role_id, $role_row) = each($roles))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);
|
|
|
f2e824 |
$role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
|
|
|
f2e824 |
|
|
|
f2e824 |
$title = ($role_description) ? ' title="' . $role_description . '"' : '';
|
|
|
f2e824 |
$s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_name . '</option>';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($s_role_options)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$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;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$current_role_id && $mode != 'view')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_custom_permissions = false;
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($ug_array as $key => $value)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($value['S_NEVER'] || $value['S_YES'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_custom_permissions = true;
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_custom_permissions = false;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(
|
|
|
f2e824 |
'NAME' => $ug_names_ary[$ug_id],
|
|
|
f2e824 |
'S_ROLE_OPTIONS' => $s_role_options,
|
|
|
f2e824 |
'UG_ID' => $ug_id,
|
|
|
f2e824 |
'S_CUSTOM' => $s_custom_permissions,
|
|
|
f2e824 |
'FORUM_ID' => $forum_id)
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
$this->assign_cat_array($ug_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, $show_trace, ($mode == 'view'));
|
|
|
f2e824 |
|
|
|
f2e824 |
unset($content_array[$ug_id]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
unset($hold_ary[$forum_id]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($ug_names_ary as $ug_id => $ug_name)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!isset($hold_ary[$ug_id]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$content_array = $categories = array();
|
|
|
f2e824 |
$this->build_permission_array($hold_ary[$ug_id], $content_array, $categories, array_keys($forum_names_ary));
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars($tpl_pmask, array(
|
|
|
f2e824 |
'NAME' => $ug_name,
|
|
|
f2e824 |
'CATEGORIES' => implode('', $categories),
|
|
|
f2e824 |
|
|
|
f2e824 |
'USER_GROUPS_DEFAULT' => ($user_mode == 'user' && isset($user_groups_default[$ug_id]) && sizeof($user_groups_default[$ug_id])) ? implode(', ', $user_groups_default[$ug_id]) : '',
|
|
|
f2e824 |
'USER_GROUPS_CUSTOM' => ($user_mode == 'user' && isset($user_groups_custom[$ug_id]) && sizeof($user_groups_custom[$ug_id])) ? implode(', ', $user_groups_custom[$ug_id]) : '',
|
|
|
f2e824 |
'L_ACL_TYPE' => $l_acl_type,
|
|
|
f2e824 |
|
|
|
f2e824 |
'S_LOCAL' => ($local) ? true : false,
|
|
|
f2e824 |
'S_GLOBAL' => (!$local) ? true : false,
|
|
|
f2e824 |
'S_NUM_CATS' => sizeof($categories),
|
|
|
f2e824 |
'S_VIEW' => ($mode == 'view') ? true : false,
|
|
|
f2e824 |
'S_NUM_OBJECTS' => sizeof($content_array),
|
|
|
f2e824 |
'S_USER_MODE' => ($user_mode == 'user') ? true : false,
|
|
|
f2e824 |
'S_GROUP_MODE' => ($user_mode == 'group') ? true : false)
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
@reset($content_array);
|
|
|
f2e824 |
while (list($forum_id, $forum_array) = each($content_array))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Build role dropdown options
|
|
|
f2e824 |
$current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
|
|
|
f2e824 |
|
|
|
f2e824 |
$s_role_options = '';
|
|
|
f2e824 |
|
|
|
f2e824 |
@reset($roles);
|
|
|
f2e824 |
while (list($role_id, $role_row) = each($roles))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);
|
|
|
f2e824 |
$role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
|
|
|
f2e824 |
|
|
|
f2e824 |
$title = ($role_description) ? ' title="' . $role_description . '"' : '';
|
|
|
f2e824 |
$s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_name . '</option>';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($s_role_options)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$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;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$current_role_id && $mode != 'view')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_custom_permissions = false;
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($forum_array as $key => $value)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($value['S_NEVER'] || $value['S_YES'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_custom_permissions = true;
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_custom_permissions = false;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(
|
|
|
f2e824 |
'NAME' => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],
|
|
|
f2e824 |
'PADDING' => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],
|
|
|
f2e824 |
'S_ROLE_OPTIONS' => $s_role_options,
|
|
|
f2e824 |
'S_CUSTOM' => $s_custom_permissions,
|
|
|
f2e824 |
'UG_ID' => $ug_id,
|
|
|
f2e824 |
'FORUM_ID' => $forum_id)
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
$this->assign_cat_array($forum_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, $show_trace, ($mode == 'view'));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
unset($hold_ary[$ug_id], $ug_names_ary[$ug_id]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Display permission mask for roles
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function display_role_mask(&$hold_ary)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db, $template, $user, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!sizeof($hold_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
return;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get forum names
|
|
|
f2e824 |
$sql = 'SELECT forum_id, forum_name
|
|
|
f2e824 |
FROM ' . FORUMS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('forum_id', array_keys($hold_ary)) . '
|
|
|
f2e824 |
ORDER BY left_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
// If the role is used globally, then reflect that
|
|
|
f2e824 |
$forum_names = (isset($hold_ary[0])) ? array(0 => '') : array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_names[$row['forum_id']] = $row['forum_name'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($forum_names as $forum_id => $forum_name)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth_ary = $hold_ary[$forum_id];
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars('role_mask', array(
|
|
|
f2e824 |
'NAME' => ($forum_id == 0) ? $user->lang['GLOBAL_MASK'] : $forum_name,
|
|
|
f2e824 |
'FORUM_ID' => $forum_id)
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (isset($auth_ary['users']) && sizeof($auth_ary['users']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT user_id, username
|
|
|
f2e824 |
FROM ' . USERS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('user_id', $auth_ary['users']) . '
|
|
|
f2e824 |
ORDER BY username_clean ASC';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_block_vars('role_mask.users', array(
|
|
|
f2e824 |
'USER_ID' => $row['user_id'],
|
|
|
f2e824 |
'USERNAME' => $row['username'],
|
|
|
f2e824 |
'U_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&u={$row['user_id']}"))
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (isset($auth_ary['groups']) && sizeof($auth_ary['groups']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT group_id, group_name, group_type
|
|
|
f2e824 |
FROM ' . GROUPS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('group_id', $auth_ary['groups']) . '
|
|
|
f2e824 |
ORDER BY group_type ASC, group_name';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_block_vars('role_mask.groups', array(
|
|
|
f2e824 |
'GROUP_ID' => $row['group_id'],
|
|
|
f2e824 |
'GROUP_NAME' => ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
|
|
|
f2e824 |
'U_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=group&g={$row['group_id']}"))
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* NOTE: this function is not in use atm
|
|
|
f2e824 |
* Add a new option to the list ... $options is a hash of form ->
|
|
|
f2e824 |
* $options = array(
|
|
|
f2e824 |
* 'local' => array('option1', 'option2', ...),
|
|
|
f2e824 |
* 'global' => array('optionA', 'optionB', ...)
|
|
|
f2e824 |
* );
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function acl_add_option($options)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db, $cache;
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!is_array($options))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
return false;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$cur_options = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT auth_option, is_global, is_local
|
|
|
f2e824 |
FROM ' . ACL_OPTIONS_TABLE . '
|
|
|
f2e824 |
ORDER BY auth_option_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($row['is_global'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$cur_options['global'][] = $row['auth_option'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['is_local'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$cur_options['local'][] = $row['auth_option'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Here we need to insert new options ... this requires discovering whether
|
|
|
f2e824 |
// an options is global, local or both and whether we need to add an permission
|
|
|
f2e824 |
// set flag (x_)
|
|
|
f2e824 |
$new_options = array('local' => array(), 'global' => array());
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($options as $type => $option_ary)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$option_ary = array_unique($option_ary);
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($option_ary as $option_value)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!in_array($option_value, $cur_options[$type]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$new_options[$type][] = $option_value;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$flag = substr($option_value, 0, strpos($option_value, '_') + 1);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!in_array($flag, $cur_options[$type]) && !in_array($flag, $new_options[$type]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$new_options[$type][] = $flag;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($options);
|
|
|
f2e824 |
|
|
|
f2e824 |
$options = array();
|
|
|
f2e824 |
$options['local'] = array_diff($new_options['local'], $new_options['global']);
|
|
|
f2e824 |
$options['global'] = array_diff($new_options['global'], $new_options['local']);
|
|
|
f2e824 |
$options['local_global'] = array_intersect($new_options['local'], $new_options['global']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql_ary = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($options as $type => $option_ary)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($option_ary as $option)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_ary[] = array(
|
|
|
f2e824 |
'auth_option' => (string) $option,
|
|
|
f2e824 |
'is_global' => ($type == 'global' || $type == 'local_global') ? 1 : 0,
|
|
|
f2e824 |
'is_local' => ($type == 'local' || $type == 'local_global') ? 1 : 0
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$db->sql_multi_insert(ACL_OPTIONS_TABLE, $sql_ary);
|
|
|
f2e824 |
|
|
|
f2e824 |
$cache->destroy('_acl_options');
|
|
|
f2e824 |
$this->acl_clear_prefetch();
|
|
|
f2e824 |
|
|
|
f2e824 |
// Because we just changed the options and also purged the options cache, we instantly update/regenerate it for later calls to succeed.
|
|
|
f2e824 |
$this->acl_options = array();
|
|
|
f2e824 |
$this->auth_admin();
|
|
|
f2e824 |
|
|
|
f2e824 |
return true;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Set a user or group ACL record
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function acl_set($ug_type, $forum_id, $ug_id, $auth, $role_id = 0, $clear_prefetch = true)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db;
|
|
|
f2e824 |
|
|
|
f2e824 |
// One or more forums
|
|
|
f2e824 |
if (!is_array($forum_id))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_id = array($forum_id);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// One or more users
|
|
|
f2e824 |
if (!is_array($ug_id))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$ug_id = array($ug_id);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$ug_id_sql = $db->sql_in_set($ug_type . '_id', array_map('intval', $ug_id));
|
|
|
f2e824 |
$forum_sql = $db->sql_in_set('forum_id', array_map('intval', $forum_id));
|
|
|
f2e824 |
|
|
|
f2e824 |
// Instead of updating, inserting, removing we just remove all current settings and re-set everything...
|
|
|
f2e824 |
$table = ($ug_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
|
|
|
f2e824 |
$id_field = $ug_type . '_id';
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get any flags as required
|
|
|
f2e824 |
reset($auth);
|
|
|
f2e824 |
$flag = key($auth);
|
|
|
f2e824 |
$flag = substr($flag, 0, strpos($flag, '_') + 1);
|
|
|
f2e824 |
|
|
|
f2e824 |
// This ID (the any-flag) is set if one or more permissions are true...
|
|
|
f2e824 |
$any_option_id = (int) $this->acl_options['id'][$flag];
|
|
|
f2e824 |
|
|
|
f2e824 |
// Remove any-flag from auth ary
|
|
|
f2e824 |
if (isset($auth[$flag]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
unset($auth[$flag]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Remove current auth options...
|
|
|
f2e824 |
$auth_option_ids = array((int)$any_option_id);
|
|
|
f2e824 |
foreach ($auth as $auth_option => $auth_setting)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth_option_ids[] = (int) $this->acl_options['id'][$auth_option];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = "DELETE FROM $table
|
|
|
f2e824 |
WHERE $forum_sql
|
|
|
f2e824 |
AND $ug_id_sql
|
|
|
f2e824 |
AND " . $db->sql_in_set('auth_option_id', $auth_option_ids);
|
|
|
f2e824 |
$db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Remove those having a role assigned... the correct type of course...
|
|
|
f2e824 |
$sql = 'SELECT role_id
|
|
|
f2e824 |
FROM ' . ACL_ROLES_TABLE . "
|
|
|
f2e824 |
WHERE role_type = '" . $db->sql_escape($flag) . "'";
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$role_ids = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$role_ids[] = $row['role_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($role_ids))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = "DELETE FROM $table
|
|
|
f2e824 |
WHERE $forum_sql
|
|
|
f2e824 |
AND $ug_id_sql
|
|
|
f2e824 |
AND auth_option_id = 0
|
|
|
f2e824 |
AND " . $db->sql_in_set('auth_role_id', $role_ids);
|
|
|
f2e824 |
$db->sql_query($sql);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Ok, include the any-flag if one or more auth options are set to yes...
|
|
|
f2e824 |
foreach ($auth as $auth_option => $setting)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth[$flag] = ACL_YES;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql_ary = array();
|
|
|
f2e824 |
foreach ($forum_id as $forum)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum = (int) $forum;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($role_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($ug_id as $id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_ary[] = array(
|
|
|
f2e824 |
$id_field => (int) $id,
|
|
|
f2e824 |
'forum_id' => (int) $forum,
|
|
|
f2e824 |
'auth_option_id' => 0,
|
|
|
f2e824 |
'auth_setting' => 0,
|
|
|
f2e824 |
'auth_role_id' => (int) $role_id,
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($auth as $auth_option => $setting)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth_option_id = (int) $this->acl_options['id'][$auth_option];
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($setting != ACL_NO)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($ug_id as $id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_ary[] = array(
|
|
|
f2e824 |
$id_field => (int) $id,
|
|
|
f2e824 |
'forum_id' => (int) $forum,
|
|
|
f2e824 |
'auth_option_id' => (int) $auth_option_id,
|
|
|
f2e824 |
'auth_setting' => (int) $setting
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$db->sql_multi_insert($table, $sql_ary);
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($clear_prefetch)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$this->acl_clear_prefetch();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Set a role-specific ACL record
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function acl_set_role($role_id, $auth)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db;
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get any-flag as required
|
|
|
f2e824 |
reset($auth);
|
|
|
f2e824 |
$flag = key($auth);
|
|
|
f2e824 |
$flag = substr($flag, 0, strpos($flag, '_') + 1);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Remove any-flag from auth ary
|
|
|
f2e824 |
if (isset($auth[$flag]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
unset($auth[$flag]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Re-set any flag...
|
|
|
f2e824 |
foreach ($auth as $auth_option => $setting)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth[$flag] = ACL_YES;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql_ary = array();
|
|
|
f2e824 |
foreach ($auth as $auth_option => $setting)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth_option_id = (int) $this->acl_options['id'][$auth_option];
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($setting != ACL_NO)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_ary[] = array(
|
|
|
f2e824 |
'role_id' => (int) $role_id,
|
|
|
f2e824 |
'auth_option_id' => (int) $auth_option_id,
|
|
|
f2e824 |
'auth_setting' => (int) $setting
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// If no data is there, we set the any-flag to ACL_NEVER...
|
|
|
f2e824 |
if (!sizeof($sql_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_ary[] = array(
|
|
|
f2e824 |
'role_id' => (int) $role_id,
|
|
|
f2e824 |
'auth_option_id' => (int) $this->acl_options['id'][$flag],
|
|
|
f2e824 |
'auth_setting' => ACL_NEVER
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Remove current auth options...
|
|
|
f2e824 |
$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
|
|
|
f2e824 |
WHERE role_id = ' . $role_id;
|
|
|
f2e824 |
$db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Now insert the new values
|
|
|
f2e824 |
$db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);
|
|
|
f2e824 |
|
|
|
f2e824 |
$this->acl_clear_prefetch();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Remove local permission
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function acl_delete($mode, $ug_id = false, $forum_id = false, $permission_type = false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($ug_id === false && $forum_id === false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
return;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$option_id_ary = array();
|
|
|
f2e824 |
$table = ($mode == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
|
|
|
f2e824 |
$id_field = $mode . '_id';
|
|
|
f2e824 |
|
|
|
f2e824 |
$where_sql = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($forum_id !== false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$where_sql[] = (!is_array($forum_id)) ? 'forum_id = ' . (int) $forum_id : $db->sql_in_set('forum_id', array_map('intval', $forum_id));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($ug_id !== false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$where_sql[] = (!is_array($ug_id)) ? $id_field . ' = ' . (int) $ug_id : $db->sql_in_set($id_field, array_map('intval', $ug_id));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// There seem to be auth options involved, therefore we need to go through the list and make sure we capture roles correctly
|
|
|
f2e824 |
if ($permission_type !== false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Get permission type
|
|
|
f2e824 |
$sql = 'SELECT auth_option, auth_option_id
|
|
|
f2e824 |
FROM ' . ACL_OPTIONS_TABLE . "
|
|
|
f2e824 |
WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char);
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$auth_id_ary = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$option_id_ary[] = $row['auth_option_id'];
|
|
|
f2e824 |
$auth_id_ary[$row['auth_option']] = ACL_NO;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// First of all, lets grab the items having roles with the specified auth options assigned
|
|
|
f2e824 |
$sql = "SELECT auth_role_id, $id_field, forum_id
|
|
|
f2e824 |
FROM $table, " . ACL_ROLES_TABLE . " r
|
|
|
f2e824 |
WHERE auth_role_id <> 0
|
|
|
f2e824 |
AND auth_role_id = r.role_id
|
|
|
f2e824 |
AND r.role_type = '{$permission_type}'
|
|
|
f2e824 |
AND " . implode(' AND ', $where_sql) . '
|
|
|
f2e824 |
ORDER BY auth_role_id';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$cur_role_auth = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$cur_role_auth[$row['auth_role_id']][$row['forum_id']][] = $row[$id_field];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Get role data for resetting data
|
|
|
f2e824 |
if (sizeof($cur_role_auth))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT ao.auth_option, rd.role_id, rd.auth_setting
|
|
|
f2e824 |
FROM ' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_ROLES_DATA_TABLE . ' rd
|
|
|
f2e824 |
WHERE ao.auth_option_id = rd.auth_option_id
|
|
|
f2e824 |
AND ' . $db->sql_in_set('rd.role_id', array_keys($cur_role_auth));
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$auth_settings = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// We need to fill all auth_options, else setting it will fail...
|
|
|
f2e824 |
if (!isset($auth_settings[$row['role_id']]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$auth_settings[$row['role_id']] = $auth_id_ary;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$auth_settings[$row['role_id']][$row['auth_option']] = $row['auth_setting'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Set the options
|
|
|
f2e824 |
foreach ($cur_role_auth as $role_id => $auth_row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($auth_row as $f_id => $ug_row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$this->acl_set($mode, $f_id, $ug_row, $auth_settings[$role_id], 0, false);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Now, normally remove permissions...
|
|
|
f2e824 |
if ($permission_type !== false)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$where_sql[] = $db->sql_in_set('auth_option_id', array_map('intval', $option_id_ary));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = "DELETE FROM $table
|
|
|
f2e824 |
WHERE " . implode(' AND ', $where_sql);
|
|
|
f2e824 |
$db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$this->acl_clear_prefetch();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Assign category to template
|
|
|
f2e824 |
* used by display_mask()
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function assign_cat_array(&$category_array, $tpl_cat, $tpl_mask, $ug_id, $forum_id, $show_trace = false, $s_view)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $template, $user, $phpbb_admin_path, $phpEx;
|
|
|
f2e824 |
|
|
|
f2e824 |
@reset($category_array);
|
|
|
f2e824 |
while (list($cat, $cat_array) = each($category_array))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_block_vars($tpl_cat, array(
|
|
|
f2e824 |
'S_YES' => ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,
|
|
|
f2e824 |
'S_NEVER' => ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,
|
|
|
f2e824 |
'S_NO' => ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false,
|
|
|
f2e824 |
|
|
|
f2e824 |
'CAT_NAME' => $user->lang['permission_cat'][$cat])
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
/* Sort permissions by name (more naturaly and user friendly than sorting by a primary key)
|
|
|
f2e824 |
* Commented out due to it's memory consumption and time needed
|
|
|
f2e824 |
*
|
|
|
f2e824 |
$key_array = array_intersect(array_keys($user->lang), array_map(create_function('$a', 'return "acl_" . $a;'), array_keys($cat_array['permissions'])));
|
|
|
f2e824 |
$values_array = $cat_array['permissions'];
|
|
|
f2e824 |
|
|
|
f2e824 |
$cat_array['permissions'] = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($key_array as $key)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$key = str_replace('acl_', '', $key);
|
|
|
f2e824 |
$cat_array['permissions'][$key] = $values_array[$key];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($key_array, $values_array);
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
@reset($cat_array['permissions']);
|
|
|
f2e824 |
while (list($permission, $allowed) = each($cat_array['permissions']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($s_view)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(
|
|
|
f2e824 |
'S_YES' => ($allowed == ACL_YES) ? true : false,
|
|
|
f2e824 |
'S_NEVER' => ($allowed == ACL_NEVER) ? true : false,
|
|
|
f2e824 |
|
|
|
f2e824 |
'UG_ID' => $ug_id,
|
|
|
f2e824 |
'FORUM_ID' => $forum_id,
|
|
|
f2e824 |
'FIELD_NAME' => $permission,
|
|
|
f2e824 |
'S_FIELD_NAME' => 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',
|
|
|
f2e824 |
|
|
|
f2e824 |
'U_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission") : '',
|
|
|
f2e824 |
'UA_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',
|
|
|
f2e824 |
|
|
|
f2e824 |
'PERMISSION' => $user->lang['acl_' . $permission]['lang'])
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(
|
|
|
f2e824 |
'S_YES' => ($allowed == ACL_YES) ? true : false,
|
|
|
f2e824 |
'S_NEVER' => ($allowed == ACL_NEVER) ? true : false,
|
|
|
f2e824 |
'S_NO' => ($allowed == ACL_NO) ? true : false,
|
|
|
f2e824 |
|
|
|
f2e824 |
'UG_ID' => $ug_id,
|
|
|
f2e824 |
'FORUM_ID' => $forum_id,
|
|
|
f2e824 |
'FIELD_NAME' => $permission,
|
|
|
f2e824 |
'S_FIELD_NAME' => 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',
|
|
|
f2e824 |
|
|
|
f2e824 |
'U_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission") : '',
|
|
|
f2e824 |
'UA_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',
|
|
|
f2e824 |
|
|
|
f2e824 |
'PERMISSION' => $user->lang['acl_' . $permission]['lang'])
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Building content array from permission rows with explicit key ordering
|
|
|
f2e824 |
* used by display_mask()
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function build_permission_array(&$permission_row, &$content_array, &$categories, $key_sort_array)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $user;
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($key_sort_array as $forum_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!isset($permission_row[$forum_id]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$permissions = $permission_row[$forum_id];
|
|
|
f2e824 |
ksort($permissions);
|
|
|
f2e824 |
|
|
|
f2e824 |
@reset($permissions);
|
|
|
f2e824 |
while (list($permission, $auth_setting) = each($permissions))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!isset($user->lang['acl_' . $permission]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$user->lang['acl_' . $permission] = array(
|
|
|
f2e824 |
'cat' => 'misc',
|
|
|
f2e824 |
'lang' => '{ acl_' . $permission . ' }'
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$cat = $user->lang['acl_' . $permission]['cat'];
|
|
|
f2e824 |
|
|
|
f2e824 |
// Build our categories array
|
|
|
f2e824 |
if (!isset($categories[$cat]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$categories[$cat] = $user->lang['permission_cat'][$cat];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Build our content array
|
|
|
f2e824 |
if (!isset($content_array[$forum_id]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$content_array[$forum_id] = array();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!isset($content_array[$forum_id][$cat]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$content_array[$forum_id][$cat] = array(
|
|
|
f2e824 |
'S_YES' => false,
|
|
|
f2e824 |
'S_NEVER' => false,
|
|
|
f2e824 |
'S_NO' => false,
|
|
|
f2e824 |
'permissions' => array(),
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$content_array[$forum_id][$cat]['S_YES'] |= ($auth_setting == ACL_YES) ? true : false;
|
|
|
f2e824 |
$content_array[$forum_id][$cat]['S_NEVER'] |= ($auth_setting == ACL_NEVER) ? true : false;
|
|
|
f2e824 |
$content_array[$forum_id][$cat]['S_NO'] |= ($auth_setting == ACL_NO) ? true : false;
|
|
|
f2e824 |
|
|
|
f2e824 |
$content_array[$forum_id][$cat]['permissions'][$permission] = $auth_setting;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* Use permissions from another user. This transferes a permission set from one user to another.
|
|
|
f2e824 |
* The other user is always able to revert back to his permission set.
|
|
|
f2e824 |
* This function does not check for lower/higher permissions, it is possible for the user to gain
|
|
|
f2e824 |
* "more" permissions by this.
|
|
|
f2e824 |
* Admin permissions will not be copied.
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
function ghost_permissions($from_user_id, $to_user_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
global $db;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($to_user_id == ANONYMOUS)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
return false;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$hold_ary = $this->acl_raw_data_single_user($from_user_id);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Key 0 in $hold_ary are global options, all others are forum_ids
|
|
|
f2e824 |
|
|
|
f2e824 |
// We disallow copying admin permissions
|
|
|
f2e824 |
foreach ($this->acl_options['global'] as $opt => $id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (strpos($opt, 'a_') === 0)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hold_ary[0][$this->acl_options['id'][$opt]] = ACL_NEVER;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Force a_switchperm to be allowed
|
|
|
f2e824 |
$hold_ary[0][$this->acl_options['id']['a_switchperm']] = ACL_YES;
|
|
|
f2e824 |
|
|
|
f2e824 |
$user_permissions = $this->build_bitstring($hold_ary);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$user_permissions)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
return false;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
|
f2e824 |
SET user_permissions = '" . $db->sql_escape($user_permissions) . "',
|
|
|
f2e824 |
user_perm_from = $from_user_id
|
|
|
f2e824 |
WHERE user_id = " . $to_user_id;
|
|
|
f2e824 |
$db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
return true;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
?>
|