Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: jazz on May 11, 2005, 10:38:13 AM

Title: Adding Menu Button for certain Member Groups
Post by: 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?
Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 11, 2005, 08:09:30 PM
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?
Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 12, 2005, 02:47:07 AM
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?
      
Title: Re: Adding Menu Button for certain Member Groups
Post by: bloc on May 12, 2005, 08:06:35 AM
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';
                }

Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 12, 2005, 02:23:53 PM
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
Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 13, 2005, 01:09:47 AM
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?
Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 13, 2005, 02:28:12 AM
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
Title: Re: Adding Menu Button for certain Member Groups
Post by: bloc on May 13, 2005, 04:19:27 AM
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';
                }
Title: Re: Adding Menu Button for certain Member Groups
Post by: 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
Title: Re: Adding Menu Button for certain Member Groups
Post by: ディン1031 on May 13, 2005, 05:15:31 AM
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...)
Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 13, 2005, 06:22:45 AM
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?
Title: Re: Adding Menu Button for certain Member Groups
Post by: bloc on May 13, 2005, 06:44:26 AM
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; 
Title: Re: Adding Menu Button for certain Member Groups
Post by: jazz on May 13, 2005, 02:09:11 PM
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()