1
attock
<{if $xoops_isadmin}> - Required class?
  • 2007/3/18 11:37

  • attock

  • Not too shy to talk

  • Posts: 138

  • Since: 2006/8/20


I am tryina to make a module, so in the index.php I have to make use of <{if $xoops_isadmin}>. Now my question is what files (classes) I need to include to in index.php.

Right now I have the followings:

include("../../mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");


thanks

2
skenow
Re: - Required class?
  • 2007/3/18 12:27

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


Anything with <{ }> is a Smarty tag and is used in the html pages for your module or theme. To use $xoops_isadmin in the logic for your module (in the php files), use it without the brackets.

The files you have included are correct.

3
ewonline
Re: <{if $xoops_isadmin}> - Required class?
  • 2007/3/18 16:24

  • ewonline

  • Not too shy to talk

  • Posts: 198

  • Since: 2004/11/17


Exactly, its
if ($xoops_isadmin) {
// do something
}
Resized Image

4
attock
Re: - Required class?
  • 2007/3/18 17:06

  • attock

  • Not too shy to talk

  • Posts: 138

  • Since: 2006/8/20


Aite i'll check it out

but I was using $xoops_isadmin() with teh brackets.

Dont we use brackets with functions in php ?

5
attock
Re: - Required class?
  • 2007/3/18 17:16

  • attock

  • Not too shy to talk

  • Posts: 138

  • Since: 2006/8/20


okie, I have tried:
if ($xoops_isadmin) {  // do something  }


but it doesnt seem to be working.

6
skenow
Re: - Required class?
  • 2007/3/18 20:57

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


$xoops_isadmin is not a function, is it a variable. If you used exactly the code above, you should not see any output. It only had the structure as an example.

if ($xoops_isadmin) {  print "The user is an admin";  }
will output the message "The user is an admin" to your browser.

I'm not trying to be simplistic, but you haven't provided us much information.

7
attock
Re: - Required class?
  • 2007/3/18 22:52

  • attock

  • Not too shy to talk

  • Posts: 138

  • Since: 2006/8/20


I am sowwie, thats wht I mean

the if statement is not working.

Do I need to inculde anything, or is there anyway around?

thank you

8
vaughan
Re: <{if $xoops_isadmin}> - Required class?
  • 2007/3/18 23:46

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


$xoopsUser needs to be declared globally

global $xoopsUser;

then the if statement >

it is actually $xoopsUser->isAdmin() and not $xoops_isadmin

so the full if statement would be >

global $xoopsUser;
if (
is_object($xoopsUser) && $xoopsUser->isAdmin()) {
your script here
}

9
attock
Re: - Required class?
  • 2007/3/19 13:14

  • attock

  • Not too shy to talk

  • Posts: 138

  • Since: 2006/8/20


more issue

okie this is what I have:
"../../mainfile.php"); 
include(
XOOPS_ROOT_PATH."/header.php"); 

global 
$xoopsUser
 if (
is_object($xoopsUser)) {    
  
$uid $xoopsUser->getVar('uid');  // I saw it another module
  
$uname_ $xoopsUser->getVar('uname');   // I saw it another module

   
echo "check if user..
"
;   
   if (
$xoopsUser->isAdmin()) echo "xoopsUser->isAdmin() result is: True
"
;
   if (
$xoops_isadmin"xoops_admin is: True
"
;     
 }

    if (
$uname == "admin") {
      echo 
"If statemen via uname is: True"
 }
    else { 
     echo 
"uname != admin, instead uname is: $uname";
  }
  
?>


As Admin I get the following

check if user..
xoopsUser->isAdmin() result is: True
uname != admin, instead uname is:

As user I get
check if user..
uname != admin, instead uname is:

not as user
uname != admin, instead uname is:

---------------------

$xoopsUser->isAdmin() works fine, but if a non-admin login is, the page wont be displayed - it halts any things after $xoopsUser->isAdmin() in php file.

Another question: Why am I unable to get uid & uname. I have used it at other places too, it works fine.

Am I doing sumthing really stupid ?

The file is located: root/modules/modulename/filename.php
also, there are no blocks on this module - does it matter?

Thank you for time

10
skenow
Re: - Required class?
  • 2007/3/19 13:45

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


Quote:
$uname_ = $xoopsUser->getVar('uname'); // I saw it another module


The underscore needs to be included in future references to this variable...

Quote:
echo "uname != admin, instead uname is: $uname";


becomes

Quote:
echo "uname != admin, instead uname is: $uname_";

Login

Who's Online

150 user(s) are online (93 user(s) are browsing Support Forums)


Members: 0


Guests: 150


more...

Donat-O-Meter

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

Latest GitHub Commits