1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-19 05:49:44 +02:00

fix "copy permissions" as well as shortening the $acl_url for redirecting to the permissions screen.

git-svn-id: file:///svn/phpbb/trunk@5715 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2006-03-25 15:32:52 +00:00
parent 791b580f43
commit 844aad7ff7
3 changed files with 128 additions and 44 deletions

View File

@ -146,28 +146,78 @@ class acp_forums
// Copy permissions?
if ($forum_perm_from && $action == 'add')
{
$sql_ary = array(
'a.user_id' => array('user_id'),
'a.forum_id' => (int) $forum_data['forum_id'],
'a.auth_option_id' => array('auth_option_id'),
'a.auth_role_id' => array('auth_role_id'),
'a.auth_setting' => array('auth_setting')
);
// From the mysql documentation:
// Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
// Due to this we stay on the safe side if we do the insertion "the manual way"
// We copy the permissions the manual way. ;)
$sql = 'INSERT INTO ' . ACL_USERS_TABLE . ' a ' . $db->sql_build_array('INSERT_SELECT', $sql_ary) . '
FROM ' . ACL_USERS_TABLE . ' b
WHERE b.forum_id = ' . $forum_perm_from;
$db->sql_query($sql);
// Change array for copying settings from the acl groups table
unset($sql_ary['user_id']);
$sql_ary['group_id'] = array('group_id');
$sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . ' a ' . $db->sql_build_array('INSERT_SELECT', $sql_ary) . '
FROM ' . ACL_GROUPS_TABLE . ' b
WHERE b.forum_id = ' . $forum_perm_from;
$db->sql_query($sql);
// Copy permisisons from/to the acl users table (only forum_id gets changed)
$sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_USERS_TABLE . '
WHERE forum_id = ' . $forum_perm_from;
$result = $db->sql_query($sql);
$users_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$users_sql_ary[] = array(
'user_id' => (int) $row['user_id'],
'forum_id' => (int) $forum_data['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
// Copy permisisons from/to the acl groups table (only forum_id gets changed)
$sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_GROUPS_TABLE . '
WHERE forum_id = ' . $forum_perm_from;
$result = $db->sql_query($sql);
$groups_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$groups_sql_ary[] = array(
'group_id' => (int) $row['group_id'],
'forum_id' => (int) $forum_data['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
// Now insert the data
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
if (sizeof($users_sql_ary))
{
$db->sql_query('INSERT INTO ' . ACL_USERS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $users_sql_ary));
}
if (sizeof($groups_sql_ary))
{
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $groups_sql_ary));
}
break;
default:
foreach ($users_sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
foreach ($groups_sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
$auth->acl_clear_prefetch();
@ -175,20 +225,8 @@ class acp_forums
recalc_btree('forum_id', FORUMS_TABLE);
$acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
$acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'] . '&select_all_groups=1';
// Add default groups to selection
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . '
WHERE group_type = ' . GROUP_SPECIAL;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$acl_url .= '&group_id[]=' . $row['group_id'];
}
$db->sql_freeresult($result);
// Redirect to permissions
$message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
$message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . $phpbb_admin_path . "index.$phpEx$SID&amp;i=permissions" . $acl_url . '">', '</a>');

View File

@ -335,19 +335,48 @@ class acp_groups
// Copy permissions?
if ($group_perm_from && $action == 'add')
{
$sql_ary = array(
'group_id' => $group_id,
'forum_id' => array('forum_id'),
'auth_option_id' => array('auth_option_id'),
'auth_role_id' => array('auth_role_id'),
'auth_setting' => array('auth_setting')
);
// From the mysql documentation:
// Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
// Due to this we stay on the safe side if we do the insertion "the manual way"
// We copy the permissions the manual way. ;)
$sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT_SELECT', $sql_ary) . '
FROM ' . ACL_GROUPS_TABLE . '
// Copy permisisons from/to the acl groups table (only group_id gets changed)
$sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_GROUPS_TABLE . '
WHERE group_id = ' . $group_perm_from;
$db->sql_query($sql);
$result = $db->sql_query($sql);
$groups_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$groups_sql_ary[] = array(
'group_id' => (int) $group_id,
'forum_id' => (int) $row['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
// Now insert the data
if (sizeof($groups_sql_ary))
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $groups_sql_ary));
break;
default:
foreach ($groups_sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
$auth->acl_clear_prefetch();
}

View File

@ -45,7 +45,24 @@ class acp_permissions
$user_id = request_var('user_id', array(0));
$group_id = request_var('group_id', array(0));
$select_all_groups = request_var('select_all_groups', 0);
// If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen)
if ($select_all_groups)
{
// Add default groups to selection
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . '
WHERE group_type = ' . GROUP_SPECIAL;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$group_id[] = $row['group_id'];
}
$db->sql_freeresult($result);
}
// Map usernames to ids and vice versa
if ($usernames)
{