1
blackrx
submenu view for certain user only
  • 2009/12/4 14:35

  • blackrx

  • Quite a regular

  • Posts: 227

  • Since: 2008/2/5 1



Ok im a php coding newbie and im trying to create my own simple module based on trabis dummy module


is there an easy way to let only admin or certain user to access a certain submenu

i have seen the news module - submenu to submit.php example..but it is complicated...

i have this in xoops_version.php

// Submenus
$modversion['sub'][0]['name'] = 'Director Section';
$modversion['sub'][0]['url'] = "director.php";

$modversion['sub'][1]['name'] = 'Submit Record';
$modversion['sub'][1]['url'] = "admin/add.php";


i tried this and it is not working

// Submenus
$modversion['sub'][0]['name'] = 'Director Section';
$modversion['sub'][0]['url'] = "director.php";

if (
$xoops_isadmin) {
$modversion['sub'][1]['name'] = 'Submit Record';
$modversion['sub'][1]['url'] = "admin/add.php";

else {

}


help

2
ghia
Re: submenu view for certain user only
  • 2009/12/4 16:32

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


A little bit too simple. You need to set your isadmin variable eg
global $xoopsModule;
if (
is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $modversion['dirname']) {
    global 
$xoopsModuleConfig$xoopsUser;
    
$isAdmin false;
    if (!empty(
$xoopsUser)) {
        
$isAdmin = ($xoopsUser->isAdmin($xoopsModule->getVar('mid')));
    }
}
This allows also the module administators.
If only the wemasters group may access, you use:
global $xoopsUser;
if ( 
is_object($xoopsUser) )
{
    if ( 
$xoopsUser->isAdmin() )
    {
....
    }
}

3
blackrx
Re: submenu view for certain user only
  • 2009/12/5 3:13

  • blackrx

  • Quite a regular

  • Posts: 227

  • Since: 2008/2/5 1


thanks Ghia yes it works..

but what about if i want a certain user (by id) or maybe a group member (moderator ?) to access the submenu

4
ghia
Re: submenu view for certain user only
  • 2009/12/5 8:16

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


I assume you have to configure that group or that user first and then you can compare these settings with
$groups is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$uid is_object($xoopsUser) ? $xoopsUser->getVar("uid") : 0;


5
blackrx
Re: submenu view for certain user only
  • 2010/3/7 3:10

  • blackrx

  • Quite a regular

  • Posts: 227

  • Since: 2008/2/5 1


Quote:

ghia wrote:
I assume you have to configure that group or that user first and then you can compare these settings with
$groups is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$uid is_object($xoopsUser) ? $xoopsUser->getVar("uid") : 0;



Ghia or anyone...

can you show if else example like in the previous post ?

i want a certain user (by id) or a group member (moderator ?) to access the submenu...

the if else admin works perfectly

thanks

6
blackrx
Re: submenu view for certain user only
  • 2010/3/7 8:28

  • blackrx

  • Quite a regular

  • Posts: 227

  • Since: 2008/2/5 1


ok i figure this out by looking at similar threads...thanks

group
// group
$groupes 0;
if (
is_object($xoopsUser))
{
$groupes $xoopsUser->getGroups();
}
else {
$groupes = array(XOOPS_GROUP_ANONYMOUS);
}

switch(
$groupes)
{

case (
in_array(1$groupes)): //admin
echo "admin group";


break 
1;

case (
in_array(2$groupes)): //registered
echo "registered group";


break 
1;

case (
in_array(3$groupes)): //anonymous
echo "guest group";


break 
1;

case (
in_array(4$groupes)): //customized
echo "custom group";
break 
1;
}


show user uid 76
//user
$uid is_object($xoopsUser) ? $xoopsUser->getVar("uid") : 0

if ( 
is_object($xoopsUser) )
{
 if ( 
$xoopsUser->getVar("uid")==76 )
 {
echo 
"User76";
 }
else
 {
echo 
"x user76";
 }


}

Login

Who's Online

236 user(s) are online (130 user(s) are browsing Support Forums)


Members: 0


Guests: 236


more...

Donat-O-Meter

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

Latest GitHub Commits