From 321a245670fba3db0ee1cbf5d7d7520d9d0437a8 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 18 Jan 2006 05:22:58 +0000 Subject: [PATCH] Split school access and school participant invitations into separate files Update invitation system to keep track of the number that have been invited and not allow the school to invite more than they are allowed Update the schools editor, to allow specifying the max number of projects and whether the max is total for the school, or per age category Add required fields to the schools table Update the config variable for special awards registration to allow turning special awards registration off --- admin/schools.php | 25 +++ db/db.update.12.sql | 2 + register_participants_project.php | 2 +- schoolaccess.php | 82 +--------- schoolinvite.php | 243 ++++++++++++++++++++++++++++++ 5 files changed, 277 insertions(+), 77 deletions(-) create mode 100644 db/db.update.12.sql create mode 100644 schoolinvite.php diff --git a/admin/schools.php b/admin/schools.php index 64600550..d5ee8800 100644 --- a/admin/schools.php +++ b/admin/schools.php @@ -54,6 +54,8 @@ "scienceheadphone='".mysql_escape_string(stripslashes($_POST['scienceheadphone']))."', ". "scienceheademail='".mysql_escape_string(stripslashes($_POST['scienceheademail']))."', ". "registration_password='".mysql_escape_string(stripslashes($_POST['registration_password']))."', ". + "projectlimit='".mysql_escape_string(stripslashes($_POST['projectlimit']))."', ". + "projectlimitper='".mysql_escape_string(stripslashes($_POST['projectlimitper']))."', ". "accesscode='".mysql_escape_string(stripslashes($_POST['accesscode']))."' ". "WHERE id='$id'"; mysql_query($exec); @@ -115,6 +117,29 @@ { echo "
".i18n("Participant Registration Password").""; echo "".i18n("Password")."registration_password)."\" size=\"32\" maxlength=\"32\" />\n"; + } + echo "
".i18n("Participant Registration Limits").""; + if($config['participant_registration_type']=="invite") + { + echo "".i18n("Set to 0 to have no registration limit").""; + echo "".i18n("Maximum of")." "; + echo "projectlimit)."\" size=\"4\" maxlength=\"4\" />"; + echo " "; + echo i18n("projects"); + echo " "; + echo ""; + echo "\n"; + } + else + { + echo "".i18n("Participant registration limits are currently disabled. In order to use participant registration limits for schools, the participant registration type must be set to 'invite' in Configuration / Configuration Variables").""; + + } echo " "; echo "\n"; diff --git a/db/db.update.12.sql b/db/db.update.12.sql new file mode 100644 index 00000000..8af5cbc0 --- /dev/null +++ b/db/db.update.12.sql @@ -0,0 +1,2 @@ +UPDATE `config` SET `description` = 'Self nominations for special awards are due either with registration or on a specific date. If "date" is used, it must be configured under "Important Dates" section. If you do not wish to allow students to self-nominate for special awards, set to "none" (none|date|registration)' WHERE `var` = 'specialawardnomination'; +ALTER TABLE `schools` ADD `projectlimit` INT NOT NULL , ADD `projectlimitper` ENUM( 'total', 'agecategory' ) NOT NULL ; diff --git a/register_participants_project.php b/register_participants_project.php index 0052c764..fb908c44 100644 --- a/register_participants_project.php +++ b/register_participants_project.php @@ -110,7 +110,7 @@ echo mysql_error(); $gradeinfo=mysql_fetch_object($q); //now lets grab all the age categories, so we can choose one based on the max grade - $q=mysql_query("SELECT * FROM projectcategories ORDER BY id"); + $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); while($r=mysql_fetch_object($q)) { //save these in an array, just incase we need them later (FIXME: remove this array if we dont need it) diff --git a/schoolaccess.php b/schoolaccess.php index 638da346..ca76a5d4 100644 --- a/schoolaccess.php +++ b/schoolaccess.php @@ -87,45 +87,6 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) } - if($_POST['action']=="invite") - { - if($_POST['firstname'] && $_POST['lastname'] && $_POST['email']) - { - $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',". - "'".$_POST['email']."',". - "NOW(),". - "'open',". - $config['FAIRYEAR']. - ")"); - $regid=mysql_insert_id(); - - mysql_query("INSERT INTO students (registrations_id,email,firstname,lastname,schools_id,year) VALUES ( - '$regid', - '".mysql_escape_string($_POST['email'])."', - '".mysql_escape_string($_POST['firstname'])."', - '".mysql_escape_string($_POST['lastname'])."', - '".mysql_escape_string($_SESSION['schoolid'])."', - '".$config['FAIRYEAR']."')"); - - email_send("new_participant",$_POST['email'],array("FAIRNAME"=>i18n($config['fairname'])),array("REGNUM"=>"$regnum")); - echo happy(i18n("The participant has been successfully invited")); - } - } - - - echo "

