diff --git a/phpBB/admin/userauth.php b/phpBB/admin/userauth.php
index 45aa01d456..ed2f33c26c 100644
--- a/phpBB/admin/userauth.php
+++ b/phpBB/admin/userauth.php
@@ -29,6 +29,51 @@ $auth_field_match = array(
);
$forum_auth_fields = array("auth_view", "auth_read", "auth_post", "auth_reply", "auth_edit", "auth_delete", "auth_sticky", "auth_announce", "auth_votecreate", "auth_vote", "auth_attachments");
+$forum_auth_key_fields = array("auth_view", "auth_read", "auth_post", "auth_reply");
+
+// ----------
+// Start Functions
+//
+function a_auth_check_user($type, $key, $u_auth, $is_admin)
+{
+
+ $single_user = 0;
+ $auth_user = array();
+
+ while( list($entry, $u_ary) = each($u_auth) )
+ {
+ if(!$single_user)
+ {
+ $single_user = $u_ary['group_single_user'];
+
+ $result = 0;
+ switch($type)
+ {
+ case AUTH_ACL:
+ $result = $u_ary[$key];
+
+ case AUTH_MOD:
+ $result = $result || $u_ary['auth_mod'];
+
+ case AUTH_ADMIN:
+ $result = $result || $is_admin;
+ break;
+ }
+
+ $auth_user['auth'] = (!$single_user) ? ( $auth_user || $result ) : $result;
+
+ }
+ $auth_user['single_group'] = ($single_user) ? "single" : "group";
+
+ }
+
+ return $auth_user;
+}
+//
+// Start Functions
+// ----------
+
+
//
//
//
@@ -67,16 +112,18 @@ if(isset($HTTP_POST_VARS['submit']) && !empty($HTTP_POST_VARS[POST_USERS_URL]))
if( !$HTTP_POST_VARS['makeadmin'] && $HTTP_POST_VARS['curadmin'] )
{
//
- // Delete any entries granting moderator
- // status in auth_access
+ // Delete any entries granting in auth_access
//
$sql_unmod = "DELETE FROM " . AUTH_ACCESS_TABLE . "
WHERE group_id = $group_id";
if(!$result = $db->sql_query($sql_unmod))
{
// Error, couldn't delete entries
- }
+ }
+ //
+ // Update users level, reset to USER
+ //
$sql_userlevel = "UPDATE " . USERS_TABLE . "
SET user_level = " . USER . "
WHERE user_id = $user_id";
@@ -91,10 +138,7 @@ if(isset($HTTP_POST_VARS['submit']) && !empty($HTTP_POST_VARS[POST_USERS_URL]))
else if( $HTTP_POST_VARS['makeadmin'] && !$HTTP_POST_VARS['curadmin'] )
{
//
- // Need to switch on admin
- // level, this also requires
- // we remove this user from all
- // auth fields(?)
+ // Switch user_level to ADMIN
//
$sql_userlevel = "UPDATE " . USERS_TABLE . "
SET user_level = " . ADMIN . "
@@ -103,43 +147,37 @@ if(isset($HTTP_POST_VARS['submit']) && !empty($HTTP_POST_VARS[POST_USERS_URL]))
{
// Error, couldn't set user level
}
-
+
+ // This needs changing -> Remove the
+ // user from auth_access where special
+ // access permissions are granted but leave
+ // moderator status
//
+ // ---------------------------------------
// Delete any entries in auth_access, they
// are unrequired if user is becoming an
// admin
//
- $sql_unmod = "DELETE FROM " . AUTH_ACCESS_TABLE . "
+ $sql_unauth = "DELETE FROM " . AUTH_ACCESS_TABLE . "
WHERE aa.group_id = $group_id";
- if(!$result = $db->sql_query($sql_unmod))
+ if(!$result = $db->sql_query($sql_unauth))
{
// Error, couldn't delete entries
}
//
- // Remove user from any groups
//
- $sql_rmgrp = "DELETE FROM " . USER_GROUP_TABLE . "
- WHERE user_id = $user_id
- AND group_id <> $group_id";
- if(!$result = $db->sql_query($sql_rmgrp))
- {
- // Error, couldn't delete entries
- }
-
-
- $sql_mod = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod)
- VALUES ($group_id, 0, 1)";
- if(!$result = $db->sql_query($sql_mod))
- {
- // Error, couldn't delete entries
- }
+ // ----------------------------------------
header("Location: userauth.$phpEx?" . POST_USERS_URL . "=$user_id");
}
else
{
+
+ $change_mod_ary = (isset($HTTP_POST_VARS['moderator'])) ? $HTTP_POST_VARS['moderator'] : 0;
+ $change_prv_ary = (isset($HTTP_POST_VARS['private'])) ? $HTTP_POST_VARS['private'] : 0;
+
//
// Pull all the group info
// for this user
@@ -149,7 +187,7 @@ if(isset($HTTP_POST_VARS['submit']) && !empty($HTTP_POST_VARS[POST_USERS_URL]))
WHERE ug.user_id = $user_id
AND g.group_id = ug.group_id
AND aa.group_id = ug.group_id
- AND g.group_single_user <> 1";
+ AND g.group_single_user <> " . TRUE;
$au_result = $db->sql_query($sql);
$num_u_access = $db->sql_numrows($au_result);
@@ -158,6 +196,87 @@ if(isset($HTTP_POST_VARS['submit']) && !empty($HTTP_POST_VARS[POST_USERS_URL]))
$u_access = $db->sql_fetchrowset($au_result);
}
+ //
+ // The data above lists access and moderator permissions
+ // for this user given by all the groups they belong to.
+ // These values must be checked against those requested
+ // by the admin and where necessary the admin is
+ // informed of problems. For example, if a group the user
+ // belongs to already grants the user moderator status
+ // then the user won't have moderator status enabled.
+ // If the user has a group entry preventing access to a
+ // forum then again, we must warn the admin that giving
+ // the user access goes against the group permissions
+ // (although in this case we'll go ahead and add the user)
+ //
+
+ //
+ // Check against moderator table ...
+ //
+ $valid_auth_mod_chg = array();
+ reset($change_mod_ary);
+ while(list($chg_forum_id, $value) = each($change_mod_ary))
+ {
+ $a_match = $value;
+ for($i = 0; $i < count($u_access); $i++)
+ {
+ $forum_id = $u_access[$i]['forum_id'];
+
+ if($forum_id == $chg_forum_id && $u_access[$i]['auth_mod'] == 1)
+ {
+ $a_match = 0;
+ }
+ }
+
+ $valid_auth_mod_chg[$chg_forum_id] = $a_match;
+
+ }
+ //
+ // valid_auth_mod_chg now contains an array (key is forum_id)
+ // where the value is 1 if the user should be an admin and 0
+ // where the user is prevented (either by the admin disallowing
+ // or the user belonging to a group which already moderates)
+ //
+
+ print_r($valid_auth_mod_chg);
+ echo "
";
+
+ //
+ // Check against priv access table ...
+ //
+ $valid_auth_prv_chg = array();
+ reset($change_prv_ary);
+ while(list($chg_forum_id, $value) = each($change_prv_ary))
+ {
+ $a_match = $value;
+ for($i = 0; $i < count($u_access); $i++)
+ {
+ $forum_id = $u_access[$i]['forum_id'];
+
+ if($forum_id == $chg_forum_id)
+ {
+ for($k = 0; $k < count($forum_auth_key_fields); $k++)
+ {
+ $a_match = $a_match && $u_access[$i][$forum_auth_key_fields[$k]];
+ }
+ }
+ }
+
+ $valid_auth_prv_chg[$chg_forum_id] = $a_match;
+
+ }
+ //
+ // valid_auth_mod_chg now contains an array (key is forum_id)
+ // where the value is 1 if the user should be an admin and 0
+ // where the user is prevented (either by the admin disallowing
+ // or the user belonging to a group which already moderates)
+ //
+
+ print_r($valid_auth_prv_chg);
+ echo "