forked from science-ation/science-ation
205 lines
7.7 KiB
PHP
205 lines
7.7 KiB
PHP
<?
|
|
/*
|
|
This file is part of the 'Science Fair In A Box' project
|
|
SFIAB Website: http://www.sfiab.ca
|
|
|
|
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
|
Copyright (C) 2005 James Grant <james@lightbox.org>
|
|
|
|
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.
|
|
*/
|
|
?>
|
|
<?
|
|
require("common.inc.php");
|
|
require_once("register_participants.inc.php");
|
|
require_once("user.inc.php");
|
|
|
|
user_auth_required("participant");
|
|
$u=user_load($_SESSION['users_id']);
|
|
|
|
if(array_key_exists('action', $_POST)){
|
|
switch($_POST['action']){
|
|
case 'save':
|
|
saveData();
|
|
break;
|
|
}
|
|
}
|
|
|
|
send_header("Participant Registration - Emergency Contact Information");
|
|
|
|
echo "<a href=\"register_participants_main.php\"><< ".i18n("Back to Participant Registration Summary")."</a><br />";
|
|
echo "<br />";
|
|
|
|
$studentstatus=studentIndividualStatus($u['id']);
|
|
if($studentstatus!="complete") {
|
|
echo error(i18n("Please complete the <a href=\"user_edit.php?tab=personal\">Student Information Page</a> 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 "<form name=\"emergencycontactform\" method=\"post\" action=\"register_participants_emergencycontact.php\">\n";
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
|
|
|
|
while($sr=mysql_fetch_object($sq))
|
|
{
|
|
$u = user_load($sr->id);
|
|
echo "<h3>".i18n("Emergency Contact for %1 %2",array($sr->firstname,$sr->lastname))."</h3>";
|
|
foreach($u['emergencycontacts'] as $contact){
|
|
drawEmergencyContactForm($sr->id, $contact);
|
|
}
|
|
echo "<h5>" . i18n("Add a new emergency contact") . "</h5>";
|
|
drawEmergencyContactForm($sr->id);
|
|
}
|
|
echo "<input type=\"submit\" value=\"".i18n("Save Emergency Contact Information")."\" />\n";
|
|
echo "</form>";
|
|
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 "<input type=\"hidden\" name=\"ids[]\" value=\"$index\">";
|
|
echo "<input type=\"hidden\" name=\"userId[$index]\" value=\"$userId\">";
|
|
echo "<table>\n";
|
|
echo "<tr>";
|
|
echo " <td>".i18n("First Name").": </td><td><input type=\"text\" name=\"firstname[$index]\" size=\"20\" value=\"{$contactInfo['firstname']}\" />".REQUIREDFIELD."</td>";
|
|
echo " <td>".i18n("Last Name").": </td><td><input type=\"text\" name=\"lastname[$index]\" size=\"20\" value=\"{$contactInfo['lastname']}\" />".REQUIREDFIELD."</td>";
|
|
echo "</tr>\n";
|
|
echo "<tr>";
|
|
echo " <td>".i18n("Relation").": </td><td>";
|
|
echo " <select name=\"relation[$index]\">\n";
|
|
echo " <option value=\"\">".i18n("Choose a relation")."</option>\n";
|
|
$relations=array("Parent","Legal Guardian","Grandparent","Family Friend", "Other");
|
|
foreach($relations AS $rel) {
|
|
if($contactInfo['relation'] == $rel) $sel="selected=\"selected\"";
|
|
else $sel="";
|
|
echo "<option $sel value=\"$rel\">".i18n($rel)."</option>\n";
|
|
}
|
|
echo " </select>\n";
|
|
echo REQUIREDFIELD."</td>";
|
|
echo " <td>".i18n("Email Address").": </td><td><input type=\"text\" name=\"email[$index]\" size=\"20\" value=\"{$contactInfo['email']}\" /></td>";
|
|
echo "</tr>\n";
|
|
echo "<tr>";
|
|
echo " <td>".i18n("Phone 1").": </td><td><input type=\"text\" name=\"phone1[$index]\" size=\"20\" value=\"{$contactInfo['phone1']}\" />".REQUIREDFIELD."</td>";
|
|
echo " <td>".i18n("Phone 2").": </td><td><input type=\"text\" name=\"phone2[$index]\" size=\"20\" value=\"{$contactInfo['phone2']}\" /></td>";
|
|
echo "</tr>\n";
|
|
echo "<tr>";
|
|
echo " <td>".i18n("Phone 3").": </td><td><input type=\"text\" name=\"phone3[$index]\" size=\"20\" value=\"{$contactInfo['phone3']}\" /></td>";
|
|
echo " <td>".i18n("Phone 4").": </td><td><input type=\"text\" name=\"phone4[$index]\" size=\"20\" value=\"{$contactInfo['phone4']}\" /></td>";
|
|
echo "</tr>\n";
|
|
if($showDeleteBox){
|
|
echo "<tr><td colspan = 2><label>" . i18n("Remove this contact") . " <input type=\"checkbox\" name=\"delete[$index]\" value=\"yes\"></label></td></tr>";
|
|
}
|
|
echo "</table>";
|
|
echo "<br />";
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
?>
|