Copyright (C) 2005-2006 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. */ ?> prepare("SELECT * FROM projects WHERE registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}' AND fairs_id=$fairs_id"); $q->execute(); if($q->rowCount() != 1) { echo "permission denied."; exit; } /* Ok, they have permission */ } } switch($action) { case 'registration_load': registration_load(); exit; case 'registration_save': registration_save(); exit; case 'students_load': students_load(); exit; case 'students_save': students_save(); exit; case 'student_remove': $remove_id = intval($_GET['students_id']); $q=$pdo->prepare("SELECT id FROM students WHERE id='$remove_id' AND registrations_id='$registrations_id'"); $q->execute(); if($q->rowCount()!=1) { error_("Invalid student to remove"); exit; } if($q->rowCount()!=1) { error_("Invalid student to remove"); exit; } $stmt = $pdo->prepare("DELETE FROM students WHERE id='$remove_id' AND registrations_id='$registrations_id'"); $stmt->execute(); //now see if they have an emergency contact that also needs to be removed $q=$pdo->prepare("SELECT id FROM emergencycontact WHERE students_id='$remove_id' AND registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $q->execute(); //no need to error message if this doesnt exist if($q->rowCount()==1) $stmt = $do->prepare("DELETE FROM emergencycontact WHERE students_id='$remove_id' AND registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $stmt->execute(); if($q->rowCount()!=1) { error_("Invalid student to remove"); exit; } $stmt = $pdo->prepare("DELETE FROM students WHERE id='$remove_id' AND registrations_id='$registrations_id'"); $stmt->execute(); //now see if they have an emergency contact that also needs to be removed $q=$pdo->prepare("SELECT id FROM emergencycontact WHERE students_id='$remove_id' AND registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $q->execute(); //no need to error message if this doesnt exist if($q->rowCount()==1) $stmt = $do->prepare("DELETE FROM emergencycontact WHERE students_id='$remove_id' AND registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $stmt->execute(); $stmt = $pdo->prepare("DELETE FROM students WHERE id='$remove_id' AND registrations_id='$registrations_id'"); $stmt->execute(); //now see if they have an emergency contact that also needs to be removed $q=$pdo->prepare("SELECT id FROM emergencycontact WHERE students_id='$remove_id' AND registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $q->execute(); //no need to error message if this doesnt exist if($q->rowCount()==1) $stmt = $do->prepare("DELETE FROM emergencycontact WHERE students_id='$remove_id' AND registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $stmt->execute(); happy_("Student successfully removed"); exit; default: exit; } exit; //now do any data saves function students_save() { global $registrations_id, $config; $x=1; while($_POST["num"][$x]) { if($_POST['id'][$x]==0) { //if they use schoolpassword or singlepassword, then we need to set the school based on the school stored in the registration record. for anything else they can school the school on their own. if($config['participant_registration_type']=="schoolpassword" || $config['participant_registration_type']=="invite") { $q=$pdo->prepare("SELECT schools_id FROM registrations WHERE id='$registrations_id' AND YEAR='{$config['FAIRYEAR']}'"); $q->execute(); $r=$q->fetch(PDO::FETCH_OBJ); $schools_id=$r->schools_id; $schoolvalue="'$schools_id', "; } else { $schoolvalue="'".stripslashes($_POST['schools_id'][$x])."', "; } //INSERT new record $dob=$_POST['year'][$x]."-".$_POST['month'][$x]."-".$_POST['day'][$x]; $stmt -> prepare("INSERT INTO students (registrations_id,firstname,lastname,sex,email,address,city,province,postalcode,phone,dateofbirth,grade,schools_id,tshirt,medicalalert,foodreq,teachername,teacheremail,year) VALUES (". "'".$registrations_id."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['firstname'][$x]))."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['lastname'][$x]))."', ". "'".stripslashes($_POST['sex'][$x])."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['email'][$x]))."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['address'][$x]))."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['city'][$x]))."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['province'][$x]))."', ". "'".stripslashes($_POST['postalcode'][$x])."', ". "'".stripslashes($_POST['phone'][$x])."', ". "'$dob', ". "'".stripslashes($_POST['grade'][$x])."', ". $schoolvalue. "'".stripslashes($_POST['tshirt'][$x])."', ". "'".stripslashes($_POST['medicalalert'][$x])."', ". "'".stripslashes($_POST['foodreq'][$x])."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['teachername'][$x]))."', ". "'".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['teacheremail'][$x]))."', ". "'".$config['FAIRYEAR']."')"); happy_("%1 %2 successfully added",array($_POST['firstname'][$x],$_POST['lastname'][$x])); } else { //if they use schoolpassword or singlepassword, then we dont need to save teh schools_id because its already set when they inserted the record, and we dont allow them to change their school. if(( $config['participant_registration_type']=="schoolpassword" || $config['participant_registration_type']=="invite") && !$_POST['schools_id'][$x]) { $schoolquery=""; } else if($_POST['schools_id'][$x]) { $schoolquery="schools_id='".stripslashes($_POST['schools_id'][$x])."', "; } else $schoolquery=""; //UPDATE existing record $dob=$_POST['year'][$x]."-".$_POST['month'][$x]."-".$_POST['day'][$x]; $stmt = $pdo->prepare("UPDATE students SET ". "firstname='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['firstname'][$x]))."', ". "lastname='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['lastname'][$x]))."', ". "sex='".stripslashes($_POST['sex'][$x])."', ". "email='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['email'][$x]))."', ". "address='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['address'][$x]))."', ". "city='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['city'][$x]))."', ". "province='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['province'][$x]))."', ". "postalcode='".stripslashes($_POST['postalcode'][$x])."', ". "phone='".stripslashes($_POST['phone'][$x])."', ". "dateofbirth='$dob', ". "grade='".stripslashes($_POST['grade'][$x])."', ". $schoolquery. "medicalalert='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['medicalalert'][$x]))."', ". "foodreq='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['foodreq'][$x]))."', ". "teachername='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['teachername'][$x]))."', ". "teacheremail='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['teacheremail'][$x]))."', ". "tshirt='".stripslashes($_POST['tshirt'][$x])."' ". "WHERE id='".$_POST['id'][$x]."'"); $stmt->execute(); happy_("%1 %2 successfully updated",array(iconv("UTF-8","ISO-8859-1//TRANSLIT",$_POST['firstname'][$x]),iconv("UTF-8","ISO-8859-1//TRANSLIT",$_POST['lastname'][$x]))); } $x++; } } function students_load() { global $registrations_id, $config; //now query and display $q=$pdo->prepare("SELECT * FROM students WHERE registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}'"); $q->execute(); echo $pdo->errorInfo(); $numfound=$q->rowCount(); $numtoshow = intval($_GET['numstudents']); if($numtoshow == 0) $numtoshow=$numfound; echo "
"; echo i18n("Number of students that worked on the project: "); echo ""; echo "
"; echo "
"; for($x=1;$x<=$numtoshow;$x++) { $studentinfo=$q->fetch(PDO::FETCH_OBJ); echo "

".i18n("Student %1 Details",array($x))."

"; //if we have a valid student, set their ID, so we can UPDATE when we submit //if there is no record for this student, then set the ID to 0, so we will INSERT when we submit if($studentinfo->id) $id=$studentinfo->id; else $id=0; //true should work here, it just has to be set to _something_ for it to work. echo ""; //save the ID, or 0 if it doesnt exist echo ""; echo ""; echo "\n"; echo " \n"; echo " \n"; echo "\n"; if($config['participant_student_personal']=="yes") { echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; if($config['participant_student_personal']=="yes") { echo " \n"; } else { echo ""; } echo "\n"; if($config['participant_student_personal']=="yes") { echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; } else echo ""; echo " "; echo ""; if($config['participant_student_tshirt']=="yes") { echo "\n"; echo " \n"; echo ""; } if($config['participant_student_personal']=="yes") { echo "\n"; echo ""; echo "\n"; } if($config['participant_student_foodreq']=="yes") { echo "\n"; echo ""; echo "\n"; } echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".i18n("First Name")."firstname\" />".REQUIREDFIELD."".i18n("Last Name")."lastname\" />".REQUIREDFIELD."
".i18n("Gender").""; echo "".REQUIREDFIELD; } echo "
".i18n("Email Address")."email\" />".REQUIREDFIELD."".i18n("City")."city\" />".REQUIREDFIELD."
".i18n("Address")."address\" />".REQUIREDFIELD."".i18n($config['provincestate']).""; emit_province_selector("province[$x]",$studentinfo->province); echo REQUIREDFIELD."
".i18n($config['postalzip'])."postalcode\" />".REQUIREDFIELD."".i18n("Phone")."phone\" />".REQUIREDFIELD."
".i18n("Date of Birth")."\n"; list($year,$month,$day)=split("-",$studentinfo->dateofbirth); echo "
"; emit_day_selector("day[$x]",$day); echo "\n"; emit_month_selector("month[$x]",$month); echo "\n"; //the year selector should be based on the min/max grades possible //assume min age of 3 for grade=0 (kindergarden) //assume max age of 18 for grade=12 $minyearselect=$config['FAIRYEAR'] - 6 - $config['maxgrade']; $maxyearselect=$config['FAIRYEAR'] - 3 - $config['mingrade']; emit_year_selector("year[$x]",$year,$minyearselect,$maxyearselect); echo "".REQUIREDFIELD."
\n"; echo "
".i18n("Grade")."\n"; echo "\n"; echo REQUIREDFIELD."
".i18n("T-Shirt Size").""; echo " "; echo "
".i18n("Medical Alert Info").""; echo "medicalalert\" />"; echo "
".i18n("Special Food Requirements").""; echo "foodreq\" />"; echo "
".i18n("School").""; if( $config['participant_registration_type']=="open" || $config['participant_registration_type']=="singlepassword" || $config['participant_registration_type']=="openorinvite" || ($studentinfo && !$studentinfo->schools_id) ) { $schoolq=$pdo->prepare("SELECT id,school,city FROM schools WHERE year='".$config['FAIRYEAR']."' ORDER by city,school"); $schoolq->execute(); echo "".REQUIREDFIELD; } else { $schoolq=$pdo->prepare("SELECT id,school FROM schools WHERE year='".$config['FAIRYEAR']."' AND id='$studentinfo->schools_id'"); $schoolq->execute(); $r=$schoolq->fetch(PDO::FETCH_OBJ); echo $r->school; } echo "
".i18n("Teacher Name")."teachername\" />".i18n("Teacher Email")."teacheremail\" />
"; if($numfound>$config['minstudentsperproject'] && $studentinfo->id) { /* Create a hidden with same id as the button and some extra, so we can find it inside * the button even with: this.id"+_studebts_id" */ echo "id}_students_id\" name=\"students_remove[]\" value=\"{$studentinfo->id}\" />"; /* Define the button */ echo "
"; echo "

