(Commit from Dave): Fix the logic for saving the school teacher. If the user

is teacher,judge, and they delete their account, the teacher save in the school
editor silently fails (id exists, but user_load returns false).  
Now it purges the teacher and creates a new one.  The downside, is the teacher
can remove their contact info without the committee knowing about it.  I guess
the real fix woudl be to either: Don't allow the account to be deleted if they
have a teacher,principal role, or duplicate the account on deletion to retain
the teacher contact info.
This commit is contained in:
james 2010-02-01 19:31:03 +00:00
parent 6261919878
commit 45864af4af

View File

@ -83,27 +83,37 @@
if($em == '' && ($first != '' || $last != '')) $em = "*$first$last".user_generate_password();
/* Load existing record, or create new if there's something
* to insert */
if($i['sciencehead_uid'] > 0)
$sh = false;
if($i['sciencehead_uid'] > 0) {
$sh = user_load_by_uid($i['sciencehead_uid']);
else if($em != '') {
/* It's possile for sh to be false now, happens when the user is
* deleted outside the school editor, this condition needs to be
* fixed. If we let it go, the saving the teacher info will
* silently fail. So let's just create a new teacher */
if(is_array($sh) && ($em != $sh['email'] || $em=='')) {
/* If the emails don't match we have no way of knowing if we're creating a different
* user, or doing a correction, assume it's a different user */
user_purge($sh, 'teacher');
$sh = false;
}
}
/* If there was no teacher loaded, or if we just purged it, create a new one
* if there's an email address */
if($sh == false && $em != '') {
$sh = user_create('teacher', $em);
$sciencehead_update = "sciencehead_uid='{$sh['uid']}',";
} else
$sh = false;
}
/* If we have a record, either delete it or update it */
/* If we have a record update it */
if(is_array($sh)) {
if($em == '') {
user_purge($sh, 'teacher');
$sciencehead_update = 'sciencehead_uid=NULL,';
} else {
$sh['firstname'] = $first;
$sh['lastname'] = $last;
$sh['phonework'] = $_POST['scienceheadphone'];
$sh['email'] = $em;
$sh['username'] = $em;
user_save($sh);
}
$sh['firstname'] = $first;
$sh['lastname'] = $last;
$sh['phonework'] = $_POST['scienceheadphone'];
$sh['email'] = $em;
$sh['username'] = $em;
user_save($sh);
}
$exec="UPDATE schools SET ".