News:

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

Main Menu

Including custom html depending on SMF member group?

Started by Nils Johan, December 14, 2004, 08:37:15 AM

Previous topic - Next topic

Nils Johan

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. :)

Peter Duggan

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;
}

Nils Johan

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?

Peter Duggan

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.

Peter Duggan

#4
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.

[Unknown]

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]

Peter Duggan

So I *should* have checked that out instead of guessing because it's so obvious now you point it out!

Nils Johan

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?

Peter Duggan


Nils Johan

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';
}

[Unknown]

Sorry, not $context['user'], $user_info.

-[Unknown]

Peter Duggan

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']))

Nils Johan

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?

Grudge

I'm only a half geek really...

Nils Johan

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:)

Nils Johan

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?


[Unknown]

Hmm... left menu?  Tell me, do attachments work properly?

-[Unknown]

Nils Johan

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.


[Unknown]

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]

Harelin

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?

Advertisement: