This topic is locked

Record locking

7/2/2009 6:02:41 AM
PHPRunner General questions
M
mauro author

PHPRunner 5.1 Build 2370
in Edit page: Before Display

*

global $strWhereClause,$conn;
$rs = CustomQuery("select IsLocked, LockTime, user
from ticket where ".$strWhereClause);
$datatmp = db_fetch_array($rs);
if ($datatmp["IsLocked"]==1 &&
(strtotime("now")-strtotime($datatmp["LockTime"]))/60<20)
{
echo "<script>alert(\"Questo Ticket è in uso da \");window.location.href='ticket_ict_list.php?a=return';

</script>";
exit();
}
else
{
//lock record here
$str = "update ticket set IsLocked=1, LockTime=now(),
user='".$_SESSION["UserID"]."' where ".$strWhereClause;
db_exec($str,$conn);
}
and it's ok IsLocked field is set 1
in Before record update

***

global $conn;
$strUpdate = "update ticket set IsLocked=0, LockTime=NOW() where ".$where;
db_exec($strUpdate,$conn);
IsLocked not se to 0

J
Jane 7/2/2009

Hi,
I recommend you to publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

M
mauro author 7/6/2009

Where is demo account in build 5.1 2370?

J
Jane 7/6/2009

Hi,
you need to add After record updated event on the Eventstab.

Here is a sample:

header("Location: ticket_ict_list.php?a=return");

exit();

M
mauro author 7/7/2009

Hi,

you need to add After record updated event on the Eventstab.

Here is a sample:


Now its' ok....but in my opinion this event can be better......i'd like to lock record only to other users, if i modify a record and return to list without any change i can no more modify record, so ...its' possible add another condition, for example record is locked (Editpage.before display) only for other user and not for current user ???
global $strTableName,$strWhereClause,$conn;

$rs = CustomQuery("select IsLocked, LockTime, user

from ticket where ".$strWhereClause);

$datatmp = db_fetch_array($rs);

if ($datatmp["IsLocked"]==1 &&

(strtotime("now")-strtotime($datatmp["LockTime"]))/60<20)

{

echo "<script>alert(\"Locked from $datatmp[user]\");window.location.href='ticket_ict_list.php?a=return';</script>";

exit();

}
------------

global $strTableName,$strWhereClause,$conn;

$rs = CustomQuery("select IsLocked, LockTime, user

from ticket where ".$strWhereClause);

$datatmp = db_fetch_array($rs);

if ($datatmp["IsLocked"]==1 &&

==1 &&

(strtotime("now")-strtotime($datatmp["LockTime"]))/60<20)

{

echo "<script>alert(\"Locked from $datatmp[user]\");window.location.href='ticket_ict_list.php?a=return';</script>";

exit();

}

J
Jane 7/7/2009

Hi,
here is just a sample:

if ($datatmp["IsLocked"]==1 && $datatmp["user"]!=$_SESSION["UserID"] && (strtotime("now")-strtotime($datatmp["LockTime"]))/60<20)

M
mauro author 7/7/2009

Hi,

here is just a sample:


Ok it's perfect <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=42544&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />

it's possible also to set Locked filed to 0 aven if user don't save record, for example when user "back to list" without any modify

Now in "Before record updated" i have
global $conn;

$strUpdate = "update ticket set IsLocked=0, LockTime=NOW() where ".$where;

db_exec($strUpdate,$conn);
i'd like insert also when user click on "back to list" button

J
Jane 7/8/2009

Hi,
in general you need to pass record ID in the Back To List link (tablename_list.php?a=return&recordid=1) and then update this record in the List page: Before process event.