Jump to content


Photo

Record Locking


  • Please log in to reply
5 replies to this topic

#1 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 18 April 2006 - 03:15 PM

Just looking for ideas on this. Trying to stick with php/MySQL only for a solution. (Running XAMPP - PHP 5.0.5 and mySQL 2.6.4)

I need to come up with a way to lock a record when a user has it opened in "Edit" mode. I have lists of records which, when displayed, offer the user a "View" or "Edit" link for that record.

I was thinking I should have a field for each record called "locked" and if a user selects "Edit" then that record gets flagged with "Y" (meaning locked). If someone else where to then try and "Edit" the same record it would kick back a message telling them it was currently being edited (I can do this, no worries there.)

But, if the original user that locked it, were to navigate away (intentional or accidental) and not submit their changes then how would I get the record to flag back to "N" (meaning unlocked)?

I need to try and also have this work if they were to close their browser accidently and say needed to get right back into the same record to "Edit" still.


#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 18 April 2006 - 03:22 PM

use an "is_locked" field.

When the edit page is opened, have an update query run and set is_locked to time()
When the edit is completed, have the update query run and set is_locked to nothing ... ie ""

If the timespan for the file to be edited has elapsed, which for example could be 5 minutes... just allow it to be edited.

Something like;

<?php
$time_now = time();
$allowed_time = $time_now-300;
if($is_locked<$allowed_time) { echo "Editing is allowed"}

Obviously this would need fleshing out, but you get the idea.
wisewood: proven fact, I am both wise, and wooden.

#3 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 18 April 2006 - 03:28 PM

[!--quoteo(post=366040:date=Apr 18 2006, 11:22 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 18 2006, 11:22 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
use an "is_locked" field.

When the edit page is opened, have an update query run and set is_locked to time()
When the edit is completed, have the update query run and set is_locked to nothing ... ie ""

If the timespan for the file to be edited has elapsed, which for example could be 5 minutes... just allow it to be edited.

Something like;

<?php
$time_now = time();
$allowed_time = $time_now-300;
if($is_locked<$allowed_time) { echo "Editing is allowed"}

Obviously this would need fleshing out, but you get the idea.
[/quote]


Very cool, will give that a go. That would appear to work no matter the misnavigation or accidental browser closing. The user would just have to wait the specified time to update that record if they goofed.

Thanks for the quick response!

#4 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 18 April 2006 - 03:35 PM

You could even set the "This can't be edited" message to incorporate the time when they will be able to edit it... ie

"You cannot edit this record until 16:38"

If you wanted to be really cocky you could let them be notified when the record became available for editing, and if multiple people are waiting to edit the record, have them held in a queue lol
wisewood: proven fact, I am both wise, and wooden.

#5 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 18 April 2006 - 03:54 PM

[!--quoteo(post=366047:date=Apr 18 2006, 11:35 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 18 2006, 11:35 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You could even set the "This can't be edited" message to incorporate the time when they will be able to edit it... ie

"You cannot edit this record until 16:38"

If you wanted to be really cocky you could let them be notified when the record became available for editing, and if multiple people are waiting to edit the record, have them held in a queue lol
[/quote]


LOL! Well I think the "you cannot edit until..." message is a really good idea to use. I don't think we are going to run into a problem where they need to be notified, but a great suggestion.

And yeah...I might just do that just be "really cocky" about it...haha!

#6 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 18 April 2006 - 03:58 PM

During the development on the system i am working on for client management here, there have been loads of instances of me thinking "we don't really need this, but for my own amusement i will add it anyway" and then a few days later, while working on something completely unrelated the code has been really useful.

It's quite good to make things as indepth as possible sometimes, because you never know how things will pan out. In 6 months time it'd be easier to be able to just "turn on" some code that's already in place, than to have to try and bolt on something to do the job later.

This has actually given me an idea for something i am working on... thanks for that lol.
wisewood: proven fact, I am both wise, and wooden.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users