davidekins
Programmer
I have written a (multi-departmental accessible) Contact Management 'plugin' for a clients CMS (LDU) - it works very well and I am looking to improve it.
The client is multi-departmental and the contact records are entered/stored with a departmental 'flag' so that only the respective department can see their own records (admin can see all).
I was using some of the CMS system variables, namely $userlevel and $username within an IF/ELSEIF statement to drive a MySQL query to display the records.
This was a little clunky as it meant everyone in a department had to use the same username. So, I decided to incorporate a group function and assign users to a specific groups...I set this up and I can now assign members of departments to a group and the plugin now uses the group ID (and the CMS system userlevel variable) within an If/Endif statement to determine which records to show a group (department) member.
It works FANTASTIC.....for a single group membership.
However, I am now faced with a dilema...how do I accomodate 'multiple group' membership into the query?
If for example, a user is in Finance and is a member of the 2 groups, 'accounts receiveable' and 'accounts payable', how do I show the contacts stored in the database, for these 2 areas, as one dataset?
Here is a snippet of my current code: (that shows departmental records dependant upon single group membership)
The IF statement checks for a userlevel of 1 and membership of Group 3
the '$contact_viewer' is a partial MySQL statement. Each record in the contact database has a 'contact_originator' field (the department that OPENED the initial record) and a 'contact visibility' field (contact_0x).
This example says: "WHERE the contact originator is NOT zero AND the contact originator is 3 OR the contact viewer is 3, then get those records......
if there is no match, the IF/ELSEIF goes to the next test (in this case, 'originator 4 and contact viewer 4)
I have a whole bunch of these IF/ELSEIF statements, (one for each department).
What I'd like to do is consolidate this somehow and and make it so that MySQL query will take mulit-group membership of a user into account.....all I have come up with so far as an idea is a whole bunch more OR clauses in the query...can I do it a better way?
I should add that I am not asking for someone to write this application for me - I'm just looking for help in doing this particular QUERY - I get wrapped-up in the LOGIC sometimes and its hard to see a clear path.
Thanks
David
The client is multi-departmental and the contact records are entered/stored with a departmental 'flag' so that only the respective department can see their own records (admin can see all).
I was using some of the CMS system variables, namely $userlevel and $username within an IF/ELSEIF statement to drive a MySQL query to display the records.
This was a little clunky as it meant everyone in a department had to use the same username. So, I decided to incorporate a group function and assign users to a specific groups...I set this up and I can now assign members of departments to a group and the plugin now uses the group ID (and the CMS system userlevel variable) within an If/Endif statement to determine which records to show a group (department) member.
It works FANTASTIC.....for a single group membership.
However, I am now faced with a dilema...how do I accomodate 'multiple group' membership into the query?
If for example, a user is in Finance and is a member of the 2 groups, 'accounts receiveable' and 'accounts payable', how do I show the contacts stored in the database, for these 2 areas, as one dataset?
Here is a snippet of my current code: (that shows departmental records dependant upon single group membership)
Code:
if ($suserlevel >=1 && $membership[3]=='Member')
{
$contact_viewer = "WHERE (contact_originator !='0' AND (contact_originator LIKE '3' OR contact_o3 LIKE '1')) AND";
}elseif ($suserlevel >=1 && $membership[4]=='Member')
{
$contact_viewer = "WHERE (contact_originator !='0' AND (contact_originator LIKE '4' OR contact_o4 LIKE '1')) AND";
}
----- etc.
(SQL Query code ommitted)
The IF statement checks for a userlevel of 1 and membership of Group 3
the '$contact_viewer' is a partial MySQL statement. Each record in the contact database has a 'contact_originator' field (the department that OPENED the initial record) and a 'contact visibility' field (contact_0x).
This example says: "WHERE the contact originator is NOT zero AND the contact originator is 3 OR the contact viewer is 3, then get those records......
if there is no match, the IF/ELSEIF goes to the next test (in this case, 'originator 4 and contact viewer 4)
I have a whole bunch of these IF/ELSEIF statements, (one for each department).
What I'd like to do is consolidate this somehow and and make it so that MySQL query will take mulit-group membership of a user into account.....all I have come up with so far as an idea is a whole bunch more OR clauses in the query...can I do it a better way?
I should add that I am not asking for someone to write this application for me - I'm just looking for help in doing this particular QUERY - I get wrapped-up in the LOGIC sometimes and its hard to see a clear path.
Thanks
David