This topic is locked

Master Detail on 3 tables

1/18/2008 12:12:53 PM
PHPRunner General questions
R
reanim author

Hi all,
I am building a simple CMS system where each user can manage his own sections and each section has its own articles.
only the section owner can add articles in his sections.
as such i have the following tables:
users

-----------

user_id (primary - autoincrement)

username

password
sections

------------

section_id (primary - autoincrement)

user_id (foreign key)

section_title

section description
articles

---------
article_id (primary - autoincrement)

section_id (foreign key)

article_title

article_body

  1. how can i make this work in phprunner without adding a user_id column on the articles table (as this is inherited by the sections table and is redundant information)
  2. When selecting a section via a select box how can i enforce that the users only select on of their own sections and not the sections of other users?
    thanks in advance

J
Jane 1/21/2008

Hi,
unfortunately you can't setup correct security settings without user_id field in the articles table.

I recommend you to duplicate user_id field and then select User can see and edit their own record only option on the Advanced security settings dialog on the Security tab.
Regarding the second question.

Use custom where clause for this purpose on the "Edit as" settings dialog on the Visual Editor tab.

Here is a sample:

"user_id=".$_SESSION["user_id"]


Define $_SESSION["user_id"] in the AfterSuccessfulLogin event on the Events tab:

global $conn;

$str = "select user_id from users where username='".$_SESSION["UserID"]."'";

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

$data = db_fetch_array($rs);

$_SESSION["user_id"] = $data["user_id"];