News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

membergroup set up and menu access

Started by ~FS~grizz, February 22, 2013, 09:35:48 PM

Previous topic - Next topic

~FS~grizz

hi
I did a basic search, maybe I used the wrong terms...
I have SMF 2.0.4
I need special access for two membergroups to log in

I have created:
member
employee

I need:
each group to have it's own access level and show specific menu items and menu sub-items
the member group can have an employee access level, which would mean the employee could NOT see certain menu options if not listed in the member group as well

I have done:
Created member and employee groups already, does it matter if they are created with inherent rights from "regular members" group?
Created new menu item "About Us" with sub-menu item "example" that is visible to all, how can I make a second sub-menu item of "example"  that is visible only to one or both of my new member groups?


MC73

Create separate member groups if you want them to have different permissions and different board access

The next step would be for you to edit permissions

Administration Center | Permissions | General Permissions

http://wiki.simplemachines.org/smf/Permissions

http://wiki.simplemachines.org/smf/Membergroups
Over 1100 Online Flash Games 

Sir Osis of Liver


The membergroups can inherit permissions from Regular Members, and you can separately set Visible Boards for each group.

To make a submenu visible to specific groups, find the menu array in /Sources/Subs.php (look for 'All the buttons....'), and specify the allowed group numbers for the menu item, like this -



'show' => $user_info['groups']['0'] == 1,



When in Emor, do as the Snamors.
                              - D. Lister

~FS~grizz

#3
Thank you both,

I have separate groups and separate permissions now,
I have edited the menu,
I have a menu item now that shows only to one member group....but it seems that not the admin can see it as well.

how do I make it so the admin also sees the menu item?

AND

I will show you the code, can anyone help with why I cannot add a 2nd level menu item?
perhaps I have something wrong, I just read the tips&tricks tutorial and tried my best.

'aboutus' => array(
      'title' => 'About Us',
      'href' => 'http://demo.blank.com/index.php?page=page1',
      'show' => true,
          'sub_buttons' => array(
                        'treaty' => array(
        'title' => 'Treaty Information',
'href' => 'http://demo.danaxdaxw.com/index.php?page=page4805',
'show' => $user_info['groups']['0'] == 9,
'sub_button2' => array(
              'title' => 'Member Treaty Info',
       'href' => 'http://demo.danaxdaxw.com/index.php?page=page3634',
       'show' => $user_info['groups']['0'] == 9,
  ),
          'is_last' => true,
                          ),
           ),

Sir Osis of Liver




'aboutus' => array(
'title' => 'About Us',
'href' => 'http://demo.blank.com/index.php?page=page1',
'show' => true,
'sub_buttons' => array(
'treaty' => array(
'title' => 'Treaty Infomation',
'href' => 'http://demo.danaxdaxw.com/index.php?page=page4805',
'show' => $user_info['groups']['0'] == 1 || $user_info['groups']['0'] == 9,
'sub_buttons' => array(
'member_treaty' => array(
'title' => 'Member Treaty Info',
'href' => 'http://demo.danaxdaxw.com/index.php?page=page3634',
'show' => $user_info['groups']['0'] == 1 || $user_info['groups']['0'] == 9,
),
),
),
),
),



Careful with the brackets.

When in Emor, do as the Snamors.
                              - D. Lister

~FS~grizz

Thanks!

looks like its all good now,
one question on this line of code:
'show' => $user_info['groups']['0'] == 1 || $user_info['groups']['0'] == 9,

I also found that this works, is there any potential problem?
'show' => $user_info['groups']['0'] == 1,9,


Sir Osis of Liver


That's fine - actually the proper way to do it, but couldn't remember the syntax.  Either will work. 

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

Wait, what? How is that the proper syntax? In fact, that syntax won't work properly (group 9 in the latter is NOT being checked at all) even though it won't cause any syntax issues.

The correct syntax:
'show' => in_array(1, $user_info['groups']) || in_array(9, $user_info['groups']),

If you're being *really* clever, you can get into using array_intersect, but largely that's unnecessary.


Just in case anyone else comes along.
$user_info['groups'][0] is *usually but NOT ALWAYS* the primary group. $user_info['groups'][1] is *usually bot NOT ALWAYS* the post count group. Check the whole array rather than relying on specific quirks.

Also note that lack of use of ['0'] when [0] will suffice and is marginally faster.
Holder of controversial views, all of which my own.


Sir Osis of Liver



Thanks, Arantor, that's why I didn't post it.  Had seen something like that in another thread and thought it was correct.  I've done it the way I originally posted, and it's always worked.  Saving your code for future reference.

When in Emor, do as the Snamors.
                              - D. Lister

~FS~grizz

Thanks Krash and Arantor.
I will update to this code you provided Arantor
Looks like I am good for now, until I find a new challenge in setting this up!
marking this as solved.

Advertisement: