Hi.
I'm creating a menu on my TinyPortal homepage that accesses the SMF usergroups. There are a number of usergroups that I have set up that users (students) are allocated to depending on the product they select through the Paid Subscriptions mod. The usergroups will be titled something like "course1", "course2", etc, and students can have a number of these groups assigned to their username depending on how many products they purchase.
The menu I'm creating is a list of hyperlinks pointing to various file attachments that are relevant to their course (PDF, audio, video, etc). When the student logs in, they will be presented with the menu that lists all the files they are allowed to access based on the courses they have paid for. I have already worked out all the logic in presenting the links, but having trouble coding them.
I am able to code the links which only the admins (administration panel) and guests (marketing material) are allowed to access. I use the following code for these:
if ($context['user']['is_guest'])
echo '
<a href="{URL}">Course Information</a><br />';
However when I put the usergroup titles that I have created (course1, course2, teacher, etc) in the Manage Usergroups admin panel, it doesn't work.
Can you please advise the correct code to use for my usergroups?
Thanks.
if (in_array('1',$GLOBALS['user_info']['groups']) || in_array('3',$GLOBALS['user_info']['groups']))
{
echo 'the stuff you want groups 1 and 3 to see';
}
elseif (in_array('2',$GLOBALS['user_info']['groups']) || in_array('5',$GLOBALS['user_info']['groups']))
# = user group
[hr]
{
echo 'the stuff you want groups 2 and 5 to see';
}
elseif (in_array('4',$GLOBALS['user_info']['groups']))
{
echo 'the stuff you want group 4 to see';
}
else
{
echo 'this part is optional if you have something you want others, like guests to see.';
}
is code i use
here is a variation of the above to lessen the code length when allowing multiple groups access:
$GroupArray = array(1,3,10); // groups 1 and 3 and 10 have access
if (in_array('$GroupArray',$GLOBALS['user_info']['groups'])
Quote from: Assistance on December 28, 2007, 12:59:38 AM
if (in_array('1',$GLOBALS['user_info']['groups']) || in_array('3',$GLOBALS['user_info']['groups']))
{
echo 'the stuff you want groups 1 and 3 to see';
}
elseif (in_array('2',$GLOBALS['user_info']['groups']) || in_array('5',$GLOBALS['user_info']['groups']))
# = user group
[hr]
{
echo 'the stuff you want groups 2 and 5 to see';
}
elseif (in_array('4',$GLOBALS['user_info']['groups']))
{
echo 'the stuff you want group 4 to see';
}
else
{
echo 'this part is optional if you have something you want others, like guests to see.';
}
is code i use
Hi.
Thanks for this code. I've tried giving it a go but with no success to date. As an example, I've used the following code on a php article page in TinyPortal (this is the entire code I have listed on this page):
________________________________________________________
if (in_array('bootcamptrainee',$GLOBALS['user_info']['groups']))
{
echo 'Your Course';
}
else
{
echo 'Marketing';
}
________________________________________________________
You would expect users with a membership "bootcamptrainee" would see the words "Your Course", but they are seeing the word "Marketing" in the output like everyone else.
Is there anything else that I should be putting in this document, like a function definition, etc. I haven't had any other issues with membergroups being able to see what they have been allocated.
Thanks.
The problem is that usergroups are defined by id, not names. So try finding the id number of the group and use these instead. For example, looking in membergroups section in admin and hovering over a membergroup link will reveal the id in the adress there.
Quote from: Bloc on December 29, 2007, 04:56:25 AM
The problem is that usergroups are defined by id, not names. So try finding the id number of the group and use these instead. For example, looking in membergroups section in admin and hovering over a membergroup link will reveal the id in the adress there.
That worked! Thanks very much for your help, Bloc.
Cheers.
E-Learn Interactive.