xoops forums

yotsugi

Just popping in
Posted on: 2008/7/25 4:17
yotsugi
yotsugi (Show more)
Just popping in
Posts: 1
Since: 2008/7/25
#21

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Quote:

This is great! Would there be a way to do this for an individual user...Im a webmaster, but there's a couple other webmasters on the site I work on, and I would like to have a couple of things in my theme so only I would have a slightly different layout.
Also, Im really new to xoops, so if somebody could lay it all out for me, like leoscotch did (thanks for that!)
Thank y'all!

Why you don't create another group for other "webmaster"? On this case, I created one group and placing the other "webmaster" into that group. Then, I'm using $group_id smarty in the template to differentiating the template between the real webmaster and the other webmaster.

For example:
<{if $xoops_isadmin}> <!--condition if the real webmaster login-->
what to do
<{elseif 
$group_id == 4}> <!--condition if the other webmaster login ("4" is the id of the group created before)-->
something to do if first condition is false and this condition is true
<{/if}>


And if you want to do it to individual user, maybe you can using $user_id smarty...

zite83

Just popping in
Posted on: 2009/3/17 1:35
zite83
zite83 (Show more)
Just popping in
Posts: 41
Since: 2004/10/5
#22

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Here is how I got mine to work

I used this because I have a custom nav bar at the top of my website, it doesn't really need to be dynamic but what I need is when a user logs in if that person belongs to the right group something will show up. So in my case, when a user is logged in and belongs to group 9 he or she will get a "Submit News Link" other users that don't belong to this group do not get the link.

Another thing I noticed is when you update a user and add a new group for them to belong to, it won't take effect till next log in.

/class/template.php
add
global $xoopsUser;
if ( @
$xoopsUser && is_object($xoopsUser) ) {
$this->assign'xoops_usergroups'$xoopsUser->getGroups() );}


under

$this->Smarty();


save file template.php

add to your theme/template
<{foreach item=group from=$xoops_usergroups}>
    <{if 
$group.groupid == 9}>  
        
YOU CAN SEE ME GROUP 9!
    <{/if}>
<{/foreach}>


ghia

Community Support Member
Posted on: 2009/3/17 9:58
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#23

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Why
if ( @$xoopsUser && is_object($xoopsUser) ) {
?
Is
if ( is_object($xoopsUser) ) {
not sufficient? You should try to avoid the use of @.

Catzwolf

Home away from home
Posted on: 2009/3/17 10:10
Catzwolf
Catzwolf (Show more)
Home away from home
Posts: 1392
Since: 2007/9/30
#24

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Quote:

ghia wrote:
Why
if ( @$xoopsUser && is_object($xoopsUser) ) {
?
Is
if ( is_object($xoopsUser) ) {
not sufficient? You should try to avoid the use of @.


I totally agree with that statement.

Problem is that I am seeing this more and more with the core and it is regarded as bad coding practice. When you start suppressing errors, you basically start making the debugging process a nightmare and when in reality, it should be a simple job.

The use of such examples:

@require_one my/file/to/include.php;


To me the worst type of suppressing an error: When it is faster and better to do the following:

if ( file_exists$file XOOPS_ROOT_PATH '/user.php' ) ) {
    require_once 
$file;
} else {
    
trigger_error"File: $file not found" );
}


Thought rather simplistic in its approach, it would provide the information on a fail that a developer would need to correct the issue.

But I am more than sure ghia could provide betters examples :)

Catz :)

ghia

Community Support Member
Posted on: 2009/3/17 11:30
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#25

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Quote:
But I am more than sure ghia could provide betters examples
No, your example demonstrates exact some of the problems. And this is a real life example by Hervet.

I believe that also the @ is the main problem why so many users have problems with the admin module manager, which fails to show uninstalled modules if there is one in it with some kind of problem. And with no messages in debug, nobody has a clue why.

For me, the @ should be banned, and in the first place from all core code.

Catzwolf

Home away from home
Posted on: 2009/3/17 12:43
Catzwolf
Catzwolf (Show more)
Home away from home
Posts: 1392
Since: 2007/9/30
#26

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Yes, I can actually give you a better example with the core that had me baffled for 5 hours and if the @ hadn't been used I would have fixed the problem in about 1 minute.

$this->path_basic XOOPS_ROOT_PATH "/class/captcha";
$this->path_plugin XOOPS_ROOT_PATH "/Frameworks/captcha";

    function 
