Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Nils Johan on December 14, 2004, 08:37:15 AM

Title: Including custom html depending on SMF member group?
Post by: Nils Johan on December 14, 2004, 08:37:15 AM
I need to insert some html (graphics and links) on the profile page and possibly also on the main page of my SMF forum that are different depending on whether the user is not logged in or, if logged in, in which user group he/she is.

I don't know enough php/mySQL to do this so I wonder if anyone can give me advice. :)
Title: Re: Including custom html depending on SMF member group?
Post by: Peter Duggan on December 14, 2004, 12:52:28 PM
Shouldn't need anything more than some $context-dependent conditions. So basically this kind of thing:

if ($context['user']['is_admin'] or $context['user']['whatever_you_want'])
{
echo '
<blah>Blah</blah>';
}
elseif ($context['user']['is_logged'])
{
echo '
<blah>Blah</blah>';
}
else
{
whatever;
}
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on December 14, 2004, 07:08:07 PM
Thank you Peter!
I tested and it works pretty well for me. I managed to get different messages to unlogged, logged user or admin. But how can I set that just one member group see a specific message? I don't understand the "whatever_you_want"  thing. In what format should I enter the member group name?
Title: Re: Including custom html depending on SMF member group?
Post by: Peter Duggan on December 14, 2004, 07:14:02 PM
Quote from: nilsjohan on December 14, 2004, 07:08:07 PM
I don't understand the "whatever_you_want"  thing. In what format should I enter the member group name?

It was meant as pseudo code for your actual array key(s), so you'll need to check your own member groups.
Title: Re: Including custom html depending on SMF member group?
Post by: Peter Duggan on December 14, 2004, 07:16:24 PM
Quote from: Peter Duggan on December 14, 2004, 07:14:02 PM
It was meant as pseudo code for your actual array key(s), so you'll need to check your own member groups.

So that example condition was for an admin *or* member of an imaginary (whatever_you_want) member group!

PS Sure you've got the 'blah' thing but, in case it's not obvious, 'whatever;' is also pseudo code.
Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on December 14, 2004, 09:07:28 PM
Well, actually, you'd have to do:

in_array(##, $context['user']['groups'])

For your own custom groups, where ## is the ID of that group.

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Peter Duggan on December 14, 2004, 09:19:59 PM
So I *should* have checked that out instead of guessing because it's so obvious now you point it out!
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on December 15, 2004, 06:48:48 AM
Sorry, but I am totally useless when it comes to PHP... :-[

I didn't manage to get the in_array thing to work.

How exactly would the first line look like if it would apply to only member group "9" and not admin?
Title: Re: Including custom html depending on SMF member group?
Post by: Peter Duggan on December 15, 2004, 10:57:08 AM
if (in_array(9, $context['user']['groups']))
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on December 15, 2004, 02:54:25 PM
I am using the following code in the templates but it still dont work for the member group. I just get the messages for logged in or not logged in .


if (in_array(9, $context['user']['groups']))
{
echo '
you are a in member group 9';
}
elseif ($context['user']['is_logged'])
{
echo '
you are logged in';
}
else
{
echo '
you are not logged in';
}
Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on December 15, 2004, 04:15:44 PM
Sorry, not $context['user'], $user_info.

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Peter Duggan on December 15, 2004, 04:20:01 PM
Quote from: [Unknown] on December 15, 2004, 04:15:44 PM
Sorry, not $context['user'], $user_info.

Had just been checking and was about to reply when that came in!

So you want:

if (in_array(9, $user_info['groups']))
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on December 16, 2004, 06:45:15 AM
It works fine now!

But...
When I include this in the profile template it of course show up even when users are looking in other members profiles.
How can I limit all this to only be displayed in the users own profile page?
Title: Re: Including custom html depending on SMF member group?
Post by: Grudge on December 16, 2004, 07:15:08 AM
In profile use this:
$context['user']['is_owner']
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on January 04, 2005, 01:28:57 PM
Thanks you, that works really well on most places!
I would like to add a table row with content in the middle of the "Edit Profile" page just above the "Chose password" section but this code don't work there. Why, and what should I change?

Also, would it be possible to completely remove the change password section for my member group 9? That group already has another place to change password and if using SMF to do this they go out of sync.

Johan:)
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on January 05, 2005, 11:38:30 AM
Well, forget about the previous post.

I have now disbled the account settings for group 9 so the "Account related settings" link is removed from the left hand menu in the profile of all members of group 9.
Now I need to put a link for this group to another place to edit their password and email address.
I use this code:

if (in_array(9, $user_info['groups']) and $context['user']['is_owner'])
{
echo '
Link to account settings';
}
else
{
echo '
print nothing';
}


If I put this somewhere in the right side table (profile info) it works as expected but I cant get it to work in the left menu. I guess it is complicated to get this link included in the middle of this menu table but if it could be just above or below this menu table it would be great.

Whould that be possible and how?

Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on January 07, 2005, 04:38:18 AM
Hmm... left menu?  Tell me, do attachments work properly?

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Nils Johan on January 07, 2005, 05:22:54 AM
Attachments?
I do not have attachements enabled  for the forum, but I don't understand how that would affect this. Does it?

When I put the above code in the left menu it displays "print nothing" no matter what member group the user is in.

Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on January 07, 2005, 09:21:33 PM
Ah, nevermind, sorry, I see what's causing it:

if (in_array(9, $GLOBALS['user_info']['groups']) and $context['user']['is_owner'])
{
echo '
Link to account settings';
}
else
{
echo '
print nothing';
}


-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Harelin on June 28, 2005, 08:25:59 PM
I'm attempting to use this, but I receive the error:

2: in_array(): Wrong datatype for second argument

Any idea as to what could be causing that?
Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on June 28, 2005, 08:31:06 PM
Sounds like you have not included SSI.php first.

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Harelin on June 28, 2005, 10:16:46 PM
That must be the issue because I don't know what you're talking about :)

