diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2006-03-25 15:32:52 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-03-25 15:32:52 +0000 |
commit | 844aad7ff70e4969f005e7d32baf34af89017eb2 (patch) | |
tree | 3db69170bd9622e6baa6da089367d7cca0bdb649 /phpBB/includes/acp | |
parent | 791b580f4392ea9442965714c1480326a96748da (diff) | |
download | forums-844aad7ff70e4969f005e7d32baf34af89017eb2.tar forums-844aad7ff70e4969f005e7d32baf34af89017eb2.tar.gz forums-844aad7ff70e4969f005e7d32baf34af89017eb2.tar.bz2 forums-844aad7ff70e4969f005e7d32baf34af89017eb2.tar.xz forums-844aad7ff70e4969f005e7d32baf34af89017eb2.zip |
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
Diffstat (limited to 'phpBB/includes/acp')
-rw-r--r-- | phpBB/includes/acp/acp_forums.php | 106 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_groups.php | 51 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_permissions.php | 17 |
3 files changed, 129 insertions, 45 deletions
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 59792b5e01..a7a5fd05da 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -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&i=permissions" . $acl_url . '">', '</a>'); diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index b932ca003d..fb84efc92a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -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(); } diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php index b07388c4e8..499e210784 100644 --- a/phpBB/includes/acp/acp_permissions.php +++ b/phpBB/includes/acp/acp_permissions.php @@ -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) { |