filtering records by login.

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
dmac411
Posts: 10
Joined: 2014-04-21 01:06

filtering records by login.

Post by dmac411 » 2014-05-20 04:03

Appginians, - It's dorky but WTH, that's what happens when we spend too much time in front of screen :)

I have the following scenario:

1. A user adds a record which have multiple look ups in the screen ( a look up for state, a look up for a sales rep, etc)
2. The user selects values from the look up and saves the record; let's say a sales rep.
3. what I need to do is associate the sales rep entered in the record with a user log in.
4. I use the user management function provided by Appgini.
5. The sales rep will need to log in and only see record data where they were selected as a value and saved at the time the record was created.
6. If the author of the original record changes the look up value to another sales rep then the original rep will no longer be able to view\edit the record.
7. Are there any code samples or videos or narratives that can explain or demonstrate this scenario?

Dmac411

dmac411
Posts: 10
Joined: 2014-04-21 01:06

Re: filtering records by login.

Post by dmac411 » 2014-05-22 03:07

Team,

I have contemplated the following approach:

1. somehow attach the rep id from the table to a user login

a. have the sales rep register, enter address info and compare info entered against the table until a match occurs then have them validate and confirm, resulting in the rep id from the table assigned to user login
b. have the sales rep register; receive a notification, manually validate and confirm and assign rep id.
c. when a rep is assigned to the record, the user, assigns the id and a email notification for confirmation goes to rep to create a login/pass
d. the issue is that reps will "come n go" and are national in scale. So, it is important to assign (correctly) the rep id to a user log in so that rep will only see their assigned data..
e. any thoughts from the community on best approach to make sure that the correct rep id is assigned to a rep registering through a sign up page..?
f. any comments would be appreciated. The issue simply is that we have to be sure the correct rep id is assigned to the correct user login.

Thank you in advance for any thoughts or suggestions.

Dmac411

dmac411
Posts: 10
Joined: 2014-04-21 01:06

Re: filtering records by login.

Post by dmac411 » 2014-05-26 18:12

Team - I thought it thru.. going to create a separate rep table with user \ pass info. however that rep user table will be hyperlinked from the order table via authentication. the reason for this is because reps are independent and should be created on the fly and this will allow amininstration to review reps and rep orders in order to authorize individual or batch approval of the logins. this environment is very dynamic and the ability to take orders and create rep logins is key. once a rep is created the authentication hyperlink will be removed; however there will still be an admin panel for managing reps..

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: filtering records by login.

Post by peebee » 2014-05-27 08:15

I manage to direct members to their specific allocated records only by adding a switch to the "function login_ok' in the _global.php hook. You just use the normal Appgini membership management and assign Users to Groups as you would normally. The switch in the global hook handles what they end up looking at. If the person assigned to a specific record is changed, they no longer see that record - the new person assigned does. This is different to just seeing "Group" records. Sound like what you're after?

It can be a bit complicated/fiddly - depending on exactly what you're trying to achieve. You will have to duplicate and edit some files - but it does work well. It allows for incredible flexibility as to who see's exactly what. A warning: aprt from requiring some work; if you subsequently update your tables - you have to update all of your edited files too. Keep a good record of what you've done. I'll try to explain and hope I don't confuse too much.

The confusing/difficult part is that you need to create new alternative_view.php and alternative_dml.php files. Generally, that just requires copying and renaming (and maybe editing a little to suit) the Appgini generated tablename_view.php and tablename_dml.php file. You will have to edit accordingly everywhere that those files are referenced.

I've also created specific templates for specific groups so they can only see what I want them see - not necessarily every available field. That just requires editing generated templates, renaming them and then directing the members to those alternative_view.php files in the _global.php hook. So users will see the correct template, you'll also have to edit the template names in the alternative_view.php and alternative_dml.php files.

I'll try to explain with your example of Sales Reps - so they only see records that have been assigned to each individual Rep. You can make the redirection broad, based on one field criteria or even combine a couple of fields so they only see a very specific view. This following switch example is based on two conditions being matched ie.: Sales Person and their Department.

In your table sales_reps, you might have a field for "salesperson" and "dept". You also have a table for Sales. The sales_reps field is a dropdown in the Sales table and the Sales Person has been assigned to a department in the Sales Rep table.

Each "salesperson" MUST have a unique id - I'll just use a name for example. Say one of your Sales Reps recorded in sales_reps.salesperson is "John Smith". You now create a User Group called John Smith. The Usergroup name must match the "salesperson" name exactly or you'll end up with an empty table. John Smith has been assigned to the Electrical department.

OK, here's an example switch for the _global.php hook:

Code: Select all

function login_ok($memberInfo, &$args){
    // Define groupName & redirect User to specific view and template 
        $groupName=sqlValue("select name from membership_groups where groupID='".$_SESSION['memberGroupID']."'", $abc);
		switch(true){
			case ($_SESSION['memberGroupID']==2):				
				return 'tablename_view.php  // for Admins only  as they are always memberGroupID 2 - they see normal table view
				break;	
				
			case ($groupName==sqlValue("select salesperson from sales_rep where sales_rep.salesperson='$groupName' and sales_rep.dept='Electrical'")):			
				return 'electrical_view.php'; // this is the Sales Persons name and their department is Electrical
				break;
					
			case ($groupName==sqlValue("select salesperson from sales_rep where sales_rep.salesperson='$groupName' and sales_rep.dept='Plumbing'")):
				return 'plumbing_view.php';  // Sales person and their department is plumbing
				break;
				
			case ($groupName==sqlValue("select salesperson from sales_rep where sales_rep.salesperson='$groupName' and sales_rep.dept='Household'")):
				return 'household_view.php';  // getting the idea - lots of alternative views
				break;
				
			case ($groupName==sqlValue("select salesperson from sales_rep where sales_rep.salesperson='$groupName' and sales_rep.dept='Something Else'")):
				return 'something_else.php';  // and so on.....
				break;

			default:
				return 'index.php?loginFailed=1';  // for any other user 
				break;
		}
			
		return '';
	}
