The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
DB-dynamic NavBar - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.4 (https://userspice.com/forums/forumdisplay.php?fid=27)
+--- Thread: DB-dynamic NavBar (/showthread.php?tid=1301)



DB-dynamic NavBar - zyan - 01-10-2019

Hello,

I am trying to build a dynamic NavBar depending on the permission level of the logged in user.

My first approach was something like:


PHP Code:
$db DB::getInstance();
$permission $user->data()->permissions //(Source: https://userspice.com/documentation-user-class/)
if ($permission == "2") {      //  "2" means admin
 
 echo "<li><a href='overview.php'>Overview</a></li>";


But the problem is, that the list element doesn't even show up for the admin. When I echoed $permission it always showed "1" for all users I tried.
To me it looks like, that "$user->data()->permissions" outputs the permissions level of the user, that is necessary to access the current the page.
So when my page requires access level 1 and the admin has access levels 1 and 2,  "$user->data()->permissions" outputs 1.

Does anyone know a solution or am I just on the wrong path?

PS: I started using UserSpice about a week ago and want to thank developers very much for this great tool!


RE: DB-dynamic NavBar - mudmin - 01-10-2019

(01-10-2019, 02:37 PM)zyan Wrote: Hello,

I am trying to build a dynamic NavBar depending on the permission level of the logged in user.

My first approach was something like:


PHP Code:
$db DB::getInstance();
$permission $user->data()->permissions //(Source: https://userspice.com/documentation-user-class/)
if ($permission == "2") {      //  "2" means admin
 
 echo "<li><a href='overview.php'>Overview</a></li>";


But the problem is, that the list element doesn't even show up for the admin. When I echoed $permission it always showed "1" for all users I tried.
To me it looks like, that "$user->data()->permissions" outputs the permissions level of the user, that is necessary to access the current the page.
So when my page requires access level 1 and the admin has access levels 1 and 2,  "$user->data()->permissions" outputs 1.

Does anyone know a solution or am I just on the wrong path?

PS: I started using UserSpice about a week ago and want to thank developers very much for this great tool!

The term "permissions" in the db is actually an old thing that basically is whether the user is locked out or not.  

What you can do instead is use the hasPerm function which takes an array of permissions to be more flexible. 
PHP Code:
if(hasPerm([2,3,4],$user->data()->id)){
 echo 
"<li><a href='overview.php'>Overview</a></li>";
}
if(
hasPerm([2],$user->data()->id)){
 echo 
"<li><a href='admin.php'>Overview</a></li>";


Glad you're enjoying it!


RE: DB-dynamic NavBar - zyan - 01-10-2019

Thank you very much!
Works perfectly!


RE: DB-dynamic NavBar - mudmin - 01-10-2019

Awesome. Happy to help.