1
The_DoubleU
Finding out what group a user belongs to.
  • 2004/12/6 15:16

  • The_DoubleU

  • Just popping in

  • Posts: 9

  • Since: 2004/11/28


I have modified my theme.html to show only a header, a 1 column center and a footer.
In the header I want to create a dynamic menu with javascript.
Something like Xoops2.org.
But I want the menu really dynamic, so if a user is not logged in I want a menu with a few options, but no link to "My account".
If a user is logged in then I want to use a different menu.
I also want to make a different menu for people in different groups. Like moderators <-> normal users.

The way I thought of doing it is by calling a different Javascript depending on userlevel.
I found out that with <{if $xoops_isuser}> I can check if the user is logged in or not.

But is there a function like <{if $xoops_group="groupname}>?

If somebody has other suggestion on how to accomplish this, you are welcome to post them.

Willem.

2
Mithrandir
Re: Finding out what group a user belongs to.

a user can be a member of several groups, so it should be an in_array() statement instead of an == statement - however, the user's groups are not available in a smarty template by default.

If you can attach some php code to the menu, you can find the user's groups with
global $xoopsUser;
$groups $xoopsUser $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);

Hope this helps you along the way

3
The_DoubleU
Re: Finding out what group a user belongs to.
  • 2004/12/6 19:12

  • The_DoubleU

  • Just popping in

  • Posts: 9

  • Since: 2004/11/28


Thanks Mithrandir, your tip helped me on my way indeed.
As I'm new with php and xoops. I searched a bit further on how to implement this and I have it now working.

But could you translate this line for me.
$groups = $xoopsUser ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);

what does the ? do in this function, does it mean query?
And is this a php function or XOOPS specific. I searched php.net but couldn't find anything about it.
What does array(xoops_group_anonymous) do?
Is there a website, documentation where I can find more about this and other functions.
I'm familiar with Lotus and Java script and have a general understanding on how programming languages work but php and XOOPS are new for me and would like to learn more for myself then going here everytime and asking questions answered a miljoen times :)

Does the $Groups array, only contain the groupid as described in the MySQL database (1,2,3,etc) or can I also search on the name of the group

4
ackbarr
Re: Finding out what group a user belongs to.

$groups $xoopsUser $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);


the '?' in the line above represents an "inline-if statement". It is a shorthand way of writing this statement:
if ($xoopsUser) {
  
$groups $xoopsUser->getGroups();
} else {
  
$groups = array(XOOPS_GROUP_ANONYMOUS);
}


if the condition before the '?' evaluates as true the first statement (after the '?') is used, if false, the second (after the ':') is used.

5
The_DoubleU
Re: Finding out what group a user belongs to.
  • 2004/12/6 21:03

  • The_DoubleU

  • Just popping in

  • Posts: 9

  • Since: 2004/11/28


Thanks ackbarr, now it makes sense :)

As said before, I can now find out in which group a user is in and display a different message for each group.
Now I'm trying to add some html + smarty tags in a php echo command, and it miserably fails. :(

When typing this post I got an idea, and it worked.
I now can get the username with the command
$name = $xoopsUser->getVar('uname');
But how can I get the xoopsurl value?

Is there a list with these value's.
I checked API Doc, wiki. But couldn't find anything.

I have the following code in my theme.html.
<td id="login">
  <{if 
$xoops_isuser}>
    <{
php}>
      global 
$xoopsUser;
      
$user_group '2';
      
$admin_group '1';
      
$name $xoopsUser->getVar('uname');
      
$groups $xoopsUser $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
      if (
in_array($admin_group$groups)) {
        echo 
'Welcome&nbsp;<a href="',$xoops_url,'/user.php">',$name,'</a>&nbsp<a href="',$xoops_url,'/user.php?op=logout">Logout</a>';}
      elseif (
in_array($user_group$groups)) {
        echo 
'You are member of user group';}
      else {
        echo 
'you are member of no group';}                                        
    <{/
php}>

