Open jberanek opened 2 years ago
Only if you modify the MRBS code. If you are running MRBS 1.9.4 you need to modify the function is_book_admin() in mrbs_auth.inc and replace line 436 which is
return (isset($mrbs_user) && ($mrbs_user->level >= 2));
by something like
if (!isset($mrbs_user))
{
return false;
}
if ($mrbs_user->level >= 2)
{
return true;
}
$area = get_area($rooms)
switch ($area)
{
case 2:
if (in_arrayi($mrbs_user->username), array('tom', 'dick', 'harry'))
{
return true;
}
break;
case 4:
if (in_arrayi($mrbs_user->username), array('alice', 'bob'))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
Original comment by: campbell-m
I tried it but not working sir. Pls can you put the whole function after fixing it? Thanks in advance
Original comment by: *anonymous
Im using version no. 2
Original comment by: *anonymous
function is_book_admin($rooms=null, $all=true)
{
if (is_array($rooms) && (count($rooms) > 0))
{
if ($all)
{
// We want the user to be a booking admin for all the rooms,
// so if for any one room they are not, then return false.
foreach ($rooms as $room)
{
if (!is_book_admin($room))
{
return false;
}
}
return true;
}
else
{
// We want the user to be a booking admin for at least one room,
// so if there are no rooms for which they are, then return false.
foreach ($rooms as $room)
{
if (is_book_admin($room))
{
return true;
}
}
return false;
}
}
if (is_null($rooms) && !$all)
{
// Not yet supported. Could support it but need to decide what $rooms=null means.
// Does it mean all rooms in the system or just all rooms in the current area?
throw new \Exception('$rooms===null and $all===false not yet supported.');
}
$mrbs_user = session()->getCurrentUser();
if (!isset($mrbs_user))
{
return false;
}
if ($mrbs_user->level >= 2)
{
return true;
}
$area = get_area($rooms)
switch ($area)
{
case 2:
if (in_arrayi($mrbs_user->username), array('tom', 'dick', 'harry'))
{
return true;
}
break;
case 4:
if (in_arrayi($mrbs_user->username), array('alice', 'bob'))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
}
Original comment by: campbell-m
still there is an error
Original comment by: *anonymous
Attachments: https://sourceforge.net/p/mrbs/support-requests/_discuss/thread/0146fe3d6b/713a/attachment/error.png
What is the error? You need to change the area ids and usernames to suit your requirements.
Original comment by: campbell-m
where should I change the area Id. For example my area id is "4". can you change it in the script please
Original comment by: *anonymous
No, you will need to change it yourself. The code above is just an example that makes usernames 'tom', 'dick' and 'harry' admins for area 2, and 'alice' and 'bob' admins for area 4.
Original comment by: campbell-m
I did exactly like this as you mentioned . For area 1 and area 3 but code error
$area = get_area($rooms)
switch ($area)
{
case 1:
if (in_arrayi($mrbs_user->username), array('ranjith', 'majed', 'chunky'))
{
return true;
}
break;
case 3:
if (in_arrayi($mrbs_user->username), array('ranjith', 'maryam'))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
}
Original comment by: *anonymous
And what is the error?
Original comment by: campbell-m
in my Dreamweaver see the picture , Once I save it page not working
Original comment by: *anonymous
Attachments: https://sourceforge.net/p/mrbs/support-requests/_discuss/thread/0146fe3d6b/cfed/attachment/error2.png
Sorry, there's a semicolon missing:
$area = get_area($rooms);
Original comment by: campbell-m
still line 444 and 450 error showing red color and page not showing sir.
Original comment by: *anonymous
Sorry, it should be
if (in_arrayi($mrbs_user->username, array('ranjith', 'majed', 'chunky')))
and similarly for the other line.
Original comment by: campbell-m
ts working now thanks a lot.
Original comment by: *anonymous
But still other room admin can admin all the areas. not restricted to one area
Original comment by: *anonymous
What do you mean by "other room admin"?
Original comment by: campbell-m
I need separate admin for separate areas. once I done this for example area 1 admin can admin area 3 also. I want area 1 admin only for that area not for area 3. Now its like having 2 admin.
Original comment by: *anonymous
Which user are you talking about? If it's ranjith then, yes, they will be admins for both areas as they are in both arrays in the code above.
Original comment by: campbell-m
in the example mariam should not be able to admin area 1 but ranjith should be admin for area 1 and area 3
Original comment by: *anonymous
Can you post your version of the code here please?
Original comment by: campbell-m
function is_book_admin($rooms=null, $all=true)
{
if (is_array($rooms) && (count($rooms) > 0))
{
if ($all)
{
// We want the user to be a booking admin for all the rooms,
// so if for any one room they are not, then return false.
foreach ($rooms as $room)
{
if (!is_book_admin($room))
{
return false;
}
}
return true;
}
else
{
// We want the user to be a booking admin for at least one room,
// so if there are no rooms for which they are, then return false.
foreach ($rooms as $room)
{
if (is_book_admin($room))
{
return true;
}
}
return false;
}
}
if (is_null($rooms) && !$all)
{
// Not yet supported. Could support it but need to decide what $rooms=null means.
// Does it mean all rooms in the system or just all rooms in the current area?
throw new \Exception('$rooms===null and $all===false not yet supported.');
}
$mrbs_user = session()->getCurrentUser();
if (!isset($mrbs_user))
{
return false;
}
if ($mrbs_user->level >= 2)
{
return true;
}
$area = get_area($rooms);
switch ($area)
{
case 1:
if (in_arrayi($mrbs_user->username, array('ranjith')))
{
return true;
}
break;
case 3:
if (in_arrayi($mrbs_user->username, array('ranjith', 'maryam')))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
}
Original comment by: *anonymous
Is maryam also a normal admin?
Original comment by: campbell-m
No . But I tried maryam as an admin and normal user. still cannot get it work
Original comment by: *anonymous
And are you definitely sure that the room that maryam is able to be an admin for is in area 1?
Original comment by: campbell-m
yes sir. I checked again and again still maryam can admin area 1. should I make maryam normal user or admin user?
Original comment by: *anonymous
Yes sir. I checked again and again changing the user to admin and normal user. When maryam is admin she can admin both and when normal user cannot admin any.
Original comment by: *anonymous
You should make maryam an ordinary user if you don't want her to have admin rights in all areas. If she is an ordinary user she should have admin rights for rooms in area 3.
Original comment by: campbell-m
no sir I tried that way once I make her ordinary user she cannot admin any area.
Original comment by: *anonymous
You'll need to start debugging the code. I've inserted some debug output below which should appear in the browser. Let me know what appears when maryam tries to delete somebody else's booking in area 1.
function is_book_admin($rooms=null, $all=true)
{
if (is_array($rooms) && (count($rooms) > 0))
{
if ($all)
{
// We want the user to be a booking admin for all the rooms,
// so if for any one room they are not, then return false.
foreach ($rooms as $room)
{
if (!is_book_admin($room))
{
return false;
}
}
return true;
}
else
{
// We want the user to be a booking admin for at least one room,
// so if there are no rooms for which they are, then return false.
foreach ($rooms as $room)
{
if (is_book_admin($room))
{
return true;
}
}
return false;
}
}
if (is_null($rooms) && !$all)
{
// Not yet supported. Could support it but need to decide what $rooms=null means.
// Does it mean all rooms in the system or just all rooms in the current area?
throw new \Exception('$rooms===null and $all===false not yet supported.');
}
$mrbs_user = session()->getCurrentUser();
if (!isset($mrbs_user))
{
return false;
}
if ($mrbs_user->level >= 2)
{
return true;
}
$area = get_area($rooms);
var_dump($area); //DEBUG
var_dump($mrbs_user->username); // DEBUG
switch ($area)
{
case 1:
if (in_arrayi($mrbs_user->username, array('ranjith')))
{
return true;
}
break;
case 3:
if (in_arrayi($mrbs_user->username, array('ranjith', 'maryam')))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
}
Original comment by: campbell-m
HI Campbell
Im just trying to get this working at our site so only certain users can administer certain areas. in the code you have posted how do you identify which room you want to be selected i can see it says case 1 and case 3 but how do they correlate the the actual rooms?
Any help would be appreciated.
Regards Scott
Original comment by: scottlangshaw
The 1 and 3 are examples and are area ids.
Original comment by: campbell-m
thanks for the quick response. Where would we find the area ids on the system?
Original comment by: scottlangshaw
Either in the area table in the database, or else just by hovering over a link to a room and looking at the area id (index.php?area=7&room=2 etc).
Original comment by: campbell-m
amazing thank you ill give it a test tomorrow and if i get stuck ill stick another message on here.
Thanks
Original comment by: scottlangshaw
Hi Campbell
I may be doing something wrong but ive found the room numbers and entered it into the code below but im not sure if its correct as i still cant edit the bookings in that room?
function is_book_admin($rooms=null, $all=true)
{
if (is_array($rooms) && (count($rooms) > 0))
{
if ($all)
{
// We want the user to be a booking admin for all the rooms,
// so if for any one room they are not, then return false.
foreach ($rooms as $room)
{
if (!is_book_admin($room))
{
return false;
}
}
return true;
}
else
{
// We want the user to be a booking admin for at least one room,
// so if there are no rooms for which they are, then return false.
foreach ($rooms as $room)
{
if (is_book_admin($room))
{
return true;
}
}
return false;
}
}
if (is_null($rooms) && !$all)
{
// Not yet supported. Could support it but need to decide what $rooms=null means.
// Does it mean all rooms in the system or just all rooms in the current area?
throw new \Exception('$rooms===null and $all===false not yet supported.');
}
$mrbs_user = session()->getCurrentUser();
if (!isset($mrbs_user))
{
return false;
}
if ($mrbs_user->level >= 2)
{
return true;
}
$area = get_area($rooms);
switch ($area)
{
case 1:
if (in_arrayi($mrbs_user->username, array('ranjith')))
{
return true;
}
case 39:
if (in_arrayi($mrbs_user->username, array('teststaff')))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
}
Original comment by: scottlangshaw
Ive sorted it :) i put the room id and not the area id.
One question are you able to allow users to edit certain rooms within an area or does this just work with areas?
Thanks Scott
Original comment by: scottlangshaw
Yes, you can do just rooms, but the code would be slightly different. Do you want certain rooms, or areas or both?
Original comment by: campbell-m
If we can do both within the code that would be amazing.
Original comment by: scottlangshaw
Replace
switch ($area)
{
case 1:
if (in_arrayi($mrbs_user->username, array('ranjith')))
{
return true;
}
case 39:
if (in_arrayi($mrbs_user->username, array('teststaff')))
{
return true;
}
break;
// etc for more areas
default:
return false;
break;
}
by
// First check areas
switch ($area)
{
case 1:
if (in_arrayi($mrbs_user->username, array('ranjith')))
{
return true;
}
case 39:
if (in_arrayi($mrbs_user->username, array('teststaff')))
{
return true;
}
break;
// etc for more areas
default:
break;
}
// Now check rooms
switch ($rooms)
{
case 11: // replace 11 etc by the relevant room id
if (in_arrayi($mrbs_user->username, array('tom')))
{
return true;
}
break;
case 32:
if (in_arrayi($mrbs_user->username, array('dick', 'harry')))
{
return true;
}
break;
// etc for more rooms
default:
return false;
break;
}
Original comment by: campbell-m
Amazing Campbell, Thank you so much it works an absolute treat :).
Original comment by: *anonymous
Hello! How can i do this in version 1.10.0 ?
Thanks!
Original comment by: *anonymous
I think it should be the same code that's needed in MRBS 1.10.0.
Original comment by: campbell-m
I have 3 areas in the system can I have different admins per area.
Reported by: *anonymous
Original Ticket: mrbs/support-requests/2461