xoops forums

blackrx

Quite a regular
Posted on: 2009/12/4 14:35
blackrx
blackrx (Show more)
Quite a regular
Posts: 227
Since: 2008/2/5 1
#1

submenu view for certain user only


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

ghia

Community Support Member
Posted on: 2009/12/4 16:32
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#2

Re: submenu view for certain user only

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() )
    {
....
    }
}

blackrx

Quite a regular
Posted on: 2009/12/5 3:13
blackrx
blackrx (Show more)
Quite a regular
Posts: 227
Since: 2008/2/5 1
#3

Re: submenu view for certain user only

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

ghia

Community Support Member
Posted on: 2009/12/5 8:16
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#4

Re: submenu view for certain user only

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;

blackrx

Quite a regular
Posted on: 2010/3/7 3:10
blackrx
blackrx (Show more)
Quite a regular
Posts: 227
Since: 2008/2/5 1
#5

Re: submenu view for certain user only

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

blackrx

Quite a regular
Posted on: 2010/3/7 8:28
blackrx
blackrx (Show more)
Quite a regular
Posts: 227
Since: 2008/2/5 1
#6

Re: submenu view for certain user only

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


}