This topic is locked

restrict detail view based on master access.

12/4/2007 6:16:11 AM
PHPRunner General questions
G
garethp authorDevClub member

Hey there.
I am not a php programmer and have just found phprunner and it is just great. I have managed to do everything I need (so far!!!) excpet one major problem that I am sure there is a way to overcome. I have played around in the edit sql to bring in fields from other tables in my view so I know where to edit the sql if required - although I only know codes I found on the internet - you have to start somewhere!!!
I have 3 tables ina mysql database with the following fields (I only show the relationship fields):
User (name,password,supplierID)

Order_header (orderID,supplierID)

Order_details (oderdetailID,orderID)
I have set up a master-detail relationship between Order_header and Order_details.
I have also managed to set a log in so the user oly sees the Order_header for their accont (supplierID in the users table).
However, how do I restrict the Order_details so the user can only see the records for their orders. There is no supplierID in the Order_details table that I can use to restrict from the user table. The relationship is through the Order_header table and the supplierID.
Hope this makes sense - I would be so greatful if anyone can help me. Many thanks

J
Jane 12/4/2007

Hi,
you can do it using List page: Before SQL query event for Order_details table on the Events tab.

here is a sample code:

global $conn,$strTableName;

if ($_SESSION[$strTableName."_masterkey1"])

{

$str = "select * from Order_header where orderID=".$_SESSION[$strTableName."_masterkey1"];

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

if (!$data = db_fetch_array($rs))

$strWhereClause = whereAdd($strWhereClause,"1=0");

}

else

$strWhereClause = whereAdd($strWhereClause,"1=0");

G
garethp authorDevClub member 12/4/2007

Jane - many thanks for your quick response - I have managed to make it work and is great - THANKS SO MUCH.
I now have another question as a result of adding the code:
Now only the users order show in the Order_header menu tab - perfect!
When I click the Order_details link for a particular order the the lines associated with this order are shown on the Order_details menu tab - perfect.
If I just click the Oder_details menu tab (not following a particular order link from the Order_header menu tab) then no records are shown - is there anyway to show here all the details associated with all the users Orders (as when there is no coding all the order_detial line are shown).
Many many thanks again for your help.