6
Dave_L
Re: Finding out what group a user belongs to.
  • 2004/12/6 21:10

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


The PHP Manual, viewable online or downloadable, is the best reference I've found on PHP:http://www.php.net/docs.php

array(XOOPS_GROUP_ANONYMOUS) creates an array with the single element XOOPS_GROUP_ANONYMOUS.

7
Mithrandir
Re: Finding out what group a user belongs to.

Quote:

The_DoubleU wrote:
I have the following code in my theme.html.
<td id="login">
  <{if 
$xoops_isuser}>
    <{
php}>
      global 
$xoopsUser;
      
$user_group '2';
      
$admin_group '1';
      
$name $xoopsUser->getVar('uname');
      
$groups $xoopsUser $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
      if (
in_array($admin_group$groups)) {
        echo 
'Welcome&nbsp;<a href="',$xoops_url,'/user.php">',$name,'</a>&nbsp<a href="',$xoops_url,'/user.php?op=logout">Logout</a>';}
      elseif (
in_array($user_group$groups)) {
        echo 
'You are member of user group';}
      else {
        echo 
'you are member of no group';}                                        
    <{/
php}>


Ok, first of all, since you have the check <{if $xoops_isuser}> you do not need the check in the assignment of $groups (as the user object IS set)
secondly, you use commas where you should use dots when building the a href.

Try this code:
<td id="login">
  <{if 
$xoops_isuser}>
    <{
php}>
      global 
$xoopsUser;
      
$user_group '2';
      
$admin_group '1';
      
$name $xoopsUser->getVar('uname');
      
$groups $xoopsUser->getGroups();
      if (
in_array($admin_group$groups)) {
        echo 
'Welcome&nbsp;<a href="'.XOOPS_URL.'/user.php">',$name,'</a>&nbsp<a href="'.XOOPS_URL.'/user.php?op=logout">Logout</a>';}
      elseif (
in_array($user_group$groups)) {
        echo 
'You are member of user group';}
      else {
        echo 
'you are member of no group';}                                        
    <{/
php}>
  <{/if}>
</
td>
The XOOPS_URL constant is defined as the URL to your XOOPS installation and corresponds to the Smarty variable <{$xoops_url}>

8
The_DoubleU
Re: Finding out what group a user belongs to.
  • 2004/12/6 22:37

  • The_DoubleU

  • Just popping in

  • Posts: 9

  • Since: 2004/11/28


Thanks all of you for helping me out with this one.
Using .XOOPS_URL. works fine.

I als removed the check if it is a xoops_user and modified the code now to $groups = $xoopsUser->getGroups();

The main problem I had with implementing this solution is "when to use what?", it was very hard to find it in any XOOPS documentation.
For example.
<{$xoops_url}> is used in html
.XOOPS_URL is used in PHP
Are there any other variations?

Also getting the info is difficult.
I understand from the php manual that I can get a variable with the command. Getvar(). But is there any documentation on what variables xoops_user has?
When trying to get the username I tried ('name'), {'username'}, etc. Only to find out after a lot of searching that the variable was called uname. If would be great if there is some document that would explains this.
For example:
xoops_session can contain xoops_url, xoops_user, xoops_database, etc
With all the variables linked to their documentation.
xoops_user can contain uname, uid, etc, etc.

I have been developing with Lotus Notes, and I started with xoops/php to expand my programming skills and I don't have the money to buy a Notes server :)
So if you take a look at this documentation you might understand what I mean with the comments above.

[Disclaimer]
If there is such documentation I will remove all comments above, smack my forhead 10 times on my keyboard and not abuse you guys anymore.
[/Disclaimer]

Thanks again for your quick replies and great help. Keep up the good work!
Willem.

Login

Who's Online

108 user(s) are online (68 user(s) are browsing Support Forums)


Members: 0


Guests: 108


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits