Having a Problem getting a Global Variable

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
ddonohue
Posts: 2
Joined: 2023-08-17 18:09

Having a Problem getting a Global Variable

Post by ddonohue » 2023-09-22 10:26

Hi

I have 2 problems at the moment
Firstly I have a database controlling wine storage where I would like the clients to log into the database and see the following
1) No of pallets sorted by the winetype and vintage
2) no of pallets sorted by the destination
3) No of pallets sorted by the category (type of Storage 'L/D' lying down bottles, 'S/U' standing up bottles '3H' 3 Pallets high )

I created in _globals.php the following
function login_ok($memberInfo, &$args) {
$logFile = 'members.log';
$usrindex = $memberInfo['custom'][0]; */= (custindex) */
$usrname = $memberInfo['custom'][1]; */= (custname) */
$ip = $memberInfo['IP'];
$date = date('m/d/Y');
$time = date('h:i:s a');
file_put_contents($logFile, "$date, $time,$usrindex,$usrname \n", FILE_APPEND);
return ' ' ;
}
so how do I get in the SQL "WHERE custindex = '$usrindex' "?
With the login the client show only get to see his pallets/


thanks for your help

David
Products.PNG
Products.PNG (54.43 KiB) Viewed 1669 times

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Having a Problem getting a Global Variable

Post by pbottcher » 2023-10-01 19:18

Hi,

you reference 2 problems. But I'm not even clear on one of them. Can you specify this in more details?

From what you write I would assume that you store in$memberInfo['custom'][0]; a custindex that you have in your product table as well.

If you try to display only the product for the user which match his custindex you can use the _init hook (hooks -> TABLENAME.php -> TABLENAME_init)

Here you can use some code like:

Code: Select all

	$usrindex = $memberInfo['custom'][0];

	$options->QueryWhere = $options->QueryWhere ? $options->QueryWhere . " AND " : " WHERE ";
	$options->QueryWhere .= "custindex = {$userindex}";
assuming your field is named custindex
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

ddonohue
Posts: 2
Joined: 2023-08-17 18:09

Re: Having a Problem getting a Global Variable

Post by ddonohue » 2023-10-04 21:25

HI

thanks a lot for your help and you are right.

I also solved the problem using the filter as follows

Code: Select all

	function products_init(&$options, $memberInfo, &$args) {
		$idx = $memberInfo['custom'][0];
		$idx1 = $memberInfo['custom'][1];
		
		if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
			
			addFilter(1, 'and', 6, 'equal-to', $memberInfo['custom'][0]);
			
		}
			 	
regards

David

Post Reply