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. */ ?> '".$config['dates']['regopen']."' AND NOW()<'".$config['dates']['regclose']."') AS datecheck"); $datecheck=mysql_fetch_object($q); if($_POST['action']=="new") { $q=mysql_query("SELECT email,num,id FROM registrations WHERE email='".$_SESSION['email']."' AND num='".$_POST['regnum']."' AND year=".$config['FAIRYEAR']); if(mysql_num_rows($q)) { $r=mysql_fetch_object($q); $_SESSION['registration_number']=$r->num; $_SESSION['registration_id']=$r->id; mysql_query("INSERT INTO students (registrations_id,email,year) VALUES ('$r->id','".mysql_escape_string($_SESSION['email'])."','".$config['FAIRYEAR']."')"); mysql_query("UPDATE registrations SET status='open' WHERE id='$r->id'"); header("Location: register_participants_main.php"); exit; } else { send_header("Participant Registration"); echo error(i18n("Invalid registration number (%1) for email address %2",array($_POST['regnum'],$_SESSION['email']),array("registration number","email address"))); $_POST['action']="login"; } } else if($_POST['action']=="continue") { $q=mysql_query("SELECT registrations.id AS regid, registrations.num AS regnum, students.id AS studentid, students.firstname FROM registrations,students ". "WHERE students.email='".$_SESSION['email']."' ". "AND registrations.num='".$_POST['regnum']."' ". "AND students.registrations_id=registrations.id ". "AND registrations.year=".$config['FAIRYEAR']." ". "AND students.year=".$config['FAIRYEAR']); if(mysql_num_rows($q)) { $r=mysql_fetch_object($q); $_SESSION['registration_number']=$r->regnum; $_SESSION['registration_id']=$r->regid; header("Location: register_participants_main.php"); exit; } else { send_header("Participant Registration"); echo error(i18n("Invalid registration number (%1) for email address %2",array($_POST['regnum'],$_SESSION['email']),array("registration number","email address"))); $_POST['action']="login"; } } else if($_GET['action']=="resend" && $_SESSION['email']) { //first see if the email matches directly from the registrations table $q=mysql_query("SELECT registrations.num FROM registrations WHERE registrations.email='".$_SESSION['email']."' AND registrations.year='".$config['FAIRYEAR']."'"); if(mysql_num_rows($q)) $r=mysql_fetch_object($q); else { //no match from registrations, so lets see if it matches from the students table $q=mysql_query("SELECT registrations.num FROM registrations, students WHERE students.email='".$_SESSION['email']."' AND students.registrations_id=registrations.id AND registrations.year='".$config['FAIRYEAR']."'"); $r=mysql_fetch_object($q); } if($r) { email_send("register_participants_resend_regnum",$_SESSION['email'],array("FAIRNAME"=>i18n($config['fairname'])),array("REGNUM"=>$r->num)); send_header("Participant Registration"); echo notice(i18n("Your registration number has been resent to your email addess %1",array($_SESSION['email']),array("email address"))); } else { send_header("Participant Registration"); echo error(i18n("Could not find a registration for your email address")); } } else if($_GET['action']=="logout") { unset($_SESSION['email']); unset($_SESSION['registration_number']); unset($_SESSION['registration_id']); send_header("Participant Registration"); echo notice(i18n("You have been successfully logged out")); } //if they've alreayd logged in, and somehow wound back up here, take them back to where they should be if($_SESSION['registration_number'] && $_SESSION['registration_id'] && $_SESSION['email']) { header("Location: register_participants_main.php"); } send_header("Participant Registration"); if($_POST['action']=="login" && ( $_POST['email'] || $_SESSION['email']) ) { if($_POST['email']) $_SESSION['email']=$_POST['email']; echo "
"; $allownew=true; $showform=true; //first, check if they have any registrations waiting to be opened $q=mysql_query("SELECT * FROM registrations WHERE email='".$_SESSION['email']."' AND status='new' AND year='".$config['FAIRYEAR']."'"); if(mysql_num_rows($q)>0) { echo i18n("Please enter your registration number that you received in your email, in order to begin your new registration"); echo ""; $allownew=false; } else { //check if they have an already open registration $q=mysql_query("SELECT students.email, registrations.status, registrations.id FROM students, registrations WHERE students.email='".$_SESSION['email']."' AND students.year=".$config['FAIRYEAR']." AND registrations.year=".$config['FAIRYEAR']." AND registrations.status='open' AND students.registrations_id=registrations.id"); if(mysql_num_rows($q)>0) { $r=mysql_fetch_object($q); // print_r($r); echo i18n("Please enter your registration number in order to continue your registration"); echo ""; $allownew=false; echo "
"; } else { //they dont have a 'new' and they dont have an 'open' so that means that they want to create a new one... BUT... if($config['participant_registration_type']=="invite") { $allownew=false; $showform=false; echo i18n("Participant registration is by invite only. You can not create a new account. If you have been invited by your school/region, you need to use the same email address that you were invited with."); echo "
"; echo "
"; echo "Back to Participant Registration"; } else if($config['participant_registration_type']=="singlepassword") { $showsinglepasswordform=true; if($_POST['singlepassword']) { if($_POST['singlepassword']==$config['participant_registration_singlepassword']) { $allownew=true; $showform=true; $showsinglepasswordform=false; } else { echo error(i18n("Invalid registration password, please try again")); $allownew=false; $showform=false; } } if($showsinglepasswordform) { echo i18n("Participant registration is protected by a password. You must know the registration password in order to create an account."); echo "
"; echo "
"; echo ""; echo i18n("Email Address:")." ".$_SESSION['email']."
"; echo i18n("Registration Password:"); echo ""; echo "
"; echo "
"; echo ""; echo "
"; $allownew=false; $showform=false; } } else if($config['participant_registration_type']=="schoolpassword") { $showschoolpasswordform=true; if($_POST['schoolpassword'] && $_POST['schoolid']) { $q=mysql_query("SELECT registration_password FROM schools WHERE id='".$_POST['schoolid']."' AND year='".$config['FAIRYEAR']."'"); $r=mysql_fetch_object($q); if($_POST['schoolpassword']==$r->registration_password) { $allownew=true; $showform=true; $showschoolpasswordform=false; } else { echo error(i18n("Invalid school registration password, please try again")); $allownew=false; $showform=false; } } if($showschoolpasswordform) { echo i18n("Participant registration is protected by a password for each school. You must know your school registration password in order to create an account."); echo "
"; echo "
"; echo ""; echo i18n("Email Address:")." ".$_SESSION['email']."
"; echo i18n("School: "); $q=mysql_query("SELECT id,school FROM schools WHERE year='".$config['FAIRYEAR']."'"); echo ""; echo "
"; echo i18n("School Registration Password: "); echo ""; echo "
"; echo "
"; echo ""; echo ""; $allownew=false; $showform=false; } } else if($config['participant_registration_type']=="open") { //thats fine, continue on and create them the account. } else { echo error(i18n("There is an error with the SFIAB configuration. participant_registration_type is not defined. Contact the fair organizers to get this fixed.")); $allownew=false; $showform=false; } } } if($allownew) { if($datecheck->datecheck==0) { echo error(i18n("Registration is closed. You can not create a new account")); $showform=false; echo "Back to Participant Registration Login Page"; } else { $regnum=0; //now create the new registration record, and assign a random/unique registration number to then. do { //random number between //100000 and 999999 (six digit integer) $regnum=rand(100000,999999); $q=mysql_query("SELECT * FROM registrations WHERE num='$regnum' AND year=".$config['FAIRYEAR']); }while(mysql_num_rows($q)>0); //actually insert it mysql_query("INSERT INTO registrations (num,email,start,status,year) VALUES (". "'$regnum',". "'".$_SESSION['email']."',". "NOW(),". "'new',". $config['FAIRYEAR']. ")"); email_send("new_participant",$_SESSION['email'],array("FAIRNAME"=>i18n($config['fairname'])),array("REGNUM"=>$regnum)); echo i18n("You have been identified as a new registrant. An email has been sent to %1 which contains your new registration number. Please check your email to obtain your registration number and then enter it below:",array($_SESSION['email']),array("email address")); echo ""; } } if($showform) { echo "
"; echo "
"; echo i18n("Registration Number:"); echo ""; echo "
"; echo "
"; echo ""; echo ""; echo "
"; echo i18n("If you have lost or forgotten your registration number, please click here to resend it to your email address"); } } else { //Lets check the date - if we are AFTER 'regopen' and BEFORE 'regclose' then we can login //otherwise, registration is closed - no logins! //this will return 1 if its between the dates, 0 otherwise. if($datecheck->datecheck==0) { echo notice(i18n("Registration for the %1 %2 is now closed. Existing registrants can login and view (read only) their information, as well as apply for special awards (if applicable).",array($config['FAIRYEAR'],$config['fairname']),array("fair year","fair name"))); echo i18n("Please enter your email address to login"); echo "
"; echo "
"; $buttontext=i18n("Login"); } else { if($config['participant_registration_type']=="invite") { echo i18n("Registration is by invitation only. In order to register you must have your account created for you by your school or the science fair committee. Once your account is created you'll be invited via email to login and complete your registration information"); echo "
"; echo "
"; echo i18n("Please enter your email address to :"); echo "