loadConfig($filename null)
    {
        
$filename = empty($filename) ? "config.php" "config.{$filename}.php";
        
$config = @include "{$this->path_basic}/{$filename}";
        if (
$config_plugin = @include "{$this->path_plugin}/{$filename}") {
            foreach (
$config_plugin as $key => $val) {
                
$config[$key] = $val;
            }
        }
        
        return 
$config;
    }


As you can see, both paths have been suppressed and note the second line is a call to the Framework folders. Here we are making the framework a requirement of the core and not the other way around.

The code that was in the framework was to include a language file and wouldn't be considered a requirement. But the code was something like this:

if (!@include '/path/to/language/file.php') {
    require 
'/path/to/language/file.php';
}


With all the error suppression and the system failing to find the required file, all that happens is that we end up with a white page and even error debugging turned on and nothing to show where the problem lies.

I agree this practice should be banned from the core along with this baby and it's still used within the core code.

foreach ($_POST as $k => $v ){
   
$kk $v;
}


Catz

zite83

Just popping in
Posted on: 2009/3/17 23:01
zite83
zite83 (Show more)
Just popping in
Posts: 41
Since: 2004/10/5
#27

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Thanks for the feed back! I'm not a programmer to the slightest but I can understand the basics of it, I just know how to use others code snippets to solved my problems

redheadedrod

Home away from home
Posted on: 2010/1/20 15:18
redheadedrod
redheadedrod (Show more)
Home away from home
Posts: 1296
Since: 2008/2/26
#28

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

It has been a while since this thread was last updated and I want to know if this method works in the latest versions as of this writing.(2.3.3, 2.4.3)

If I have this right...

In /class/template.php we look for the line...
Quote:
$this->Smarty();


And insert the following lines after...
Quote:

global $xoopsUser;
if ( is_object($xoopsUser) ) {
$this->assign( 'xoops_usergroups', $xoopsUser->getGroups() );}



then in our
theme/template

use
Quote:

<{foreach item=group from=$xoops_usergroups}>
<{if $group.groupid == 9}>
YOU CAN SEE ME GROUP 9!
<{/if}>
<{/foreach}>


Then you could use this to go through every id and adjust the theme or template.

What adjustments would need to be made to this to make it look at the group name? And I assume that the system used ID 0-2 for anonymous, registered and admin.

On my site I have 2 additional users as it is a team site and I am using the registered user as the generic fans and I also have a "player" and "moderator" groups available.

Would rather set them up as the names of the groups so if I add or change groups later this can be used.

Also looks like the function listed in the first page would work the way I want it to as well and be somewhat simpler in the long run. Has anyone tested this and make sure it works?

And as has been asked where would you put this function?

Thanks!

JCash

Just popping in
Posted on: 2012/1/19 22:01
JCash
JCash (Show more)
Just popping in
Posts: 66
Since: 2011/2/22
#29

Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

Nice :)

Still works with Xoops 2.5.4 but... why it is not implemented by default ?
May be into Xoops 2.6 code ?

mjoel

Quite a regular
Posted on: 2013/8/18 10:58
mjoel
mjoel (Show more)
Quite a regular
Posts: 304
Since: 2006/12/9
#30

Re: $xoops_isadmin, $xoops_isuser, but $xoops_?

Quote:

Dave_L wrote:
This may help. I haven't tested it.

/**
 * Check whether current user is in specified group.
 *
 * @param string $group_name Name of group
 * @return bool True if user is in group, otherwise false
 */
function in_group($group_name) {
   global 
$xoopsUser;
   if (!
is_object($xoopsUser)) {
      return 
false;
   }
   
$member_handler =& xoops_gethandler('member');
   
$groups =& $member_handler->getGroupsByUser($xoopsUser->getVar('uid'), true);
   
$in_group false;
   foreach (
$groups as $group) {
      if (
$group->getVar('name') == $group_name) {
         
$in_group true;
         break;
      }
   }
   return 
$in_group;
}


Then you could assign a template variable:

$xoopsTpl->assign('in_subscribed_group'in_group('subscribed'));


Then in the template:

<{if $in_subscribed_group}>
   ...
<{/if}>


How do i use this if Im in custom php page ?

i tried this but not working
if ($in_group == 'nameofmygroup'
{
echo 
"In Group";
}   
else
{
echo 
"Not in Group";
}