This topic is locked

Prevent edit after a specific interval

10/4/2008 3:53:02 PM
PHPRunner General questions
J
jbartc author

I would like to prevent users from editing records after a certain interval has elapsed since the record was created, 1 month for example. I already have fields that automatically store the date when a record is created and when it is edited. I believe that what I need to do is compare the stored date with the current date and "return false" if the allowed edit interval is exceeded. What I am having difficulty with is determining how compare dates in PHP. From what I can tell, there is no PHP equivalent to the "DateDiff" function. I imagine that I am overlooking somehting quite simple. Any assistance would be appreciated.

T
thesofa 10/6/2008

OK, you have been waiting a while so I have dug out what I recall of posts about time, try here where you will find links to other posts about time

J
jbartc author 11/8/2008

I would like to prevent users from editing records after a certain interval has elapsed since the record was created, 1 month for example. I already have fields that automatically store the date when a record is created and when it is edited. I believe that what I need to do is compare the stored date with the current date and "return false" if the allowed edit interval is exceeded. What I am having difficulty with is determining how compare dates in PHP. From what I can tell, there is no PHP equivalent to the "DateDiff" function. I imagine that I am overlooking somehting quite simple. Any assistance would be appreciated.


For the benefit of anyone else who may find the information useful, I developed a solution to the problem above. It is very simple, actually. Here is the relevant code that is in the BeforeRecordUpdated function:

****

****

$n_start_date=$oldvalues["SystemDate"]; //SystemDate is a DateTime field that is automatically populated using the Now() function when the record is created

$n_pres_date=Now();
$nowdate = strtotime($n_pres_date);

$thendate = strtotime($n_start_date);
$datediff = ($nowdate - $thendate);
//if the record is more than 30 days old prevent the changes

if (round($datediff / 86400) > 30)

{

echo "<script language=\"JavaScript\">\n";

echo "alert('WARNING - THIS RECORD IS TOO OLD TO EDIT - Your changes were NOT recorded!');\n";

echo "</script>";

return false;

}
... //unrelated code here
return true;

****

****
This has worked well for what I needed.