[PHP] Locking and unlocking records

2004-01-15 Thread Lowell Allen
I need to implement database record locking and unlocking. I want to prevent
multiple users of a content management system from editing the same record
simultaneously, which can result in one user's edits being overwritten. I
can use PHP to lock a record when it's opened, and unlock it when it's
updated or if the user goes anywhere else within the content management
system (or logs out), but I need to account for a user leaving the CMS
directly from the edit screen. I'm not aware of any way to do that other
than using a Javascript onunload event to open a new window, run a PHP
script, and close the new window onload -- very nasty and unreliable with
pop-up blocking so popular. Can anyone suggest an all-PHP way?

TIA

--
Lowell Allen

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Locking and unlocking records

2004-01-15 Thread Jason Wong
On Friday 16 January 2004 04:49, Lowell Allen wrote:
 I need to implement database record locking and unlocking. I want to
 prevent multiple users of a content management system from editing the same
 record simultaneously, which can result in one user's edits being
 overwritten. I can use PHP to lock a record when it's opened, and unlock it
 when it's updated or if the user goes anywhere else within the content
 management system (or logs out), but I need to account for a user leaving
 the CMS directly from the edit screen. I'm not aware of any way to do that
 other than using a Javascript onunload event to open a new window, run a
 PHP script, and close the new window onload -- very nasty and unreliable
 with pop-up blocking so popular. Can anyone suggest an all-PHP way?

There is no way to determine whether/when a user 'leaves' the edit screen. The 
best you can do is to set a timeout on the locked record. So if the person 
who locked the record hasn't done anything to it for the last 10 minutes (or 
whatever) then unlock the record.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
A psychiatrist is a fellow who asks you a lot of expensive questions
your wife asks you for nothing.
-- Joey Adams
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Locking and unlocking records

2004-01-15 Thread Williams, Olwen - SAL
One way to do this is to keep a copy of the old record in a session
variable.  When you com to write the data back read the record again and see
if it is still the same.  If it is you can save the changes, otherwise give
an error saying that the data has been changed, and probably refuse to do
the update.  You might like to concoct a friendlier failure than this.  

Olwen Williams
[EMAIL PROTECTED]


-Original Message-
From: Jason Wong [mailto:[EMAIL PROTECTED]
Sent: Friday, January 16, 2004 12:05 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Locking and unlocking records


On Friday 16 January 2004 04:49, Lowell Allen wrote:
 I need to implement database record locking and unlocking. I want to
 prevent multiple users of a content management system from editing the
same
 record simultaneously, which can result in one user's edits being
 overwritten. I can use PHP to lock a record when it's opened, and unlock
it
 when it's updated or if the user goes anywhere else within the content
 management system (or logs out), but I need to account for a user leaving
 the CMS directly from the edit screen. I'm not aware of any way to do that
 other than using a Javascript onunload event to open a new window, run a
 PHP script, and close the new window onload -- very nasty and unreliable
 with pop-up blocking so popular. Can anyone suggest an all-PHP way?

There is no way to determine whether/when a user 'leaves' the edit screen.
The 
best you can do is to set a timeout on the locked record. So if the person 
who locked the record hasn't done anything to it for the last 10 minutes (or

whatever) then unlock the record.

-- 


CAUTION - This message may contain privileged and confidential 
information intended only for the use of the addressee named above.
If you are not the intended recipient of this message you are hereby 
notified that any use, dissemination, distribution or reproduction 
of this message is prohibited. If you have received this message in 
error please notify Safe Air Ltd immediately. Any views expressed 
in this message are those of the individual sender and may not 
necessarily reflect the views of Safe Air.
_
For more information on the Safe Air Group, visit us online
at http://www.safeair.co.nz/ 
_

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php