From 2b65a6223983dd74dced7502deda0c0482ade269 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 5 Jan 2005 15:34:25 +0000 Subject: [PATCH] Implementation for emergency contacts remove emergency contact for a student if the student is removed (keep db clean) --- register_participants_emergencycontact.php | 142 +++++++++++++++++++++ register_participants_students.php | 8 ++ 2 files changed, 150 insertions(+) create mode 100644 register_participants_emergencycontact.php diff --git a/register_participants_emergencycontact.php b/register_participants_emergencycontact.php new file mode 100644 index 0000000..f89c48f --- /dev/null +++ b/register_participants_emergencycontact.php @@ -0,0 +1,142 @@ +<< ".i18n("Back to Participant Registration Summary")."
"; + echo "
"; + + $studentstatus=studentStatus(); + if($studentstatus!="complete") + { + echo error(i18n("Please complete the Student Information Page first")); + send_footer(); + exit; + } + + + if($_POST['action']=="save") + { + //first, lets make sure this emergency contact really does belong to them + foreach($_POST['ids'] AS $id) + { + $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) + { + mysql_query("UPDATE emergencycontact SET ". + "firstname='".mysql_escape_string(stripslashes($_POST['firstname'][$id]))."', ". + "lastname='".mysql_escape_string(stripslashes($_POST['lastname'][$id]))."', ". + "relation='".mysql_escape_string(stripslashes($_POST['relation'][$id]))."', ". + "phone1='".mysql_escape_string(stripslashes($_POST['phone1'][$id]))."', ". + "phone2='".mysql_escape_string(stripslashes($_POST['phone2'][$id]))."', ". + "phone3='".mysql_escape_string(stripslashes($_POST['phone3'][$id]))."', ". + "phone4='".mysql_escape_string(stripslashes($_POST['phone4'][$id]))."', ". + "email='".mysql_escape_string(stripslashes($_POST['email'][$id]))."' ". + "WHERE id='$id'"); + echo mysql_error(); + echo notice(i18n("Emergency contact information successfully updated")); + } + else + { + echo error(i18n("Invalid emergency contact to update (%1)"),array($id)); + } + } + } + + + +//output the current status +$newstatus=emergencycontactStatus(); +if($newstatus!="complete") +{ + echo error(i18n("Emergency Contact Information Incomplete")); +} +else if($newstatus=="complete") +{ + echo happy(i18n("Emergency Contact Information Complete")); + +} + +$sq=mysql_query("SELECT id,firstname,lastname FROM students WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); +$numstudents=mysql_num_rows($sq); + +echo "
\n"; +echo "\n"; + +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'"); + + if(mysql_num_rows($q)==0) + { + mysql_query("INSERT INTO emergencycontact (registrations_id,students_id,year) VALUES ('".$_SESSION['registration_id']."','".$sr->id."','".$config['FAIRYEAR']."')"); + $id=mysql_insert_id(); + unset($r); + } + else + { + $r=mysql_fetch_object($q); + $id=$r->id; + } + + echo "

".i18n("Emergency Contact for %1 %2",array($sr->firstname,$sr->lastname))."

"; + echo ""; + echo "\n"; + echo ""; + echo " "; + echo " "; + echo "\n"; + echo ""; + echo " "; + echo " "; + echo "\n"; + echo ""; + echo " "; + echo " "; + echo "\n"; + echo ""; + echo " "; + echo " "; + echo "\n"; + echo "
".i18n("First Name").": firstname\" />".i18n("Last Name").": lastname\" />
".i18n("Relation").": relation\" />".i18n("Email Address").": email\" />
".i18n("Phone 1").": phone1\" />".i18n("Phone 2").": phone2\" />
".i18n("Phone 3").": phone3\" />".i18n("Phone 4").": phone4\" />
"; + echo "
"; + echo "
"; + + } + echo "\n"; + echo "
"; + + + send_footer(); +?> diff --git a/register_participants_students.php b/register_participants_students.php index 5640a74..fae1f55 100644 --- a/register_participants_students.php +++ b/register_participants_students.php @@ -109,6 +109,14 @@ if($_GET['action']=="removestudent") if(mysql_num_rows($q)==1) { mysql_query("DELETE FROM students WHERE id='".$_GET['removestudent']."' AND registrations_id='".$_SESSION['registration_id']."'"); + + //now see if they have an emergency contact that also needs to be removed + + $q=mysql_query("SELECT id FROM emergencycontact WHERE students_id='".$_GET['removestudent']."' AND registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); + //no need to error message if this doesnt exist + if(mysql_num_rows($q)==1) + mysql_query("DELETE FROM emergencycontact WHERE students_id='".$_GET['removestudent']."' AND registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); + echo notice(i18n("Student successfully removed")); } else