"; } echo "
"; echo "
"; } echo "
"; echo i18n("WARNING! If you make a change to the grade that would affect the project number, you must update the project number manually, it will NOT be automatically updated"); echo "
"; echo "\n"; echo "
"; echo "
"; } function registration_load() { global $registrations_id, $config, $auth_type; /* Load reg data */ if($registrations_id == -1) { /* New project */ /* Find a reg num */ do { $regnum=rand(100000,999999); $q=$pdo->prepare("SELECT * FROM registrations WHERE num='$regnum' AND year={$config['FAIRYEAR']}"); $q->execute(); } while($q->rowCount()>0); $r['num'] = $regnum; echo notice(i18n('New registration number generated.')); echo notice(i18n('This new registration will added when the "Save Registration Information" button is pressed below. At that time the other tabs will become available.')); } else { $q = $pdo->prepare("SELECT * FROM registrations WHERE id='$registrations_id'"); $q->execute(); if($q->rowCount() != 1) $r = array(); else { $r = $q->fetch(PDO::FETCH_ASSOC); /* Get the fair from the project */ $q = $pdo->prepare("SELECT fairs_id FROM projects WHERE registrations_id='$registrations_id'"); $q->execute(); if($q->rowCount() == 1) { $p = $q->fetch(PDO::FETCH_ASSOC); $r['fairs_id'] = $p['fairs_id']; } } } /* Load fairs */ $fairs = array(); $q = $pdo->prepare("SELECT * FROM fairs WHERE type='feeder'"); $q->execute(); while(($f = $q->fetch(PDO::FETCH_ASSOC))) { $fairs[$f['id']] = $f; } /* Print form */ $status = array('new'=>'New', 'open'=>'Open','paymentpending'=>'Payment Pending', 'complete'=>'Complete'); ?>
0) { ?> \n"; } ?>
:
:
:
:


prepare("INSERT INTO registrations (start,schools_id,year) VALUES ( NOW(), NULL, '{$config['FAIRYEAR']}')"); $stmt->execute(); $registrations_id = $pdo->lastInsertId(); /* Create one student and a project */ $stmt=$pdo->prepare("INSERT INTO students (registrations_id,email,year) VALUES ( $registrations_id, '$registration_email', '{$config['FAIRYEAR']}')"); $stmt->execute(); $stmt=$pdo->prepare("INSERT INTO projects (registrations_id,year) VALUES ( $registrations_id, '{$config['FAIRYEAR']}')"); $stmt->execute(); happy_('Created student and project record'); } /* Update registration */ $stmt = $pdo->prepare("UPDATE registrations SET num='$registration_num', status='$registration_status', email='$registration_email' WHERE id='$registrations_id'"); $stmt->execute(); echo $pdo->errorInfo(); /* And the fairs_id, override anythign specified * if the user is a fair, force their own fairs_id */ if($auth_type == 'fair') $fairs_id = $_SESSION['fairs_id']; $stmt = $pdo->prepare("UPDATE projects SET fairs_id='$fairs_id' WHERE registrations_id='$registrations_id'"); $stmt->execute(); echo $pdo->errorInfo(); happy_('Information Saved'); echo ""; } ?>