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
Problems with "hasPerm" function - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Problems with "hasPerm" function (/showthread.php?tid=706)



Problems with "hasPerm" function - bladerunner - 08-31-2017

Hi!

I'm having some problems with the hasPerm function. In a part of a page (dashboard.php), I want to show a menu only to users with permission id=2. So, I write:

<pre>
Code:
if(hasPerm([2],$user->data()->id)){
   // Some stuff
}
</pre>



Everything works fine if user "admin" is logged in ("admin" has permission of "Administrator" (id=2) and "User" (id=1)). But when user "dummy" (who has permision of "User" (id=1) only) I get this error:

Notice: Undefined variable: master_account in C:\wamp\www\true\admin\production\users\helpers\us_helpers.php on line 788
Call Stack
# Time Memory Function Location
1 0.0008 259656 {main}( ) ..\dashboard.php:0
2 0.0546 1098544 hasPerm( ) ..\dashboard.php:50

( ! ) Warning: in_array() expects parameter 2 to be array, null given in C:\wamp\www\true\admin\production\users\helpers\us_helpers.php on line 788
Call Stack
# Time Memory Function Location
1 0.0008 259656 {main}( ) ..\dashboard.php:0
2 0.0546 1098544 hasPerm( ) ..\dashboard.php:50
3 0.0821 1100296 in_array ( ) ..\us_helpers.php:788

Can anyone give some help, please? I can't understand what's happening here. Thank you!



Problems with "hasPerm" function - Brandin - 08-31-2017

THIS IS THE ERROR I HAD BEFORE that I couldn't figure out lol

@Mudmin?


Problems with "hasPerm" function - bladerunner - 09-01-2017

The modification of the file "us_helpers.php", adding the declaration of the variable "master_account" as global inside the function "hasPerm", has worked for me. This way:

Code:
function hasPerm($permissions, $id) {
Code:
$db = DB::getInstance();
Code:
global $user;
Code:
global $master_account;   //THIS IS THE NEW LINE
Code:
//Grant access if master user
Code:
$access = 0;

Can anyone verify if this is a correct way to fix this problem, please?


Problems with "hasPerm" function - mudmin - 09-01-2017

I think that might be right. I never even noticed that hasPerm was the common denominator in the seemingly "random" times that has come up. THANK YOU! I will be trying it.


Problems with "hasPerm" function - Brandin - 09-01-2017

This is why I don't use hasPerm Wink So that's why I could never tell you why it was broke lol


Problems with "hasPerm" function - mudmin - 09-01-2017

haha. Well as I had more permission levels, writing 10 checkmenu statements got a little clunky. This update should fix it. I'll push it out to 4.2 also.


Problems with "hasPerm" function - Brandin - 09-01-2017

It definitely does, so once this is fixed - I will be very happy to use this! Smile


Problems with "hasPerm" function - bladerunner - 09-04-2017

I'm glad to hear that this solution is working properly.
Best regards.