This topic is locked

multiple users problem

8/26/2011 6:39:11 AM
PHPRunner General questions
T
techster author

Hi
This is what I am looking for:
Roles & Users

ADMIN, USERS, CUSTOMER

ADMIN - Moderators

USERS - Data fetchers and collectors

CUSTOMER - To whom data must be forwarded
Now a user will upload lets say 10 records. Out of these 10, 4 are sent to customer 1 and 6 to customer 2. This moderation is done by admin. Now I want to restrict user to see only these 10 records since he added them; at customers' login end I want to show them only the data that has been assigned to them.
How can I do this?

C
cgphp 8/26/2011

I suppose that in the "records" table there will be a field indicating the record owner (username_field) so, in the "Before SQL query" event of the List page, set the where clause for the current logged in user:

$strWhereClause = "username_field='".$_SESSION['UserID']."'";
T
techster author 8/26/2011



I suppose that in the "records" table there will be a field indicating the record owner (username_field) so, in the "Before SQL query" event of the List page, set the where clause for the current logged in user:

$strWhereClause = "username_field='".$_SESSION['UserID']."'";



Yes, there is one owners' field. But the problem is here:
Scenario 1:
Say, Mark, enters 3 records to the table.

Now, administrator, Jacob, will moderate as per the availability of customers. He assigns (Owner field) to 2 people - Nancy with 2 records from Mark; and Martha for the other one.

Once moderated, Mark would want to be updated on the details that he has provided so he should be able to see all of his data. Now, Nancy would be concerned only about the leads that are assigned to her so she will need only her view; same for Martha.
Jacob would want to see everything on the table.
If I add where clause to the session user ID; it will only show the records which have owners field set to the particular USER ID.

Do you think if I add 2 fields, it will work - one as owner & the other as assignedto.

ownersfield - Mark

Assignedtofield - Nancy

Assignedtofield - Martha
Now how do I ensure that these 2 fields are checked against logged in user? So we will use OR statement here, right? Essentially, a record can either belong to someone who is logged in OR is assigned to him/her.
Many thanks, Cristian... you had been a great help.
TIA

C
cgphp 8/26/2011

I think it would be better to have a support table for the assignments. Anyway, if you add two new fields, the before SQL query becomes:



global $conn;

$strSQL = "SELECT GroupID FROM ugmembers WHERE UserName ='".$_SESSION["UserID"]."' LIMIT 1";

$rs = db_query($strSQL,$conn);

$record=db_fetch_array($rs);
if($record['GroupID'] != "Admin")

$strWhereClause = "ownersfield='".$_SESSION['UserID']."' OR Assignedtofield_1 ='".$_SESSION['UserID']."' OR Assignedtofield_2 ='".$_SESSION['UserID']."'";
T
techster author 8/26/2011



I think it would be better to have a support table for the assignments. Anyway, if you add two new fields, the before SQL query becomes:



global $conn;

$strSQL = "SELECT GroupID FROM ugmembers WHERE UserName ='".$_SESSION["UserID"]."' LIMIT 1";

$rs = db_query($strSQL,$conn);

$record=db_fetch_array($rs);
if($record['GroupID'] != "Admin")

$strWhereClause = "ownersfield='".$_SESSION['UserID']."' OR Assignedtofield_1 ='".$_SESSION['UserID']."' OR Assignedtofield_2 ='".$_SESSION['UserID']."'";



Thanks again Cristian. What do we mean by support table? A new table with name, assignment id?

T
techster author 8/26/2011



Thanks again Cristian. What do we mean by support table? A new table with name, assignment id?


Can ownersfield be filled automatically with the user who logs in?

C
cgphp 8/26/2011

Yes, a table where you keep the record_id and the assignment_id.

C
cgphp 8/26/2011



Can ownersfield be filled automatically with the user who logs in?


Before record added ?

T
techster author 8/26/2011



Before record added ?


Yes, because onwer and user will be same at any given point in time...

C
cgphp 8/26/2011



Yes, because onwer and user will be same at any given point in time...


In the Fields section, uncheck the owner field for the add and edit page.

In the "Before record added/update" event enter:

$values['owner_field_name'] = $_SESSION['UserID'];