I'm attempting to do this in my boardindex.template.php, at the bottom of my index - and if I needed to include SSI or whatnot to prevent guests from viewing this content, it must already be included because I got that working correctly as well as the code to require a minimum amount of posts to view... in the same section.
Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on June 28, 2005, 10:38:30 PM
You don't need SSI.php within the BoardIndex template.  Can you post a few lines above and below what you're trying to add?

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Harelin on June 28, 2005, 11:09:23 PM
      echo '
        </table>
         </table>
  <BR>
<div align=center>
    <table width="75%
%" height="139" border="0" bgcolor="#50535B">
  <tr>
    <td width="22%" rowspan="2" bordercolor="#50535B" bgcolor="#50535B"><img src="http://www.evcitadel.com/triarii-icon.jpg" width="131" height="146"></td>
    <td width="78%" height="36" bordercolor="#50535B" bgcolor="#50535B"><font size="2" face="tahoma">
                      ';

if (in_array(66, $user_info['groups']))
{
echo 'You are a veteran member
        of Eternal Vigilance. It is your sworn duty to uphold and protect the
        ideals of the guild as you and your peers pave the way towards greatness.</em></font><BR><BR><font size="2" face="tahoma"><em>You possess the ability to vote in elections,
        run for election, or even spearhead new cohorts. You, as a revered veteran
        member, are responsible for swaying the course of the guild for years
        to come.';

        }
elseif ($context['user']['is_logged'])
{
echo 'alternate text';
}
else
{
echo 'guest text';
}


                echo '
        </em></font></p>
      </td>
  </tr>
</table> <BR>
</div>';
}

?>


should display (when I am in group 66)
(http://www.evcitadel.com/triarii-working.jpg)

but instead displays
(http://www.evcitadel.com/triarii-notworking.jpg)

granted I'm only trying to make the text in this instance dynamic and haven't even touched the image yet.
Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on June 29, 2005, 01:09:06 AM
$GLOBALS['user_info'] not $user_info.

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Shoeb Omar on August 28, 2005, 08:21:10 PM
out of interest (sorry to bring this right back up but I was searching for some stuff  and stumbled upon this, what is $context['user']['is_owner'] ?

I think I know now though - it's in the profile, so if this is the owner for this particular profile. Right?
Title: Re: Including custom html depending on SMF member group?
Post by: [Unknown] on August 28, 2005, 09:36:33 PM
Right.

-[Unknown]
Title: Re: Including custom html depending on SMF member group?
Post by: Shoeb Omar on August 28, 2005, 11:17:21 PM
Thanks.  Gotta store up these gems - soon SMF is going to be the user base for my site too hehe :)