This topic is locked
[SOLVED]

  Dropdown box values special filtering

10/7/2011 5:52:08 AM
PHPRunner General questions
M
marimach77 author

Hi,

I need some advice how to manage the problem below.
I have 3 tables:

Desktop - master table, fields: siteid and few others

Sites - dictionary table (data for dropdown box on desktop page), fields: SiteID, SiteName

Administrator - contains fields: UserLogin, SiteID, RoleID
I'm filtering records in Desktop table based on detected NT login and relation between tables.
Login page -> Before process (check the NT user name)

if ($_SERVER["REMOTE_USER"])

{

$_SESSION["UserID"] = $_SERVER["REMOTE_USER"];

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

header("Location: menu.php");

exit();

}


List page (Desktop) -> Before SQL Query

global $conn;

$rs = CustomQuery("SELECT RoleID FROM Administrator WHERE UserLogin='".$_SERVER["REMOTE_USER"]."'",$conn);

$data = db_fetch_array($rs);

if($data['RoleID'] == 'LOCALADMIN')

{

$rs = CustomQuery("SELECT SiteID FROM Administrator WHERE UserLogin='".$_SERVER["REMOTE_USER"]."'",$conn);

$sites = "(";

while($record = db_fetch_array($rs))

{

$sites .= "'".$record['SiteID']."',";

}

$sites .= "'')";

$strWhereClause = whereAdd($strWhereClause,"SiteID in ".$sites);

}


Summary:

  • if user has MASTERADMIN role - can see ALL records
  • if user has LOCALADMIN role - can see only records related to SiteID assigned to his NT login in Administrator table
    For now everything is working fine.
    Now I have dropdown box Site on page Desktop - it is connected to table Sites, linked field is SiteID, display field is SiteName. For now I see here all sites.
    How to set any relation on this dropdown box (Site) to show only sites match relations between NT login and records in Administrator table? Simple example:
  • if UserLogin AAA has assigned SiteID S1, S2 and has RoleID "localadmin", he should see only sites S1, S2 in dropdown box
  • if UserLogin AAA has assigned RoleID "masteradmin", he should see ALL sites in dropdown box
    Brgds

    Mariusz

C
cgphp 10/7/2011

The best way to proceed is to create a view inside SQLserver joining the Sites table and the Administrator table. The fields of the VIEW would be:

SiteID

UserLogin

SiteName


The VIEW will be the source of the dropdown:



Link field: SiteID

Display field: Sitename

WHERE: "UserLogin='".$_SESSION['UserID']."'"
M
marimach77 author 10/10/2011

This is working fine. Thanks a lot for simple advice <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61364&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />