2005-01-24 18:00:03 +00:00
< ?
/*
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 .
*/
?>
2004-11-30 18:55:39 +00:00
< ?
require ( " common.inc.php " );
2004-11-30 22:59:27 +00:00
2006-09-17 14:32:42 +00:00
$q = mysql_query ( " SELECT (NOW()>' " . $config [ 'dates' ][ 'regopen' ] . " ' AND NOW()<' " . $config [ 'dates' ][ 'regclose' ] . " ') AS datecheck,
NOW () < '".$config[' dates '][' regopen ']."' AS datecheckbefore ,
NOW () > '".$config[' dates '][' regclose ']."' AS datecheckafter " );
2005-05-12 15:47:21 +00:00
$datecheck = mysql_fetch_object ( $q );
2010-03-16 16:49:40 +00:00
if ( $_POST [ 'action' ] == " new " ) {
2006-02-23 20:40:48 +00:00
$q = mysql_query ( " SELECT email,num,id,schools_id FROM registrations WHERE email=' " . $_SESSION [ 'email' ] . " ' AND num=' " . $_POST [ 'regnum' ] . " ' AND year= " . $config [ 'FAIRYEAR' ]);
2010-03-16 16:49:40 +00:00
if ( mysql_num_rows ( $q )) {
2004-11-30 22:59:27 +00:00
$r = mysql_fetch_object ( $q );
$_SESSION [ 'registration_number' ] = $r -> num ;
$_SESSION [ 'registration_id' ] = $r -> id ;
2006-02-23 20:40:48 +00:00
mysql_query ( " INSERT INTO students (registrations_id,email,schools_id,year) VALUES (' $r->id ',' " . mysql_escape_string ( $_SESSION [ 'email' ]) . " ',' " . $r -> schools_id . " ',' " . $config [ 'FAIRYEAR' ] . " ') " );
2004-11-30 23:38:13 +00:00
mysql_query ( " UPDATE registrations SET status='open' WHERE id=' $r->id ' " );
2004-11-30 22:59:27 +00:00
header ( " Location: register_participants_main.php " );
exit ;
}
2010-03-16 16:49:40 +00:00
else {
2004-11-30 22:59:27 +00:00
send_header ( " Participant Registration " );
2006-01-19 17:15:07 +00:00
echo error ( i18n ( " Invalid registration number (%1) for email address %2 " , array ( $_POST [ 'regnum' ], $_SESSION [ 'email' ]), array ( " registration number " , " email address " )));
2004-11-30 22:59:27 +00:00
$_POST [ 'action' ] = " login " ;
}
}
2010-03-16 16:49:40 +00:00
else if ( $_POST [ 'action' ] == " continue " ) {
2007-10-26 16:57:14 +00:00
if ( $_POST [ 'email' ])
$_SESSION [ 'email' ] = stripslashes ( mysql_escape_string ( $_POST [ 'email' ]));
2004-11-30 22:59:27 +00:00
2004-12-03 04:28:18 +00:00
$q = mysql_query ( " SELECT registrations.id AS regid, registrations.num AS regnum, students.id AS studentid, students.firstname FROM registrations,students " .
2010-03-16 16:57:39 +00:00
" WHERE students.email=' " . $_SESSION [ 'email' ] . " ' " .
2010-03-16 16:49:40 +00:00
" AND registrations.num=' " . intval ( $_POST [ 'regnum' ]) . " ' " .
2004-11-30 23:38:13 +00:00
" AND students.registrations_id=registrations.id " .
" AND registrations.year= " . $config [ 'FAIRYEAR' ] . " " .
" AND students.year= " . $config [ 'FAIRYEAR' ]);
2010-03-16 16:49:40 +00:00
if ( mysql_num_rows ( $q )) {
2004-11-30 23:38:13 +00:00
$r = mysql_fetch_object ( $q );
$_SESSION [ 'registration_number' ] = $r -> regnum ;
$_SESSION [ 'registration_id' ] = $r -> regid ;
2007-12-22 23:28:14 +00:00
$_SESSION [ 'students_id' ] = $r -> studentid ;
2004-11-30 23:38:13 +00:00
header ( " Location: register_participants_main.php " );
exit ;
}
2010-03-16 16:49:40 +00:00
else {
2005-12-08 18:01:30 +00:00
send_header ( " Participant Registration " );
2006-01-19 17:15:07 +00:00
echo error ( i18n ( " Invalid registration number (%1) for email address %2 " , array ( $_POST [ 'regnum' ], $_SESSION [ 'email' ]), array ( " registration number " , " email address " )));
2004-12-02 23:15:42 +00:00
$_POST [ 'action' ] = " login " ;
}
2004-11-30 23:38:13 +00:00
}
2010-03-16 16:49:40 +00:00
else if ( $_GET [ 'action' ] == " resend " && $_SESSION [ 'email' ]) {
2005-11-24 20:21:55 +00:00
//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 );
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
//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 );
2004-12-02 17:53:31 +00:00
2005-11-24 20:21:55 +00:00
}
2004-12-02 17:53:31 +00:00
2010-03-16 16:49:40 +00:00
if ( $r ) {
2010-01-27 20:24:16 +00:00
email_send ( " register_participants_resend_regnum " , $_SESSION [ 'email' ], array (), array ( " REGNUM " => $r -> num ));
2005-11-24 20:21:55 +00:00
send_header ( " Participant Registration " );
2008-02-15 05:27:06 +00:00
echo notice ( i18n ( " Your registration number has been resent to your email address <b>%1</b> " , array ( $_SESSION [ 'email' ]), array ( " email address " )));
2005-11-24 20:21:55 +00:00
}
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
send_header ( " Participant Registration " );
echo error ( i18n ( " Could not find a registration for your email address " ));
}
2004-12-02 23:15:42 +00:00
}
2010-03-16 16:49:40 +00:00
else if ( $_GET [ 'action' ] == " logout " ) {
2004-12-02 23:15:42 +00:00
unset ( $_SESSION [ 'email' ]);
unset ( $_SESSION [ 'registration_number' ]);
unset ( $_SESSION [ 'registration_id' ]);
send_header ( " Participant Registration " );
echo notice ( i18n ( " You have been successfully logged out " ));
2004-12-02 17:53:31 +00:00
}
2004-11-30 23:38:13 +00:00
//if they've alreayd logged in, and somehow wound back up here, take them back to where they should be
2010-03-16 16:49:40 +00:00
if ( $_SESSION [ 'registration_number' ] && $_SESSION [ 'registration_id' ] && $_SESSION [ 'email' ]) {
2004-11-30 23:38:13 +00:00
header ( " Location: register_participants_main.php " );
2007-05-10 19:18:01 +00:00
exit ;
2004-11-30 23:38:13 +00:00
2004-11-30 22:59:27 +00:00
}
2004-11-30 18:55:39 +00:00
send_header ( " Participant Registration " );
2004-11-30 22:59:27 +00:00
2010-03-16 16:49:40 +00:00
if ( $_POST [ 'action' ] == " login " && ( $_POST [ 'email' ] || $_SESSION [ 'email' ]) ) {
2004-11-30 22:59:27 +00:00
if ( $_POST [ 'email' ])
2007-10-25 15:12:20 +00:00
$_SESSION [ 'email' ] = stripslashes ( mysql_escape_string ( $_POST [ 'email' ]));
2004-11-30 22:59:27 +00:00
echo " <form method= \" post \" action= \" register_participants.php \" > " ;
$allownew = true ;
2005-11-24 20:21:55 +00:00
$showform = true ;
2004-11-30 22:59:27 +00:00
//first, check if they have any registrations waiting to be opened
2005-11-24 20:21:55 +00:00
$q = mysql_query ( " SELECT * FROM registrations WHERE email=' " . $_SESSION [ 'email' ] . " ' AND status='new' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
2010-03-16 16:49:40 +00:00
if ( mysql_num_rows ( $q ) > 0 ) {
2004-12-02 17:53:31 +00:00
echo i18n ( " Please enter your <b>registration number</b> that you received in your email, in order to begin your new registration " );
2004-11-30 22:59:27 +00:00
echo " <input type= \" hidden \" name= \" action \" value= \" new \" > " ;
$allownew = false ;
}
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
//check if they have an already open registration
$q = mysql_query ( " SELECT
students . email ,
registrations . status ,
registrations . id
FROM
students ,
2004-11-30 22:59:27 +00:00
registrations
WHERE
2010-03-16 16:49:40 +00:00
students . email = '".$_SESSION[' email ']."'
2004-11-30 22:59:27 +00:00
AND students . year = " . $config['FAIRYEAR'] . "
AND registrations . year = " . $config['FAIRYEAR'] . "
2006-01-24 14:30:38 +00:00
AND
( registrations . status = 'open'
OR registrations . status = 'paymentpending'
OR registrations . status = 'complete'
)
2005-11-24 20:21:55 +00:00
AND students . registrations_id = registrations . id " );
2010-03-16 16:49:40 +00:00
if ( mysql_num_rows ( $q ) > 0 ) {
2005-11-24 20:21:55 +00:00
$r = mysql_fetch_object ( $q );
2005-12-08 15:35:41 +00:00
// print_r($r);
2006-01-24 14:30:38 +00:00
echo i18n ( " Please enter your <b>registration number</b> in order to login " );
2004-11-30 22:59:27 +00:00
echo " <input type= \" hidden \" name= \" action \" value= \" continue \" > " ;
$allownew = false ;
2004-12-02 17:53:31 +00:00
echo " <br /> " ;
2004-11-30 22:59:27 +00:00
}
2010-03-16 16:49:40 +00:00
else {
2006-01-24 14:30:38 +00:00
//they dont have a 'new' and they dont have an 'open/paymentpending/complete' so that means that they want to create a new one... BUT...
2010-03-16 16:49:40 +00:00
if ( $config [ 'participant_registration_type' ] == " invite " ) {
2005-11-24 20:21:55 +00:00
$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 " <br /> " ;
echo " <br /> " ;
echo " <a href= \" register_participants.php \" >Back to Participant Registration</a> " ;
}
2010-03-16 16:49:40 +00:00
else if ( $config [ 'participant_registration_type' ] == " singlepassword " ) {
2005-11-24 20:21:55 +00:00
$showsinglepasswordform = true ;
2010-03-16 16:49:40 +00:00
if ( $_POST [ 'singlepassword' ]) {
if ( $_POST [ 'singlepassword' ] == $config [ 'participant_registration_singlepassword' ]) {
2005-11-24 20:21:55 +00:00
$allownew = true ;
$showform = true ;
$showsinglepasswordform = false ;
}
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
echo error ( i18n ( " Invalid registration password, please try again " ));
$allownew = false ;
$showform = false ;
}
}
2010-03-16 16:49:40 +00:00
if ( $showsinglepasswordform ) {
2005-11-24 20:21:55 +00:00
echo i18n ( " Participant registration is protected by a password. You must know the <b>registration password</b> in order to create an account. " );
echo " <br /> " ;
echo " <br /> " ;
echo " <input type= \" hidden \" name= \" action \" value= \" login \" > " ;
echo i18n ( " Email Address: " ) . " " . $_SESSION [ 'email' ] . " <br /> " ;
echo i18n ( " Registration Password: " );
echo " <input type= \" text \" size= \" 10 \" name= \" singlepassword \" > " ;
echo " <br /> " ;
echo " <br /> " ;
echo " <input type= \" submit \" value= \" Submit \" > " ;
echo " </form> " ;
$allownew = false ;
$showform = false ;
}
}
2010-03-16 16:49:40 +00:00
else if ( $config [ 'participant_registration_type' ] == " schoolpassword " ) {
2005-11-24 20:21:55 +00:00
$showschoolpasswordform = true ;
2010-03-16 16:49:40 +00:00
if ( $_POST [ 'schoolpassword' ] && $_POST [ 'schoolid' ]) {
2005-11-24 20:21:55 +00:00
$q = mysql_query ( " SELECT registration_password FROM schools WHERE id=' " . $_POST [ 'schoolid' ] . " ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
$r = mysql_fetch_object ( $q );
2010-03-16 16:49:40 +00:00
if ( $_POST [ 'schoolpassword' ] == $r -> registration_password ) {
2005-11-24 20:21:55 +00:00
$allownew = true ;
$showform = true ;
$showschoolpasswordform = false ;
2006-02-23 20:40:48 +00:00
$schoolidquery = " ' " . $_POST [ 'schoolid' ] . " ' " ;
2005-11-24 20:21:55 +00:00
}
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
echo error ( i18n ( " Invalid school registration password, please try again " ));
$allownew = false ;
$showform = false ;
}
}
2010-03-16 16:49:40 +00:00
if ( $showschoolpasswordform ) {
2005-11-24 20:21:55 +00:00
echo i18n ( " Participant registration is protected by a password for each school. You must know your <b>school registration password</b> in order to create an account. " );
echo " <br /> " ;
echo " <br /> " ;
echo " <input type= \" hidden \" name= \" action \" value= \" login \" > " ;
echo i18n ( " Email Address: " ) . " " . $_SESSION [ 'email' ] . " <br /> " ;
echo i18n ( " School: " );
2007-02-24 19:31:55 +00:00
$q = mysql_query ( " SELECT id,school FROM schools WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY school " );
2005-11-24 20:21:55 +00:00
echo " <select name= \" schoolid \" > " ;
echo " <option value= \" \" > " . i18n ( " Choose your school " ) . " </option> \n " ;
while ( $r = mysql_fetch_object ( $q ))
echo " <option value= \" $r->id\ " > $r -> school </ option > \n " ;
echo " </select> " ;
echo " <br /> " ;
echo i18n ( " School Registration Password: " );
echo " <input type= \" text \" size= \" 10 \" name= \" schoolpassword \" > " ;
echo " <br /> " ;
echo " <br /> " ;
echo " <input type= \" submit \" value= \" Submit \" > " ;
echo " </form> " ;
$allownew = false ;
$showform = false ;
}
}
2010-03-16 16:49:40 +00:00
else if ( $config [ 'participant_registration_type' ] == " open " ) {
2005-11-24 20:21:55 +00:00
//thats fine, continue on and create them the account.
2007-01-02 23:38:53 +00:00
}
2010-03-16 16:49:40 +00:00
else if ( $config [ 'participant_registration_type' ] == " openorinvite " ) {
2007-01-02 23:38:53 +00:00
//thats fine too, continue on and create them the account.
2005-11-24 20:21:55 +00:00
}
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
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 ;
}
}
2004-11-30 22:59:27 +00:00
}
2005-11-24 20:21:55 +00:00
2004-11-30 22:59:27 +00:00
2010-03-16 16:49:40 +00:00
if ( $allownew ) {
if ( $datecheck -> datecheck == 0 ) {
2006-09-17 14:32:42 +00:00
if ( $datecheck -> datecheckbefore )
echo error ( i18n ( " Registration is not open yet. You can not create a new account " ));
else if ( $datecheck -> datecheckafter )
echo error ( i18n ( " Registration is now closed. You can not create a new account " ));
2005-05-12 15:47:21 +00:00
$showform = false ;
echo " <A href= \" register_participants.php \" >Back to Participant Registration Login Page</a> " ;
}
2010-03-16 16:49:40 +00:00
else {
2006-02-14 21:50:41 +00:00
//they can only create a new registraiton if they have a valid email address, so lets do a quick ereg check on their email
2010-03-16 16:49:40 +00:00
if ( isEmailAddress ( $_SESSION [ 'email' ])) {
2006-02-14 21:50:41 +00:00
$regnum = 0 ;
//now create the new registration record, and assign a random/unique registration number to then.
2010-03-16 16:49:40 +00:00
do {
2006-02-14 21:50:41 +00:00
//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 );
2006-02-23 20:40:48 +00:00
if ( ! $schoolidquery ) $schoolidquery = " null " ;
2006-02-14 21:50:41 +00:00
//actually insert it
2006-02-23 20:40:48 +00:00
mysql_query ( " INSERT INTO registrations (num,email,start,status,schools_id,year) VALUES ( " .
2006-02-14 21:50:41 +00:00
" ' $regnum ', " .
" ' " . $_SESSION [ 'email' ] . " ', " .
" NOW(), " .
" 'new', " .
2006-02-23 20:40:48 +00:00
$schoolidquery . " , " .
2006-02-14 21:50:41 +00:00
$config [ 'FAIRYEAR' ] .
" ) " );
2010-01-27 20:24:16 +00:00
email_send ( " new_participant " , $_SESSION [ 'email' ], array (), array ( " REGNUM " => $regnum , " EMAIL " => $_SESSION [ 'email' ]));
2006-02-14 21:50:41 +00:00
echo i18n ( " You have been identified as a new registrant. An email has been sent to <b>%1</b> which contains your new <b>registration number</b>. Please check your email to obtain your <b>registration number</b> and then enter it below: " , array ( $_SESSION [ 'email' ]), array ( " email address " ));
echo " <input type= \" hidden \" name= \" action \" value= \" new \" > " ;
}
2010-03-16 16:49:40 +00:00
else {
2006-02-14 21:50:41 +00:00
echo error ( i18n ( " The email address you entered (%1) appears to be invalid. You must use a proper email address in order to create an account " , array ( $_SESSION [ 'email' ])));
echo " <a href= \" register_participants.php \" > " . i18n ( " Return to participant registration " ) . " </a> " ;
$showform = false ;
}
2005-05-12 15:47:21 +00:00
}
2004-11-30 22:59:27 +00:00
}
2010-03-16 16:49:40 +00:00
if ( $showform ) {
2005-11-24 20:21:55 +00:00
echo " <br /> " ;
2005-05-12 15:47:21 +00:00
echo " <br /> " ;
echo i18n ( " Registration Number: " );
echo " <input type= \" text \" size= \" 10 \" name= \" regnum \" > " ;
2005-11-24 20:21:55 +00:00
echo " <br /> " ;
echo " <br /> " ;
2005-05-12 15:47:21 +00:00
echo " <input type= \" submit \" value= \" Submit \" > " ;
echo " </form> " ;
echo " <br /> " ;
echo i18n ( " If you have lost or forgotten your <b>registration number</b>, please <a href= \" register_participants.php?action=resend \" >click here to resend</a> it to your email address " );
}
2004-11-30 22:59:27 +00:00
}
2010-03-16 16:49:40 +00:00
else {
2005-03-29 19:21:14 +00:00
//Lets check the date - if we are AFTER 'regopen' and BEFORE 'regclose' then we can login
//otherwise, registration is closed - no logins!
2004-11-30 22:59:27 +00:00
2005-03-29 19:21:14 +00:00
//this will return 1 if its between the dates, 0 otherwise.
2010-03-16 16:49:40 +00:00
if ( $datecheck -> datecheck == 0 ) {
2006-09-17 14:32:42 +00:00
if ( $datecheck -> datecheckbefore )
2008-08-28 22:02:06 +00:00
echo notice ( i18n ( " Registration for the %1 %2 is not open yet. Registration will open on %3. " , array ( $config [ 'FAIRYEAR' ], $config [ 'fairname' ], format_datetime ( $config [ 'dates' ][ 'regopen' ])), array ( " fair year " , " fair name " , " registration open date " )));
2010-03-16 16:49:40 +00:00
else if ( $datecheck -> datecheckafter ) {
2006-09-17 14:32:42 +00:00
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 " );
}
2005-05-12 15:47:21 +00:00
echo " <br /> " ;
echo " <br /> " ;
$buttontext = i18n ( " Login " );
}
2010-03-16 16:49:40 +00:00
else {
if ( $config [ 'participant_registration_type' ] == " invite " ) {
2008-08-26 20:50:25 +00:00
echo i18n ( " Registration is by invitation only. As soon as you are invited by your school or the science fair committee, you will receive a welcoming email with your Registration Number " );
2005-11-24 20:21:55 +00:00
echo " <br /> " ;
echo " <br /> " ;
2008-08-26 20:50:25 +00:00
echo i18n ( " Please enter your email address to: " );
2005-11-24 20:21:55 +00:00
echo " <ul> " ;
}
2010-03-16 16:49:40 +00:00
else {
2005-11-24 20:21:55 +00:00
echo i18n ( " Please enter your email address to : " );
echo " <ul> " ;
echo " <li> " . i18n ( " Begin a new registration " ) . " </li> " ;
}
2005-03-29 19:21:14 +00:00
echo " <li> " . i18n ( " Continue a previously started registration " ) . " </li> " ;
echo " <li> " . i18n ( " Modify an existing registration " ) . " </li> " ;
echo " </ul> " ;
2005-05-12 15:47:21 +00:00
echo i18n ( " You must enter a valid email address. We will be emailing you information which you will need to complete the registration process! " );
2005-03-29 19:21:14 +00:00
echo " <br /> " ;
echo " <br /> " ;
2005-05-12 15:47:21 +00:00
$buttontext = i18n ( " Begin " );
2005-03-29 19:21:14 +00:00
}
2005-05-12 15:47:21 +00:00
2006-09-17 14:32:42 +00:00
//only show the email login box if registration is open, or we're past the registration deadline (so they can login and view / apply for special awards). if we're before the registration deadline then they cant create an account or login anwyays so no point in showing the box
2010-03-16 16:49:40 +00:00
if ( ! $datecheck -> datecheckbefore ) {
2005-05-12 15:47:21 +00:00
?>
< form method = " post " action = " register_participants.php " >
< input type = " hidden " name = " action " value = " login " />
< ? = i18n ( " Email " ) ?> : <input type="text" name="email" size="30" />
< input type = " submit " value = " <?= $buttontext ?> " />
</ form >
< ?
2006-09-17 14:32:42 +00:00
}
2004-11-30 22:59:27 +00:00
}
2004-11-30 18:55:39 +00:00
send_footer ();
?>