This topic is locked

master key passing

9/18/2006 9:47:23 AM
PHPRunner General questions
K
ken.stessens@telenet.be author

Hello,
suppose I do the following on a build page (like an end user would do):

  • I am looking at a master page
  • I click the details link of record #99 to view its details
  • on the details page (obviously belonging to the master record #99), I want to add a/another detail record, so I click 'add'
  • now I am on the 'add' page
    -> at this point, I was expecting that the new added detail record would automatically be linked to the master record #99. In my case, it does not.
    Is the master key be passed automatically (so am I doing something wrong) or should it be programmed? What is the most elegant way to accomplish this?
    thanks in advance!

    Ken

A
andyjames 9/18/2006

Hi Ken
I encounter the same problem when I log in as ADMINISTRATOR with the "Add admin user that can see and edit all users data" enabled and set to my record on the Advanced Security Settings dialog.
If I then click on a detail table for another user and then click on Add to add a record to THEIR detail table, it adds the record but using my masterkey as the default value for the foreign key in the detail table.
The default value of the foreign key in the detail table is set to:

@$_SESSION[$strTableName."_masterkey"]
It seems to be taking the administrator masterkey. I have tried in vain to set a session variable of the foreign key of the user you click on but have not succeeded yet. There is no appropriate event.

The code in the mastertable_list.php file is:

<td align=center>

<a href="detailtable_list.php" onClick = "document.forms.details.action='detailtable_list.php';document.forms.details.masterkey.value='<?php echo db_addslashes($data[RemoveFieldWrappers("`mastertableprimarykey`")]);?>'; document.forms.details.submit();return false;">

Detail Table Caption

</a>

</td>


where

detailtable is the name of your detail table

mastertableprimarykey is the name of the primary key field in your master table

Detail Table Caption is the menu caption of the detail field.
If anyone knows how to set a session variable when clicking on this to then set as the default value of the foreign key in the detail table, then do let us know. Thanks

Sergey Kornilov admin 9/18/2006

Ken,
when you add a new detail record it's attached to the master record automatically.

If for some reasons it doesn't work send your PHP files, project files and sample database to support@xlinesoft.com.
Andy:

you are confusing master-details relationships with "Users can see and edit their own data only"security mode. When admin user adds a new record it belongs to admin.
If you setup both master-details and addvanced security mode using the same field most probably it won't work. In most cases you don't need to use them together.

A
andyjames 9/19/2006

Hi Sergey
Thanks for your explanation "When an admin user adds a new record it belongs to admin." This helps my understanding of how phprunner works.
But is there any way of admin adding detail records on behalf of another user attributing the other user's key fields rather than his own (apart from logging on as the other user). The reason for wanting to do this is because I have built an administrator interface as a separate, more elaborate project to my user interface. They both access the same database but the admin interface has various search functions and reveals fields that I don't want users to see. It would be fantastically helpful for me, as the administrator, to be able to add new detail records to other users records in the administrator interface without having to log on as them every time.

All of your help and insights are greatly appreciated <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=11169&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

Alexey admin 9/19/2006

Andy,
I see what you saying.

I recommend you to create a custom view for your details table, make this view available to admin only and set Users can see and edit all records mode for this table.

So admin will use this view to add records on behalf of other users.

A
andyjames 9/19/2006

Hi Alexey
You have made my day! Spot on, works a treat now.

Thanks for the excellent support and an excellent product.