Create and maintain parent records for emergency contacts that are parents

This commit is contained in:
james 2009-10-22 19:22:53 +00:00
parent c4f5ed2ab7
commit 10fa7919c4

View File

@ -24,6 +24,7 @@
<? <?
require("common.inc.php"); require("common.inc.php");
include "register_participants.inc.php"; include "register_participants.inc.php";
include "user.inc.php";
//authenticate based on email address and registration number from the SESSION //authenticate based on email address and registration number from the SESSION
if(!$_SESSION['email']) if(!$_SESSION['email'])
@ -71,22 +72,37 @@ echo mysql_error();
if($_POST['action']=="save") if($_POST['action']=="save")
{ {
if(registrationFormsReceived()) if(registrationFormsReceived()) {
{
echo error(i18n("Cannot make changes to forms once they have been received by the fair")); echo error(i18n("Cannot make changes to forms once they have been received by the fair"));
} }
else if(registrationDeadlinePassed()) else if(registrationDeadlinePassed()) {
{
echo error(i18n("Cannot make changes to forms after registration deadline")); echo error(i18n("Cannot make changes to forms after registration deadline"));
} }
else else {
{
//first, lets make sure this emergency contact really does belong to them //first, lets make sure this emergency contact really does belong to them
foreach($_POST['ids'] AS $id) foreach($_POST['ids'] AS $id)
{ { $q=mysql_query("SELECT * FROM emergencycontact WHERE id='$id' AND registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
$q=mysql_query("SELECT * FROM emergencycontact WHERE id='$id' AND registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); if(mysql_num_rows($q)==1) {
if(mysql_num_rows($q)==1) $e=stripslashes($_POST['email']);
{ if($_POST['relation']=="Parent" && $e && user_valid_email($e)) {
if($u=user_load_by_username($e)) {
$u['firstname']=stripslashes($_POST['firstname'][$id]);
$u['lastname']=stripslashes($_POST['lastname'][$id]);
$u['phone']=stripslashes($_POST['phone1'][$id]);
$u['email']=$e;
$u['types'][]="parent";
user_save($u);
}
else {
$u=user_create("parent",$e);
$u['firstname']=stripslashes($_POST['firstname'][$id]);
$u['lastname']=stripslashes($_POST['lastname'][$id]);
$u['phone']=stripslashes($_POST['phone1'][$id]);
$u['email']=$e;
user_save($u);
}
}
mysql_query("UPDATE emergencycontact SET ". mysql_query("UPDATE emergencycontact SET ".
"firstname='".mysql_escape_string(stripslashes($_POST['firstname'][$id]))."', ". "firstname='".mysql_escape_string(stripslashes($_POST['firstname'][$id]))."', ".
"lastname='".mysql_escape_string(stripslashes($_POST['lastname'][$id]))."', ". "lastname='".mysql_escape_string(stripslashes($_POST['lastname'][$id]))."', ".
@ -132,14 +148,12 @@ while($sr=mysql_fetch_object($sq))
{ {
$q=mysql_query("SELECT * FROM emergencycontact WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."' AND students_id='$sr->id'"); $q=mysql_query("SELECT * FROM emergencycontact WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."' AND students_id='$sr->id'");
if(mysql_num_rows($q)==0) if(mysql_num_rows($q)==0) {
{
mysql_query("INSERT INTO emergencycontact (registrations_id,students_id,year) VALUES ('".$_SESSION['registration_id']."','".$sr->id."','".$config['FAIRYEAR']."')"); mysql_query("INSERT INTO emergencycontact (registrations_id,students_id,year) VALUES ('".$_SESSION['registration_id']."','".$sr->id."','".$config['FAIRYEAR']."')");
$id=mysql_insert_id(); $id=mysql_insert_id();
unset($r); unset($r);
} }
else else {
{
$r=mysql_fetch_object($q); $r=mysql_fetch_object($q);
$id=$r->id; $id=$r->id;
} }