There's something not working. I can't manage to clean the
cache, even outside the function...
If want, please try to upload this code to the admin/ directory
and try to execute vs. some private/protected forum (&forumid=xx) and with moderator or supermods usergroup (&grpid=y).
Even, a single user (&singleuser=uuu) can be specified.
PHP Code:
<?php
error_reporting(E_ALL);
require("./global.php");
cpheader();
echo "<p>Group <b>$grpid</b> crossed with Forum <b>$forumid</b></p>";
if (isset($forumid) and isset($grpid)) {
$forum2test=$forumid;
$usergroups=$DB_site->query("SELECT usergroupid,title FROM usergroup where usergroupid=$grpid");
echo "<p>";
while ($usergroup=$DB_site->fetch_array($usergroups)) {
$id=$usergroup[usergroupid];
$perms[$id]=getpermissions($forum2test,0,$id);
$k=$perms[$id];
if ($k[canview])
echo "<br>Forum <b>$forum2test</b> <b> can </b> be accessed by usergroup $usergroup[usergroupid] ($usergroup[title])";
else
echo "<br>Forum <b>$forum2test</b> <b>can't</b> be accessed by usergroup $usergroup[usergroupid] ($usergroup[title])";
}
echo "</p>";
$users=$DB_site->query("SELECT userid,username FROM user WHERE usergroupid=$grpid ORDER BY userid");
echo "<p>";
while ($user=$DB_site->fetch_array($users)) {
unset($permscache, $usergroupcache);
$id=$user[userid];
$permuser[$id]=getpermissions($forum2test,$id);
$k=$permuser[$id];
if ($k[canview])
echo "<br>Forum <b>$forum2test</b> <b> can </b> be accessed by user $user[userid] ($user[username])";
else
echo "<br>Forum <b>$forum2test</b> <b>can't</b> be accessed by user $user[userid] ($user[username])";
}
echo "</p>";
// copy this code right before the first select...
if (isset($singleuser)) {
if ($permsingleuser[canview])
echo "<br>Forum <b>$forum2test</b> <b> can </b> be accessed by user $user[userid]";
else
echo "<br>Forum <b>$forum2test</b> <b>can't</b> be accessed by user $user[userid]";
}
// ... and if run with an user of the usergroup specified,
// you'll get different values for same instructions.
}
echo "<br><br><p>Performance stats: <b>".number_format($query_count)."</b> queries done in <b>".number_format($querytime,7)."</b> seconds</p>";
cpfooter();
?>
You can notice if run with a single user, that:
- if the user belongs to the specified group, permissions are
cached (i.e. wrong results if such user has single access mask
set)
- if not, permissions returned are true (reflecting the actual user ones)
- if you copy the same section of $singleuser also before the first
getpermissions(), you'll obtain true values ANY CASE, much
different from the same code at the end of the script.
It means that permissions are cached per usergroup and per
forum. And the unsets aren't enough ....