$school->school

"; echo "

School Information

"; echo "Please make sure your school contact information is correct, make any necessary changes:"; @@ -163,40 +124,13 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) } else if($config['participant_registration_type']=="invite") { - $q=mysql_query("SELECT (NOW()>'".$config['dates']['regopen']."' AND NOW()<'".$config['dates']['regclose']."') AS datecheck"); - $datecheck=mysql_fetch_object($q); - if($datecheck!=0) - { - echo "

".i18n("Participant Registration Invitations")."

"; - - echo i18n("In order for your school's students to register for the fair, you will need to invite them to register. Simply enter their email address below to invite them to register. Important: for group projects, only add one of the participants, that participant will then add the other group member(s) to the project"); - echo "
"; - echo "
"; - - echo "
"; - echo ""; - - echo ""; - echo ""; - echo ""; - echo ""; - echo "
".i18n("Email Address")."
".i18n("First Name")."
".i18n("Last Name")."
"; - echo ""; - echo "
"; - } + + echo "

".i18n("Participant Registration Invitations")."

"; + echo i18n("In order for your school's students to register for the fair, you must first invite them via email. Use the 'Participant Registration Invitations' link below to invite your students to the fair"); + echo "
"; + echo "
"; + echo "   ".i18n("Participant Registration Invitations").""; echo "
"; - - echo "

".i18n("Invited participants from your school")."

