This topic is locked

Using logged in user's name and IDNumber

8/20/2006 11:01:35 AM
PHPRunner General questions
T
thesofa author

Hi, I have another problem with this B****y database I am trying to build

My apologies if this is the same question as my other post here.
Here are the table structures
CREATE TABLE `staff` (

`userid` int(11) NOT NULL auto_increment,

`pcs_ac` varchar(15) default NULL,

`firstname` varchar(30) default NULL,

`lastname` varchar(30) default NULL,

`level` int(11) default NULL,

`Responsibility` int(11) default NULL,

`Department` varchar(50) default NULL,

PRIMARY KEY (`userid`),

KEY `id` (`userid`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `detentions` (

`ID` int(11) NOT NULL auto_increment,

`DateGiven` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

`TimeGiven` datetime default NULL,

`detainee` int(11) NOT NULL,

`donor` int(11) default NULL,

`TutorGroup` varchar(3) default NULL,

`DayForDetention` datetime NOT NULL,

`sess` int(11) NOT NULL,

`Lunchtime` varchar(1) default NULL,

`Done` tinyint(4) default NULL,

`reason` int(11) default NULL,

`Origin` int(11) default NULL,

`MoveToDept` datetime default NULL,

`DeptHead` int(11) default NULL,

`ReasonForDept` int(11) default NULL,

`OriginalDate` datetime default NULL,

`DoneAtDept` tinyint(4) default NULL,

`MovedToAfterSchool` datetime default NULL,

PRIMARY KEY (`detainee`,`DayForDetention`,`sess`),

UNIQUE KEY `ID` (`ID`),

KEY `Lunchtime` (`Lunchtime`),

KEY `To` (`detainee`),

KEY `TutorGroup` (`TutorGroup`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
As a temp measure while I am developing the application, i have used the staff table to act as the login table, so the login name is stored in`pcs_ac`. Just to keep things easy for testing, I have set the password field for the login screen to be equal to the `lastname` field. Once the system is up and tested, I shall get the login to use LDAP and get the user privelidges from the staff table.

The Link between the detentions table and the staff table is from `userid` in the staff table and `donor` in the detentions table.
In the Add Record form, I have the value of the `donor` set to "@$_SESSION["OwnerID"]". This gives me the login name of the staff member, I need the userID of that staff member to store in the detentions table,

How do I do this?

J
Jane 8/21/2006

Hi,
you can do it using events.

Proceed to the Events tab, select AddOnLoad event and put your code in it.

Here is a sample:

function AddOnLoad()

{

global $conn;

$str = "select * from `staff` where `pcs_ac`='".$_SESSION["OwnerID"]."'";

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

$data = db_fetch_array($rs);

$_SESSION["id"] = $data["userid"];

}



And then use $_SESSION["id"] as default value for donor field on the Edit format dialog on the Formatting tab.

T
thesofa author 8/21/2006

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10553&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

Many thanks, that worked a treat, even tho I haven't a clue how it works.

T
thesofa author 12/28/2006

Hi,

you can do it using events.

Proceed to the Events tab, select AddOnLoad event and put your code in it.

Here is a sample:
And then use $_SESSION["id"] as default value for donor field on the Edit format dialog on the Formatting tab.



Hi, It's the pest again here

Will this code be the same for use in version 3.11?

Also I was intending to put the code in the function AfterSuccessfulLogin() on the login page, as I should then be able to use the session variable all through the application.

Happy New Year to you all.

Sergey Kornilov admin 12/28/2006

Yes, this should work in PHPRunner 3.1.1 as well.

Just make sure security settings are the same.

$_SESSION["OwnerID"] is only populated when you use one of Advanced Security methods where users see or edit their own data.