09-11-2017, 07:19 AM
Is there a way to check whether the logged in user is a admin?
The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Check if user is admin
|
09-11-2017, 07:19 AM
Is there a way to check whether the logged in user is a admin?
09-11-2017, 09:11 AM
You can use checkMenu or hasPerm.
if(checkMenu(2,$user->data()->id)) OR hasPerm($permissions, $id)
09-11-2017, 11:54 AM
Note that hasPerm is made to be an array so it can do multiple levels at once, so it's expecting an array.
When you go into the admin panel and click admin permissions and then click a permission, if you look at this screenshot http://puu.sh/xx701/7a52b51a58.png You'll see that each permission has an id on it. By default, Admin is 2. If you add others like staff and manager, they'll come in at 3 & 4. Then you have to pass the user id into either checkMenu or hasPerm. With that array, let's say you want permission levels 2 and 4 to be able to do something, that would be Code: if(hasPerm([2,4],$user->data()->id)){ Code: //do something Code: }
09-11-2017, 12:57 PM
Thanks a lot. I solved it with the checkMenu(a,b) methode.
|