This topic is locked
[SOLVED]

 Importing records from excel and inserting into DB for the logged in user only

1/24/2018 9:25:57 AM
PHPRunner General questions
M
myherds author

OK guys this is my first post and I'm having a little difficulty.
I have the security settings such that each user can only see and modify the data they input. That works. I have a field UID in each table with relationships between them.
The excel import function does not follow this protocol such that importing data from any user account has a default UID of 0.
I cannot allow users to specify a UID in the excel file for they will screw it up and push records into the wrong account or leave it blank pushing the data with again a UID of 0.
I therefore need getOwnerId or currentuser type functionality such that when the excel is inserted it goes in with the current logged in user's UID which is not in the excel file.
I have tried putting in code in beforeinsert in the Import function but I just can't seem to get anything that sets the UID for import correctly.
I don't see any postings anywhere either.
Does anyone have samples of what they've done for this?

Sergey Kornilov admin 1/24/2018
M
myherds author 1/24/2018



Sure, check this:

https://xlinesoft.com/phprunner/docs/secapi_get_ownerid.htm


Well even more baseline I tried hardcoding a value to see if import would insert data into fixed account.
uid is a field in the users table and the import area with a relationship between them (the table I am importing into).
I put this in beforeinsert in an attempt to FORCE the data to the user with uid = 7.

Doesn't work
I have code in Add and Edit areas using this method and it all works fine. But not on importing.
$values['uid']='7';

romaldus 1/25/2018

In after successfully login event:



//get userid value from user login table

$_SESSION['uid'] = $data['UserId'];


And than in import page, before record inserted event:



$values['uid'] = $_SESSION['uid'];
M
myherds author 1/25/2018



In after successfully login event:



//get userid value from user login table

$_SESSION['uid'] = $data['UserId'];


And than in import page, before record inserted event:



$values['uid'] = $_SESSION['uid'];



Thanks romaldus.
Same problem persists though. Records get inserted with a null uid and not the session derived uid.
Also, explicitly setting $values['uid'] = '7'; before insert gives the same results even without trying to get a session value. Again, I can add and edit records with correct results when using this method but import from excel does not.
One would think hardcoding the uid beforeinsert would put those records in the right place in the db just as it does in add and edit modes.
This is dumped from the list view so I know the uid is set to 7 for this test on this user logged in.
uid Status Tag # Tag Color

7 Active 66666 Black

7 Active 1000 Black
Here is the code in BeforeInsert
$values['uid'] = 7;

print_r($values['uid']); //show me what the uid is set to during inserting
Now, the records do not get inserted for uid 7 but rather null uid.

However the printf function shows that uid is in fact set to 7.
I am at a loss on this.