"; - $q=mysql_query("SELECT students.*,registrations.num FROM students,registrations WHERE schools_id='".$school->id."' AND students.year='".$config['FAIRYEAR']."' AND students.registrations_id=registrations.id ORDER BY lastname,firstname"); - echo ""; - echo ""; - while($r=mysql_fetch_object($q)) - { - echo ""; - - } - echo "
".i18n("Last Name")."".i18n("First Name")."".i18n("Email Address")."".i18n("Registration Number")."
$r->lastname$r->firstname$r->email$r->num
"; - } /* @@ -268,10 +202,6 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) { echo "Invalid School ID or Access Code (2)"; } - - - - } else { diff --git a/schoolinvite.php b/schoolinvite.php new file mode 100644 index 00000000..d1a68e2a --- /dev/null +++ b/schoolinvite.php @@ -0,0 +1,243 @@ +<< ".i18n("Return to school access main page")."
"; + echo "
"; + $q=mysql_query("SELECT * FROM schools WHERE id='".$_SESSION['schoolid']."' AND accesscode='".$_SESSION['schoolaccesscode']."' AND year='".$config['FAIRYEAR']."'"); + echo mysql_error(); + $school=mysql_fetch_object($q); + if($school) + { + if($config['participant_registration_type']=="invite") + { + if($_POST['action']=="invite") + { + if($_POST['firstname'] && $_POST['lastname'] && $_POST['email'] && $_POST['grade']) + { + //make sure they arent already invited! + $q=mysql_query("SELECT firstname, lastname FROM students WHERE year='".$config['FAIRYEAR']."' AND email='".$_POST['email']."'"); + if(mysql_num_rows($q)) + { + echo error(i18n("That students email address has already been invited")); + } + 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',". + "'".$_POST['email']."',". + "NOW(),". + "'open',". + $config['FAIRYEAR']. + ")"); + $regid=mysql_insert_id(); + + mysql_query("INSERT INTO students (registrations_id,email,firstname,lastname,schools_id,grade,year) VALUES ( + '$regid', + '".mysql_escape_string($_POST['email'])."', + '".mysql_escape_string($_POST['firstname'])."', + '".mysql_escape_string($_POST['lastname'])."', + '".mysql_escape_string($_SESSION['schoolid'])."', + '".mysql_escape_string($_POST['grade'])."', + '".$config['FAIRYEAR']."')"); + + email_send("new_participant",$_POST['email'],array("FAIRNAME"=>i18n($config['fairname'])),array("REGNUM"=>"$regnum")); + echo happy(i18n("The participant has been successfully invited")); + } + } + else + echo error(i18n("All fields are required for invitations")); + } + + if($_GET['action']=="uninvite") + { + //first, make sure that this is really their student, and it sfor this year. + $q=mysql_query("SELECT * FROM students WHERE id='".$_GET['uninvite']."' AND year='".$config['FAIRYEAR']."' AND schools_id='".$_SESSION['schoolid']."'"); + if(mysql_num_rows($q)) + { + $r=mysql_fetch_object($q); + $registrations_id=$r->registrations_id; + if($registrations_id) //just to be safe! + { + mysql_query("DELETE FROM students WHERE registrations_id='$registrations_id'"); + mysql_query("DELETE FROM projects WHERE registrations_id='$registrations_id'"); + mysql_query("DELETE FROM mentors WHERE registrations_id='$registrations_id'"); + mysql_query("DELETE FROM safety WHERE registrations_id='$registrations_id'"); + mysql_query("DELETE FROM emergencycontact WHERE registrations_id='$registrations_id'"); + mysql_query("DELETE FROM registrations WHERE id='$registrations_id'"); + + echo happy(i18n("Student successfully uninvited")); + } + } + else + echo error(i18n("Invalid student to uninvite")); + } + + + $q=mysql_query("SELECT (NOW()>'".$config['dates']['regopen']."' AND NOW()<'".$config['dates']['regclose']."') AS datecheck"); + $datecheck=mysql_fetch_object($q); + + + $q=mysql_query("SELECT students.*, + registrations.num + FROM + students, + registrations + WHERE + schools_id='".$school->id."' + AND students.year='".$config['FAIRYEAR']."' + AND students.registrations_id=registrations.id + ORDER BY + lastname, + firstname"); + if($datecheck!=0) + $currentinvited=mysql_num_rows($q); + { + echo i18n("In order for your school's students to register for the fair, you will need to invite them to register. Simply enter their email address below to invite them to register. Important: for group projects, only add one of the participants, that participant will then add the other group member(s) to the project"); + echo "
"; + $okaygrades=array(); + if($school->projectlimitper=="total") + { + if($school->projectlimit) + { + echo i18n("You have invited %1 of %2 total projects for your school",array($currentinvited,$school->projectlimit)); + if($currenteinvited<$school->projectlimit) + { + for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++) + $okaygrades[]=$a; + } + } + else + { + echo i18n("You have invited %1 project(s) for your school",array($currentinvited,$school->projectlimit)); + for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++) + $okaygrades[]=$a; + + } + } + else if($school->projectlimitper=="agecategory") + { + echo "
"; + $catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); + while($catr=mysql_fetch_object($catq)) + { + + $q2=mysql_query("SELECT COUNT(students.id) AS num + FROM + students, + registrations + WHERE + schools_id='".$school->id."' + AND students.grade>='$catr->mingrade' + AND students.grade<='$catr->maxgrade' + AND students.year='".$config['FAIRYEAR']."' + AND students.registrations_id=registrations.id + "); + echo mysql_error(); + $r2=mysql_fetch_object($q2); + $currentinvited=$r2->num; + + if($currentinvited<$school->projectlimit) + { + for($a=$catr->mingrade;$a<=$catr->maxgrade;$a++) + $okaygrades[]=$a; + } + + echo i18n("You have invited %1 of %2 total projects for for the %3 age category",array($currentinvited,$school->projectlimit,i18n($catr->category))); + echo "
"; + + } + } + echo "
"; + + if(count($okaygrades)) + { + + echo "
"; + echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "
".i18n("Email Address")."
".i18n("First Name")."
".i18n("Last Name")."
".i18n("Grade").""; + + echo "
"; + echo ""; + echo "
"; + } + else + { + echo notice(i18n("You have invited the maximum number of participants for your school")); + + } + } + echo "
"; + + echo "

".i18n("Invited participants from your school")."

"; + if(mysql_num_rows($q)) + { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + while($r=mysql_fetch_object($q)) + { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + } + echo "
".i18n("Last Name")."".i18n("First Name")."".i18n("Email Address")."".i18n("Grade")."".i18n("Registration Number")."".i18n("Actions")."
$r->lastname$r->firstname$r->email$r->grade$r->num"; + echo "id\">"; + echo "
"; + } + else + echo i18n("You have not yet invited any participants from your school"); + + } + } + else + { + echo error(i18n("Invalid School ID or Access Code")); + echo "
"; + echo "".i18n("Perhaps you should login first").""; + } + send_footer(); +} +else +{ + header("Location: schoolaccess.php"); +} + +?>