|
How to check if user is admin?
|
| jodlajodla |
Posted on 04-08-2012 14:36
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
Hello,
I'm writing some infusion for user warnings and before inserting in database I would like to check if the user is administrator. This is my first time writing an infusion and I don't know much about the functions in PHP-Fusion that I can use. How to do that?
Where can I write new function for one file in infusion?
If I would like to use this function in file my_infusion.php (this name is just for example), can I write it next to include of language file or somewhere else?
Thanks! 
P.S.: Is there any documentation with functions or something like that for PHP-Fusion Infusions? |
| |
|
|
| Yodix |
Posted on 04-08-2012 16:12
|

Member

Posts: 71
Joined: 22/10/2010
|
To check whether the user is an administrator is definition iADMIN , but it is better to check permissions checkrights(); function.
Happy Hunger Games! And may the odds be ever in your favor.
|
| |
|
|
| jodlajodla |
Posted on 04-08-2012 16:14
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
Which rights do I have to check, to know this is admin? |
| |
|
|
| Craig |
Posted on 05-08-2012 01:12
|

Fusioneer

Posts: 3980
Joined: 27/09/2005
|
In infusion.php, the inf admin panel array is where you define the access rights for that infusion.
Like so...
Code$inf_adminpanel[1] = array(
"title" => "An Infusion",
"image" => "image.gif",
"panel" => "admin/index.php",
"rights" => "RIG"
);
Where you see...
Code "rights" => "RIG"
That's the admin access rights for it.
Then in the page you wish only the admin who has RIG rights to see, like the settings for your infusion or whatever page, you would then add in the top of the file usually after the maincore.php and admin_header.php include. Just like so...
Codeif (!checkrights("RIG") || !defined("iAUTH") || !isset($_GET['aid']) || $_GET['aid'] != iAUTH) redirect("../index.php");
There you can see only admins with the checkrights RIG will be able to enter that page.
Please note that ../index.php is just an example for the redirection page if not got the access rights sometimes this might be different depending on which folder your index.php lies in.
|
| |
|
|
| jodlajodla |
Posted on 05-08-2012 10:39
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
Thanks!
What means $row in dbresult($query, $row) if:
$query = "SELECT infusion_id FROM DB WHERE user_id=20"?
Is there any documentation with functions or something like that for PHP-Fusion Infusions?
EDIT: What about user_level? I see the administrators have bigger user_level than members - can I check administrators with this? (I need to check if user with name from input is administrator, so checkrights there will not work properly) |
| |
|
|
| Craig |
Posted on 05-08-2012 10:57
|

Fusioneer

Posts: 3980
Joined: 27/09/2005
|
I'll let this article do all the talking for now...
http://www.php-fu...icle_id=27
|
| |
|
|
| jodlajodla |
Posted on 05-08-2012 13:13
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
Where can I see some example for checking functions and for dbresult() (in which file are these functions written)? |
| |
|
|
| Craig |
Posted on 05-08-2012 13:36
|

Fusioneer

Posts: 3980
Joined: 27/09/2005
|
Function dbrows
Codefunction dbrows($query) {
$result = @mysql_num_rows($query);
return $result;
}
Example Usage
Code$result = dbquery("SELECT * FROM ".DB_YOURS." WHERE a_id !='0'");
if (dbrows($result > 0)) {
while ($data = dbarray($result)) {
echo $data['a_id'];
}
} else {
die("FAIL");
}
|
| |
|
|
| jodlajodla |
Posted on 05-08-2012 13:42
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
What about example for checkgroup()/checkrights() if I need to check other user (which I choose after I type it in input box) than me?
EDIT: In which files are these functions written?
Edited by jodlajodla on 05-08-2012 13:47
|
| |
|
|
| Craig |
Posted on 05-08-2012 13:47
|

Fusioneer

Posts: 3980
Joined: 27/09/2005
|
Look in maincore.php
|
| |
|
|
| jodlajodla |
Posted on 05-08-2012 14:04
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
I looked into file, but I can't find function that I need or I don't know how to use it. Now I will explain you, what I need.
First of all I type somebody's username into input box and set few (currently unimportant) things. When I send the form, infusion checks if username exist (normally SQL statement - SELECT, FROM, WHERE). If this username exist, than insert it into database. But before insertion in database, I'd like to check if this user is administrator and if it's, the infusion must return error.
What's the way to do checking for administration rights? |
| |
|
|
| Craig |
Posted on 06-08-2012 10:38
|

Fusioneer

Posts: 3980
Joined: 27/09/2005
|
You sure about that? 
Also what's the difference between this and registration?
|
| |
|
|
| jodlajodla |
Posted on 07-08-2012 08:18
|

Junior Member

Posts: 15
Joined: 04/08/2012
|
Yes, because instead of username the script insert user id into database.
Craig wrote:
Also what's the difference between this and registration?
User is just number (user id) in database in my case, at registration user gets inserted all information that it provide.
So...
Merged on Aug 07 2012 at 22:18:26:
One more question... Can I set checking if the user is administrator depending on user level?
I see that normal members have user level 101, administrators 102 and super administrator 103.
Edited by jodlajodla on 07-08-2012 22:18
|
| |
|
|
| PolarFox |
Posted on 08-08-2012 13:55
|

Admin

Posts: 1480
Joined: 26/08/2008
|
user is administrator depending on user level?
yes
user level 101, administrators 102 and super administrator 103.
right
|
| |
|
|
| Craig |
Posted on 08-08-2012 13:57
|

Fusioneer

Posts: 3980
Joined: 27/09/2005
|
jodlajodla wrote:
Merged on Aug 07 2012 at 22:18:26:
One more question... Can I set checking if the user is administrator depending on user level?
Yes
|
| |
|