If John Smith who works in the Electrical Department logged in, he would be redirected to electrical_view.php and that might have a specific template assigned for that department that only requires certain fields to be visible. You can of course change the conditions in the switch above to any other variables you want and it will work the same.

Making any sense? Yes, confusing I know and a bit of editing required but it does work well and once set up, it's really easy to manage who sees what. Hope that helps or at least perhaps gives you some ideas.

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: filtering records by login.

Post by peebee » 2014-05-27 22:07

Oops, further to that post above... Sorry, I can't believe I forgot to add that you need to add a WHERE condition to the query in the new alternative_view.php files that you create so the User will see just records assigned to them.

In the new alternative_view.php, just below the line and fields that commences with "//Lookup fields that can be used as filters" you'll see a set of MySQL queries.

Immediately above the line that commences with: $x->QueryFrom=".....

Add this line: $groupName=sqlValue("select name from membership_groups where groupID='".$_SESSION['memberGroupID']."'");

Then, just below that you'll see the line: $x->QueryWhere='';

Replace that with: $x->QueryWhere="where `sales_rep`.`salesperson`='$groupName'"; (obviously you will have to replace the table name and field with your own table name and field.)

Then, when the User logs in and is redirected to the new custom alternative_view.php they will only see records that have been been assigned to them.

The other thing I should have mentioned in my first post is that adding Users and Groups to access just records assigned to them this way is a manual process by the Admin only. I can't think of a way to allow auto signups.

dmac411
Posts: 10
Joined: 2014-04-21 01:06

Re: filtering records by login.

Post by dmac411 » 2014-05-30 03:44

PeeBee,

I think it will work for me as you suggested.

I am anxious to try your method over the next week and will focus much time on it over the weekend.
I will definitely reply with the results.

It's an awesome functional approach you thought thru using the hooks and maintaining the integrity of Appgini code.

Thank you.


Sincerely,

Dmac411

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: filtering records by login.

Post by peebee » 2014-05-30 04:29

Good luck with it. Perhaps not the most elegant or the quickest/simplest way to go about it (I don't know any other way?) but there's no doubt it does work and will do exactly what you're after. I've been using it for years since Appgini V3 through to current V5.23.

User avatar
fbrano
Veteran Member
Posts: 70
Joined: 2018-03-19 10:39
Location: Slovakia
Contact:

Re: filtering records by login.

Post by fbrano » 2020-09-10 18:41

I'd like to use $memberInfo['custom'][1] variable, but have porblem with sytax:

$x->QueryWhere = 'where `Pristupy`.`Manazer`='{$memberInfo['custom'][1]}'"';

( ! ) Parse error: syntax error, unexpected '{'

Thank you
ver 23.15 1484

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: filtering records by login.

Post by jsetzer » 2020-09-10 19:00

As far as I know, {$variable} can not be resolved in single quoted strings but only in double quoted strings:

Correct:
"{$a}"

Not correct:
'{$a}'
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
fbrano
Veteran Member
Posts: 70
Joined: 2018-03-19 10:39
Location: Slovakia
Contact:

Re: filtering records by login.

Post by fbrano » 2020-09-10 19:17

Here is my code:
$memberInfo = getMemberInfo();
$x->QueryWhere = 'where `Pristupy`.`Manazer`="{$memberInfo['custom'][1]}""';

Still with error:
( ! ) Parse error: syntax error, unexpected 'custom' (T_STRING) in D:\wamp64\www\elp\Pristupy_view_revizia_ziadatel.php on line 142
ver 23.15 1484

User avatar
fbrano
Veteran Member
Posts: 70
Joined: 2018-03-19 10:39
Location: Slovakia
Contact:

Re: filtering records by login.

Post by fbrano » 2020-09-10 19:58

This code is without syntax error, but no records shows as result in query

$memberInfo = getMemberInfo();
$osc = $memberInfo['custom'][1];
$x->QueryWhere = 'where `Pristupy`.`Ziadatel`="$osc""';
ver 23.15 1484

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

Re: filtering records by login.

Post by pbottcher » 2020-09-10 20:36

try

Code: Select all

$x->QueryWhere = " where `Pristupy`.`Manazer`='".$memberInfo['custom'][1]}."'";
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.

User avatar
fbrano
Veteran Member
Posts: 70
Joined: 2018-03-19 10:39
Location: Slovakia
Contact:

Re: filtering records by login.

Post by fbrano » 2020-09-11 21:57

Here is correct syntax,

$x->QueryWhere = 'where `Pristupy`.`Schvalovatel`='.$memberInfo['custom'][1].'"';

but query is empty, isn't it because of Manazer field is lookup field?
ver 23.15 1484

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

Re: filtering records by login.

Post by pbottcher » 2020-09-12 10:41

Hi,

not sure if your syntax is correct, but if it is for you great.

You change the fieldnames and do not explain detailed enough what ou have/need, so it is impossible to guess what is not working.

So please explain detailed your issue.
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.

User avatar
fbrano
Veteran Member
Posts: 70
Joined: 2018-03-19 10:39
Location: Slovakia
Contact:

Re: filtering records by login.

Post by fbrano » 2020-09-14 00:36

ver 23.15 1484

Post Reply