This topic is locked

hiding edit link depending on username and group

3/23/2012 5:15:19 AM
PHPRunner General questions
S
Sergej author

i'm trying to do the following - if an user is not a member of admin group - he will have edit link only by his own user name - admin group member will have it under every username...

but it doesn't work
here is code placed on list page before process
global $conn;

if ($_SESSION["GroupPermiss"]!=-1)

{

$strSQLExists = "select * from TCIUsers WHERE username = '".$_SESSION["username"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if ($data){

$record["edit_link"] = true;

}

else

{

$record["edit_link"] = false;

}

}

TIA to all you guys

W
wildwally 3/23/2012

It looks like you might have things out of order from what I can tell and what you have posted.
The way I have gotten mine to work is like such:
In the Login Page after succesful login:
<code>

global $conn;

$str = "select * from dbo.table_ugmembers where UserName='".$username."'";

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

$data1 = db_fetch_array($result);

$_SESSION['Group'] = $data1['GroupID'];

</code>
Then on the list page of your choice List page:After record processed use:
<code>

if ($_SESSION['Group']=-1)

{

$record["edit_link"] = true;

}

else

{

$record["edit_link"] = false;

}

</code>
**EDIT - I thought I had it working, apparently not. Disregard my instructions.

S
Sergej author 3/23/2012



It looks like you might have things out of order from what I can tell and what you have posted.
The way I have gotten mine to work is like such:
In the Login Page after succesful login:
<code>

global $conn;

$str = "select * from dbo.table_ugmembers where UserName='".$username."'";

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

$data1 = db_fetch_array($result);

$_SESSION['Group'] = $data1['GroupID'];

</code>
Then on the list page of your choice List page:After record processed use:
<code>

if ($_SESSION['Group']=-1)

{

$record["edit_link"] = true;

}

else

{

$record["edit_link"] = false;

}

</code>
**EDIT - I thought I had it working, apparently not. Disregard my instructions.



well it might seem like they are out of order but i managed to solve problem concerning group id and got it in session variable immediatelly

after succesful login and it works ok

$sql = ("SELECT GroupID FROM tci11_ugmembers WHERE UserName = '".$_SESSION["username"]."'");

$rs = CustomQuery($sql);

$data2 = db_fetch_array($rs);

$_SESSION["GroupPermiss"]=$data2["GroupID"];

$temp = $_SESSION["GroupPermiss"];

$sql2 = ("SELECT GroupPermiss FROM TCIUsers WHERE username = '".$_SESSION["username"]."'");

$rs2 = CustomQuery($sql2);

$data3 = db_fetch_array($rs2);

if (($data3["GroupPermiss"])!=$temp)

{

$sql3 =("update TCIUsers set GroupPermiss = $temp WHERE username='".$_SESSION["username"]."'");

db_exec($sql3, $conn);

}

i put the group id to the login table in Grouppermiss variable - even checking if the user changed the group in meantime ($temp) - so i could update the group permiss of the specific user....so the first part works - which means if group -1 (admin) all edit possible - don't know just how to leave edit for all other users only for their specific records

thnx anyway