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
Problems with "hasPerm" function
#1
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!
  Reply
#2
THIS IS THE ERROR I HAD BEFORE that I couldn't figure out lol

@Mudmin?
  Reply
#3
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?
  Reply
#4
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.
  Reply
#5
This is why I don't use hasPerm Wink So that's why I could never tell you why it was broke lol
  Reply
#6
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.
  Reply
#7
It definitely does, so once this is fixed - I will be very happy to use this! Smile
  Reply
#8
I'm glad to hear that this solution is working properly.
Best regards.
  Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)