I am creating a file sharing web application. When a user edits an existing file -- by clicking the edit link for the file on the "directory view" page (which displays a list of all files in that "directory) -- the file's checkout value is changed from '0' to '1' to indicate that it has been checked out. This means that other users that visit the "directory view" page will not be given the option to edit that file.
Here's the problem. If the user editing the file finishes editing by clicking the "submit" button (or clicks the "return to directory view" button), the flag will be reset so that the file is checked back in (and available for others to edit). But if instead the user (a) clicks the browser's back button or (b) closes the browser window entirely, the file never get's checked back in.
For situation (a), is there a way to "intercept" the browser back command so that the file is checked back in? I.e., when the user clicks the back button, the page runs the "check the file back in" php script before returning the user to the directory view page.
For situation (b), is there a generally accepted method for such situations? For instance, I might place a time limit on checked out files so that after a file is checked out, it is automatically checked back in after 30 minutes or so?
Thanks.