User Group Permissions

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
byteme
Posts: 10
Joined: Fri Jun 30, 2006 7:14 pm

User Group Permissions

Post by byteme »

I am writing several block type areas for a portal using PHPBB3.
Everything is working, HOWEVER< I was hoping someone could point me in the right direction.

I am hoping to display content based upon USERGROUP.
If the user belongs in usergroup 1, then they get the "menu" for usergroup1
If they belong to usergroup 2 - then they get the menu for usergroup2
If they belong to both 1 AND 2, then they get both.

Sort of
IF Users' USERGROUP=1
Display some code
ENDIF

IF Users' USERGROUP=2
Display some code
ENDIF

Any suggestions or ideas?
Zircon17
Registered User
Posts: 6
Joined: Sun Aug 12, 2007 11:37 am

Re: User Group Permissions

Post by Zircon17 »

I can't see how that would be too hard, I mean if you go off the "IF 'user logged in" or "IF not bot" things, it shouldn't be too hard, BUT if you have tried that and I am completely wrong, let me know, for I am only JUST starting to learn php
byteme
Posts: 10
Joined: Fri Jun 30, 2006 7:14 pm

Re: User Group Permissions

Post by byteme »

I havent been able to find the ability to see the variable that indicates that the user belongs to XYZ group. :cry:

I and pooring over code looking for group membership to be called out, OR maybe to find someone else's code that already does a portion of it.

This is NOT difficult, but trying to "ripoff and deploy" (R&D) someone elses code is proving much more time consuming that I though before.
Zircon17
Registered User
Posts: 6
Joined: Sun Aug 12, 2007 11:37 am

Re: User Group Permissions

Post by Zircon17 »

hm, yes I know what you mean, I'm trying to template the time with php(to learn how) and I went to phpbb's code, and all I could find that helped was to LINK to a template, but when it came to a certain part, it always linked to ANOTHER php code further in, getting it done is easy, but getting the code to go off of, it's a nightmare!!!
byteme
Posts: 10
Joined: Fri Jun 30, 2006 7:14 pm

Re: User Group Permissions

Post by byteme »


THAT is freakin awesome. AND I know now where I can go for more data. However, I am still at a quandry. I am not positive how to use it - but I will keep l;ooking - this is a GREAT starting point. Now I just have to move from phpnoob - to noob hacker :-)
Zircon17
Registered User
Posts: 6
Joined: Sun Aug 12, 2007 11:37 am

Re: User Group Permissions

Post by Zircon17 »

yeah sweet!!! thanks man, I also needed that, not the permissions thing, the whole codes thing
byteme
Posts: 10
Joined: Fri Jun 30, 2006 7:14 pm

Re: User Group Permissions

Post by byteme »

Zircon17 wrote:yeah sweet!!! thanks man, I also needed that, not the permissions thing, the whole codes thing
I am still trying to finger this thing out - I see the group_membership and that it can form an array, but I dont know what would be the easiest way to check if the array contains a given number.......
Zircon17
Registered User
Posts: 6
Joined: Sun Aug 12, 2007 11:37 am

Re: User Group Permissions

Post by Zircon17 »

byteme wrote:
Zircon17 wrote:yeah sweet!!! thanks man, I also needed that, not the permissions thing, the whole codes thing
I am still trying to finger this thing out - I see the group_membership and that it can form an array, but I dont know what would be the easiest way to check if the array contains a given number.......

um dude I'm still trying to work out how to template a php time function with an external template, don't quote one of my posts and say that, besides I don't know what an array is
KFCSpike
Registered User
Posts: 17
Joined: Mon Oct 02, 2006 5:44 pm
Location: Scotland
Contact:

Re: User Group Permissions

Post by KFCSpike »

byteme wrote:
Zircon17 wrote:yeah sweet!!! thanks man, I also needed that, not the permissions thing, the whole codes thing
I am still trying to finger this thing out - I see the group_membership and that it can form an array, but I dont know what would be the easiest way to check if the array contains a given number.......
byteme - I think I am trying similar to what you are trying to achieve and I have managed to get a snippet of code working that checks if the logged in user is a member of a specific group.
(Thanks to Acyd Burn pointing out the relevant function or I would never have found it!)

I still consider myself a noob when it comes to writing code to interact with phpBB3 so don't assume this is the best way to do it - its only an example that worked for me and I would hope any of the more experienced guys will point out any flaws.
I only require to check a single user against a single group but should be expandable by adding to the arrays.

Code: Select all

$my_user_id_ary = array($user->data['user_id']); //Assumes user object already set up
$my_group_id_ary = array(7); //Only checking a single group
$my_return_bool = true; //Is this correct usage for a true/false answer depending whether user(s) are in group(s)??

//OK - Now check if User is in Group
if (group_memberships($my_group_id_ary, $my_user_id_ary, $my_return_bool))
{
	//Success
	$result = 'You are a member of group: '.$my_group_id_ary[0];
}
else
{
	//Failure
	$result = 'You are NOT a member of group: '.$my_group_id_ary[0];
}
Post Reply