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.