This topic is locked
[SOLVED]

 Adding a where clause prior to list and search

10/1/2017 8:57:29 PM
PHPRunner General questions
K
keithh0427 author

I have a need to restrict the query based on whether or not the user is in the Admin group.
I've started working with the list page
function BeforeQueryList($strSQL, $strWhereClause, $strOrderBy, $pageObject)

{

if (IsAdmin())

$query->addWhere("regionID='".$_SESSION["regionID"]."'");

}
But, this is obviously not working.
I've looked at the strWhereClause, but it's only showing ((1=0)) when I don't want to display records before a search and it doesn't display anything when a search is not required before displaying records.
I can limit the dropdown search box to a particular "regionID", but then the Admins can't access anything (as they don't have a "regionID"
Can someone point me in the right direction?

romaldus 10/2/2017

in PHPRunner 9.8 you can use security API, for example to check logged in user is admin or not:

//replace $test variable with your own var

$test=Security::isAdmin();
//if logged in user user is admin:

if($test){
//do something for example:

echo 'you are admin';

}
//but if logged in user user is NOT admin:

else{
//do something:

echo 'you are not admin';}
romaldus 10/2/2017

Check phprunner user manual for other methods:

https://xlinesoft.com/phprunner/docs/secapi_about.htm

K
keithh0427 author 10/2/2017

Yes, I'm doing that to some extenet by using the IsAdmin() functionality as shown in my original post.
How do I limit a data element?
I've also tried this:
if (!IsAdmin())

{

$regionID = $_SESSION["regionID"];

$query->addWhere("regionID = $regionID");

}
but that doesn't work either

romaldus 10/2/2017

Just to make sure you need to declare a variable contains Security::isAdmin()

Do not use isAdmin() directly