Copyright (C) 2005 James Grant This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ?> << ".i18n("Back to Participant Registration Summary")."
"; echo "
"; $studentstatus=studentIndividualStatus($u['id']); if($studentstatus!="complete") { echo error(i18n("Please complete the Student Information Page first")); send_footer(); exit; } //output the current status $newstatus=emergencycontactStatus($u['registrations_id']); if($newstatus!="complete") { echo error(i18n("Emergency Contact Information Incomplete")); } else if($newstatus=="complete") { echo happy(i18n("Emergency Contact Information Complete")); } $registrations_id = $u['registrations_id']; $sq=mysql_query("SELECT id,firstname,lastname FROM users WHERE registrations_id='$registrations_id' AND conferences_id='".$conference['id']."'"); $numstudents=mysql_num_rows($sq); echo "
\n"; echo "\n"; while($sr=mysql_fetch_object($sq)) { $u = user_load($sr->id); echo "

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

"; foreach($u['emergencycontacts'] as $contact){ drawEmergencyContactForm($sr->id, $contact); } echo "
" . i18n("Add a new emergency contact") . "
"; drawEmergencyContactForm($sr->id); } echo "\n"; echo "
"; send_footer(); /***************** function definitions *****************/ // draw the form in which emergency contact data is populated/edited function drawEmergencyContactForm($userId, $contactInfo = null){ static $index = 0; $index++; $showDeleteBox = true; if($contactInfo == null){ // we'll use the same variables for drawing the form regardless, // just need to make sure they're defined $contactInfo = array( 'firstname' => '', 'lastname' => '', 'relation' => '', 'email' => '', 'phone1' => '', 'phone2' => '', 'phone3' => '', 'phone4' => '' ); $showDeleteBox = false; } echo ""; echo ""; echo "\n"; echo ""; echo " "; echo " "; echo "\n"; echo ""; echo " "; echo " "; echo "\n"; echo ""; echo " "; echo " "; echo "\n"; echo ""; echo " "; echo " "; echo "\n"; if($showDeleteBox){ echo ""; } echo "
".i18n("First Name").": ".REQUIREDFIELD."".i18n("Last Name").": ".REQUIREDFIELD."
".i18n("Relation").": "; echo " \n"; echo REQUIREDFIELD."".i18n("Email Address").":
".i18n("Phone 1").": ".REQUIREDFIELD."".i18n("Phone 2").":
".i18n("Phone 3").": ".i18n("Phone 4").":
"; echo "
"; } // save the posted contact info data function saveData(){ global $conference; $currentUser = user_load($_SESSION['users_id']); $registrations_id = $currentUser['registrations_id']; $newContacts = array(); foreach($_POST['ids'] as $postIndex){ if(substr($postIndex, 0, 4) == 'new_'){ // we're creating a new contact, and linking them to the user whose ID is in the contactId tag $userId = intval(substr($postIndex, 4)); }else if(is_numeric($postIndex)){ // we're updating an existing contact $userId = $_POST['userId'][$postIndex]; }else{ // invalid contact Id continue; } // let's make sure this user ID is a valid one and one which we can update with this post $query = "SELECT COUNT(*) AS tally FROM users WHERE id = $userId AND registrations_id='$registrations_id' AND conferences_id='{$conference['id']}'"; $row = mysql_fetch_assoc(mysql_query($query)); if($row['tally'] != 1){ // not a user whose contacts we're allowed to update continue; } // don't add contact info from an empty form $emptyFields = true; foreach(array('firstname', 'lastname', 'relation', 'email', 'phone1', 'phone2', 'phone3', 'phone4') as $idx){ if($_POST[$idx][$postIndex] != ''){ $emptyFields = false; break; } } if($emptyFields) continue; if(array_key_exists('delete', $_POST) && array_key_exists($postIndex, $_POST['delete'])){ if($_POST['delete'][$postIndex] == 'yes'){ continue; } } if(!array_key_exists($userId, $newContacts)){ $newContacts[$userId] = array(); } $newContacts[$userId][] = array( 'firstname' => mysql_real_escape_string($_POST['firstname'][$postIndex]), 'lastname' => mysql_real_escape_string($_POST['lastname'][$postIndex]), 'relation' => mysql_real_escape_string($_POST['relation'][$postIndex]), 'email' => mysql_real_escape_string($_POST['email'][$postIndex]), 'phone1' => mysql_real_escape_string($_POST['phone1'][$postIndex]), 'phone2' => mysql_real_escape_string($_POST['phone2'][$postIndex]), 'phone3' => mysql_real_escape_string($_POST['phone3'][$postIndex]), 'phone4' => mysql_real_escape_string($_POST['phone4'][$postIndex]) ); } // we've scraped together the new contact info, now let's update each of the users foreach($newContacts as $userId => $contactList){ $u = user_load($userId); $u['emergencycontacts'] = $contactList; user_save($u); } } ?>