The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB-dynamic NavBar
#1
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!
  Reply
#2
(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!
  Reply
#3
Thank you very much!
Works perfectly!
  Reply
#4
Awesome. Happy to help.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)