Prevent editing based upon a date except for certain groups
Posted: 2013-01-31 02:23
Ok, a continuation of a series.
Look at my previous posts on this topic. This is just an addition. This addition lets you decide which groups will still be able to edit records. This is stage one of this hook. Next stage will show how to have it look up in a table to see which groups are approved to edit records etc. Then, how to do it based upon member name. The whole intent is to create a system where you do not need to admin it a lot or even at all by using tables to contain various features. A little more work up front but way way less down the road. The next one will show a few more tricks to make this more of a carefree system so it can be used year over year.
In this case I am just going to post the code. Should not need explanation but if you wish one just ask and I will flesh it out. (The new code is in red).
function clinic_reg_before_update(&$data, $memberInfo, &$args){
if($memberInfo['group']=='groupname' || $memberInfo['group']=='groupname'){
return TRUE;
}else{
// get the creation date of the record
$creationDate=sqlValue("select dateAdded from membership_userrecords
where tableName='yourtablename' and pkValue='{$data['selectedID']}'");
$lastchangedate=(strtotime("25 Feb 2013"));
// if the record is older than 180 days, deny changes
if($creationDate < strtotime('180 days ago')) return FALSE;
if(($lastchangedate - strtotime("now")) < 864000) return FALSE;
}
return TRUE;
}
Alan
Look at my previous posts on this topic. This is just an addition. This addition lets you decide which groups will still be able to edit records. This is stage one of this hook. Next stage will show how to have it look up in a table to see which groups are approved to edit records etc. Then, how to do it based upon member name. The whole intent is to create a system where you do not need to admin it a lot or even at all by using tables to contain various features. A little more work up front but way way less down the road. The next one will show a few more tricks to make this more of a carefree system so it can be used year over year.
In this case I am just going to post the code. Should not need explanation but if you wish one just ask and I will flesh it out. (The new code is in red).
function clinic_reg_before_update(&$data, $memberInfo, &$args){
if($memberInfo['group']=='groupname' || $memberInfo['group']=='groupname'){
return TRUE;
}else{
// get the creation date of the record
$creationDate=sqlValue("select dateAdded from membership_userrecords
where tableName='yourtablename' and pkValue='{$data['selectedID']}'");
$lastchangedate=(strtotime("25 Feb 2013"));
// if the record is older than 180 days, deny changes
if($creationDate < strtotime('180 days ago')) return FALSE;
if(($lastchangedate - strtotime("now")) < 864000) return FALSE;
}
return TRUE;
}
Alan