News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Adding Menu Button for certain Member Groups

Started by jazz, May 11, 2005, 10:38:13 AM

Previous topic - Next topic

jazz

I'm trying to add a menu item for only certain groups to see.  In index.template.php, I've added

// Member List
if (count(array_intersect(range(22, 58), $user_info['groups'])) != 0){
echo '
<td><a href="http://mydomain.com/fcp/fcp.php">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/memberlist.gif" alt="' . $txt[802] . '" border="0" />' : $txt[802]), '</a></td>';
}


It isn't working.  Can someone tell me what I'm doing wrong?

jazz

Quote from: jazz on May 11, 2005, 10:38:13 AM
I'm trying to add a menu item for only certain groups to see.  In index.template.php, I've added

// Member List
if (count(array_intersect(range(22, 58), $user_info['groups'])) != 0){
echo '
<td><a href="http://mydomain.com/fcp/fcp.php">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/memberlist.gif" alt="' . $txt[802] . '" border="0" />' : $txt[802]), '</a></td>';
}


It isn't working.  Can someone tell me what I'm doing wrong?

Is there anyone who can help me with this?

jazz

This is the code that I would use if I were going to use include in index.template.

      if (count(array_intersect(range(22, 58), $user_info['groups'])) != 0){
echo ' content';
}

I would have thought that this would be the same for adding a button for these groups, but it doesn't work.  I don't even know where to turn from here.  Where am I wrong?
      

bloc

I posted an answer to you up on Bloczone.. but I can post here too, in case you did not see it. i would use this code for it(not the most advanced, but it should be clear)

// Member List
                $show=false;
                foreach($user_info['groups'] as $mgrp => $val){
                      if(in_array($val,array('22','23','24','25','26')))
                         $show=true;
                }
                if($show==true){
                  echo '
                                content';
                }


jazz

Well I'm getting somewhere, but it's still not there.  Here is the message that I receive.

Warning: Invalid argument supplied for foreach() in /home/carmmcom/public_html/testforum/Sources/Load.php(1040) : eval()'d code on line 451

jazz

For some reason I'm feeling ignored. :(  Anyway, this is what I've got.  It makes the button appear, but it appears for everyone.

// Member List
if (count(array(range(22, 28), $user_info['groups'])) != 0){
echo '
<td><a href="http://mydomain.com/fcp/fcp.php">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/memberlist.gif" alt="' . $txt[802] . '" border="0" />' : $txt[802]), '</a></td>';
}


What do I need to do to make it only viewable for the groups specified?

jazz

#6
ANYONE???  This is the latest attempt.

// Member List
                $show=false;
                foreach($context['user']['groups'] as $mgrp => $val){
                      if(in_array($val,array('9','10','11','12','13')))
                         $show=true;
                }
                if($show==true){
                  echo '<td><a href="http://mydomain.com/fcp/fcp.php">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/memberlist.gif" alt="' . $txt[802] . '" border="0" />' : $txt[802]), '</a></td>';
                }


Gives this error.... 

Warning: Invalid argument supplied for foreach() in /home/carmmcom/public_html/testforum/Sources/Load.php(1040) : eval()'d code on line 864

bloc

I seem to forgot that it only works for members.. ::) How about this then?

// Member List
                $show=false;
                if($context['user']['is_logged']){
                  foreach($user_info['groups'] as $mgrp => $val){
                      if(in_array($val,array('22','23','24','25','26')))
                         $show=true;
                  }
                }

                if($show==true){
                  echo '
                                content';
                }

jazz

This is starting to drive me insane and make me stay up hours past my bed time.  Here is the error with that.

Notice: Undefined variable: user_info in /home/carmmcom/public_html/testforum/Sources/Load.php(1040) : eval()'d code on line 863

Warning: in_array(): Wrong datatype for second argument in /home/carmmcom/public_html/testforum/Sources/Load.php(1040) : eval()'d code on line 863

ディン1031

#9
Hmmm i have done this with $user_settings['ID_POST_GROUP'].

but you must load the $user_settings with global $user_settings at the top of the function.

I put this code in the index.template.php in the "function template_menu"


if (!$context['user']['is_guest'] && $user_settings['ID_POST_GROUP'] != 4)
{
echo '
<a href="http://secret">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/bild.gif" alt="description" border="0" />' : 'Text'), '</a>', $context['menu_separator'];
}


This code show the button only if the user is not a guest and the group the is not 4.
You can also use 'ID_GROUP' for special groups like 2 for Global Moderator, or for your special thing '22','23','24','25','26'. ;)

I hope that help you ;).

Bye
DIN1031

(Than you need no changes in the load.php i think...)
Support only via MOD Thread! NO PM Support!
My Forum: ayu][kult Forum
My Mods: My Small Mod Collection
My Parser: DIN1031's ModParser
Current Info: More away the next days, because i've to much work to do :x

jazz

I'll try this later on today after I get some sleep.  I appreciate your help.  Should I put this code in the function template_menu in addition to the section where the menu buttons are in the code?

bloc

Quote from: jazz on May 13, 2005, 05:11:41 AM
This is starting to drive me insane and make me stay up hours past my bed time.  Here is the error with that.

Notice: Undefined variable: user_info in /home/carmmcom/public_html/testforum/Sources/Load.php(1040) : eval()'d code on line 863

Warning: in_array(): Wrong datatype for second argument in /home/carmmcom/public_html/testforum/Sources/Load.php(1040) : eval()'d code on line 863


Of course...this line in template_menu():
global $context, $settings, $options, $scripturl, $txt; 
needs the variable we are checking, like this:
global $context, $settings, $options, $scripturl, $txt, $user_info; 

jazz

Quote from: Bloc on May 13, 2005, 06:44:26 AM
Of course...this line in template_menu():
global $context, $settings, $options, $scripturl, $txt; 
needs the variable we are checking, like this:
global $context, $settings, $options, $scripturl, $txt, $user_info; 

I appreciate everyone's help.  The code you had me use worked.  I was just missing the $user_info in the template_menu()

Advertisement: