Advertisement:

Author Topic: Including custom html depending on SMF member group?  (Read 43833 times)

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Including custom html depending on SMF member group?
« 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. :)

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Including custom html depending on SMF member group?
« Reply #1 on: December 14, 2004, 12:52:28 PM »
Shouldn't need anything more than some $context-dependent conditions. So basically this kind of thing:

Code: [Select]
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;
}

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #2 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?

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Including custom html depending on SMF member group?
« Reply #3 on: December 14, 2004, 07:14:02 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.

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Including custom html depending on SMF member group?
« Reply #4 on: December 14, 2004, 07:16:24 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.
« Last Edit: December 14, 2004, 07:19:55 PM by Peter Duggan »

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Including custom html depending on SMF member group?
« Reply #5 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]

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Including custom html depending on SMF member group?
« Reply #6 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!

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #7 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?

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Including custom html depending on SMF member group?
« Reply #8 on: December 15, 2004, 10:57:08 AM »
Code: [Select]
if (in_array(9, $context['user']['groups']))

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #9 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 .

Code: [Select]
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';
}

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Including custom html depending on SMF member group?
« Reply #10 on: December 15, 2004, 04:15:44 PM »
Sorry, not $context['user'], $user_info.

-[Unknown]

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Including custom html depending on SMF member group?
« Reply #11 on: December 15, 2004, 04:20:01 PM »
Sorry, not $context['user'], $user_info.

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

So you want:

Code: [Select]
if (in_array(9, $user_info['groups']))

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #12 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?

Offline Grudge

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,742
  • Gender: Male
  • Unofficial nuisance
Re: Including custom html depending on SMF member group?
« Reply #13 on: December 16, 2004, 07:15:08 AM »
In profile use this:
$context['user']['is_owner']
I'm only a half geek really...

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #14 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:)

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #15 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:

Code: [Select]
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?

 

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Including custom html depending on SMF member group?
« Reply #16 on: January 07, 2005, 04:38:18 AM »
Hmm... left menu?  Tell me, do attachments work properly?

-[Unknown]

Offline Nils Johan

  • Semi-Newbie
  • *
  • Posts: 18
Re: Including custom html depending on SMF member group?
« Reply #17 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.


Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Including custom html depending on SMF member group?
« Reply #18 on: January 07, 2005, 09:21:33 PM »
Ah, nevermind, sorry, I see what's causing it:

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

-[Unknown]

Offline Harelin

  • Semi-Newbie
  • *
  • Posts: 88
  • Gender: Male
Re: Including custom html depending on SMF member group?
« Reply #19 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?