Board Logo

Hiding nodes based on permissions (pro verson, php)
bentmyers - 9/30/2007 at 11:29 PM

I'm trying to use tree menu pro to generate a dynamic menu from my database. The user access variables are in a comma delineated set (ex: 1,4,17,24) and the page permissions are in a similar set (ex: 2,4,15,56,57). In this example, the 4 matches in both, so the user would be able to see the page.

I edited items.php to query the permissions field in the db table and then compare the user's access session variable with the field from the db, but it's not generating the correct menu.

Code:

$sql = "SELECT * FROM $tn WHERE $pidfn=$id";
$result = mysql_query($sql);

if (mysql_num_rows($result) == 0) return;
while ($row = mysql_fetch_assoc($result)) {

$clink = $row[$lfn];
$cid = $row[$idfn];

// ****
// **** START CUSTOMIZATION **** //
// ****
// **** THIS ARRAY WILL CONTAIN THE ACCESS PRIVS OF THE PAGE
// **** IF IT'S PRIVS MATCH THE PRIVS IN THE sess_access VARIABLE, THE USER CAN SEE THE PAGE
$accessVar = FALSE;
$pageAccessArray = $row[page_permission];
$pageAccessArray = explode(",",$pageAccessArray);
$userAccessArray = explode(",",$user_permissions); //**** $user_permissions IS A SESSION VARIABLE ASSIGNED WHEN THE USER LOGS IN **** //

if(in_array("0",$pageAccessArray))
$accessVar = TRUE;
else
{
for($i=0;$i<count($userAccessArray);$i++)
{
$thisItem = $userAccessArray[$i];
if(in_array($thisItem,$pageAccessArray))
$accessVar = TRUE;
}
}

// ****
// **** END CUSTOMIZATION
// ****


if($accessVar == TRUE)
{
if ($id == 0) echo 'var '.$vn.' = [';

if(!$vn) echo ',';
$vn = 0;
echo " ['$row[$cfn]', "$clink", ";
if($id == 0) echo "{'st':1}";
else echo "0";
build_hierarchy($cid, $vn, $tn, $idfn, $pidfn, $cfn, $lfn);
echo ']';
}
else
build_hierarchy($cid, $vn, $tn, $idfn, $pidfn, $cfn, $lfn);
}
mysql_free_result($result);
if($id == 0) echo "];";



The menu will give me a few seemingly random nodes, but not the correct structure.
Anyone have any ideas on how to correct this?
Thanks!


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/