News:

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

Main Menu

Add menu button with permissions

Started by FragaCampos, November 24, 2009, 03:43:57 PM

Previous topic - Next topic

FragaCampos

Hello there.
Sorry if this has already been answered, but i searched and didn't find what i'm looking for.

I would like to add a button to the forum's menu, but only to a certain group created by me. I don't know how to set the permissions of a button besides admin, guest and member.

Can anyone give me a hand?
Thanks in advance.

Arantor

What theme, what group id, is it a post count group, or will be it primary and/or secondary groups of users?
Holder of controversial views, all of which my own.


FragaCampos

Thanks for answering.
Here's the code of my menu:

   // setup menu
   echo '
      <div id="wrap">
         <div id="menu">';
           echo '<a id="home" ',$current_action=='home' ? 'class="menu_item_sel" ' : 'class="menu_item"' ,' href="'.$scripturl.'">'.$txt[103].'</a>';
      echo ' <a id="forum" ',$current_action=='forum' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=forum">'.$txt['tp-forum'].'</a>';
   if ($context['allow_search'])
      echo ' <a ',$current_action=='search' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=search">'.$txt[182].'</a>';
   if ($context['allow_calendar'])
      echo ' <a ',$current_action=='calendar' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=calendar">'.$txt['calendar24'].'</a>';
   if ($context['allow_admin'])
      echo ' <a ',$current_action=='admin' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=admin">'.$txt[2].'</a>';
   if ($context['allow_edit_profile'])
      echo ' <a ',$context['sitespot']=='' ? 'class="active_now" ' : '' ,'href="'.$scripturl.'?action=profile">'.$txt[79].'</a>';
   if ($context['user']['is_logged'])
      echo ' <a ',$current_action=='mlist' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=mlist">'.$txt[19].'</a>';
      echo ($current_action == 'tags' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
            <td valign="top" class="maintab_' , $current_action == 'tags' ? 'active_back' : 'back' , '">
               <a href="', $scripturl, '?action=tags">' , $txt['smftags_menu']  , '</a>
            </td>' , $current_action == 'tags' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';   
   echo ' <a ',$current_action=='help' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=help">'.$txt[119].'</a>';
   if ($context['user']['is_guest'])
      echo ' <a ',$current_action=='login' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=login">'.$txt[34].'</a>';
   if ($context['user']['is_guest'])
      echo ' <a ',$current_action=='register' ? 'class="menu_item_sel" ' : 'class="menu_item" ' ,'href="'.$scripturl.'?action=register">'.$txt[97].'</a>';
   if ($context['user']['is_logged'])
      echo ' <a class="menu_item" href="'.$scripturl.'?action=logout;sesc='.$context['session_id']. '">'.$txt[108].'</a>';

echo ' </div>';


I'm using SMF 1.1.10. The group id is 13 and it's a normal group (not a post count group).
Btw... the page to where i want to go from there is index.php?action=form

Arantor

Where do you want it in relation to the other buttons and will that group be a primary group (i.e. displayed visibly in the forum) or secondary (not visible publicly) group or potentially either?
Holder of controversial views, all of which my own.


FragaCampos

The button can be inserted after the tags button and yes, the group is displayed in the forum (i didn't even know you could hide a group  ;D)

Arantor

Regarding the groups, you can actually have multiple groups, just only the primary is visible. Here for example, my primary group is Customizer, but I have a couple of other groups, such as Community Support Helper which isn't.

Before the last line there, the echo ' </div>';

Add:
   global $user_info; // in case it isn't already
   if (in_array(13, $user_info['groups']))
      echo ' <a class="menu_item" href="'.$scripturl.'?action=form">Button</a>';


Change the word Button to whatever writing you want (being careful to put \ in if you use an ' in there, e.g. My Site\'s Form
Holder of controversial views, all of which my own.


akeid

i used this

// Show the default [forum] button.

echo ($current_action=='forum' || $context['browser']['is_ie4']) ? '' : '' , '

<li class="' , $current_action == 'forum' ? 'current' : '' , '"><a href="http://eidscape.co.cc/index.php?action=forum">Forum</a></li>';

Arantor

akeid: That will work fine for your theme but FragaCompos isn't using that theme, and in any case wants to make it visible only to one group.
Holder of controversial views, all of which my own.


FragaCampos

Thank you very much Arantor for your help! It works marvellously :)

Hope it can help others.
Compliments.

FragaCampos

By the way... no wanting to abuse you, how can i make available to the group and to admins?

Arantor

No worries at all; it's always good to ask questions :)

   global $user_info; // in case it isn't already
   if ($context['user']['is_admin'] || in_array(13, $user_info['groups']))
      echo ' <a class="menu_item" href="'.$scripturl.'?action=form">Button</a>';
Holder of controversial views, all of which my own.


FragaCampos


Advertisement: