This topic is locked

group field - automatically enter

7/24/2006 9:44:09 PM
PHPRunner General questions
P
phpwalker author

I am using group level security... When editing or adding new records, I would like the signed in users group to automatically enter in the table they are working on... (and then I would like this field to be read-only (not change-able by the user))...
is there a way to do this?
Karen <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=3055&image=1&table=forumtopics' class='bbc_emoticon' alt=':huh:' />

J
Jane 7/25/2006

Karen,
you can automatically populate some fields using events. Please give me more detailed description of what you want to achieve and I'll help you.
To make field as readonly select Readonly in the Edit as dropdown box on the Formatting tab.

P
phpwalker author 7/25/2006

I have a user table:
user.username

user.password

user.group
I have a table of voter issues with a master table of voters. I "get to" the voter issues table by clicking on the link from the voters list (much like you would get to order details from an order table).
The voter table and voter issues table both contain a field called group. When a user logs in, that user can only view/edit/add records where the group field = user.group. So I use "user name and password" from table for security.
When I login as a user who belongs to the group "EB"... go to the voter list... click on voter issues... and add a new voter issue, I currently see the field voterIssue.group as being blank (editable)... I would like this field to automatically be populated with the logged in user's group... in this case "EB" and do not want the user to have to enter this or be able to edit this.
I hope this makes sense.
thanks for your help,

karen

J
Jane 7/25/2006

Karen,
here is event code:

function BeforeLogin($username, $password)

{

global $conn;

$strSQL = "select * from users where UserName='".$username."'";

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

$data=db_fetch_array($rs);

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

return true;

}



And then use $_SESSION["group"] as default value on the Edit format dialog on the Formatting tab.

P
phpwalker author 7/25/2006

per instructions - I copied and pasted above code into Global --> Before Log in and now I receive the following error when going to main menu:
Parse error: parse error, unexpected T_RETURN in /home/ccdem2/public_html/test/include/events.php on line 25
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10017&image=1&table=forumreplies' class='bbc_emoticon' alt=':blink:' />

P
phpwalker author 7/25/2006

sorry --- id10t error
I had the function line twice (my copied version and the version that is created when you hit the add action button...
(blush)