|
|
To implement record locking (when a record is locked while
editing):
1. Add three additional fields IsLocked (Yes/No field), LockTime (Datetime field) and
UserField (username field
) to the database table.
2. Add the following code to the Edit page: Before display event. In the
example below, timeout is set to 20 minutes.
Note: Change the values listed in
red to match your specific needs.
global $strTableName,$strWhereClause,$conn;
$rs = CustomQuery("select IsLocked, LockTime, UserField
from ".$strTableName." where ".$strWhereClause);
$datatmp = db_fetch_array($rs);
if ($datatmp["IsLocked"]==1 &&
(strtotime("now")-strtotime($datatmp["LockTime"]))/60<20)
{
echo "<script>alert(\"This record is in use by <?php echo
$datatmp["UserField"]?>\")</script>";
exit();
}
else
{
//lock record here
$str = "update ".$strTableName." set IsLocked=1, LockTime=CURDATE(),
UserField='".$_SESSION["UserID"]."' where ".$strWhereClause;
db_exec($str,$conn);
}
|
To unlock a record use the following code in the Edit
page: Before record updated event:
global $conn,$strTableName;
$strUpdate = "update ".$strTableName." set IsLocked=0, LockTime=NOW() where ".$where;
db_exec($strUpdate,$conn);
return true;
|
|