diff --git a/admin/index.php b/admin/index.php
index 8bd83b41..178b1e10 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -35,6 +35,9 @@
echo "".i18n("School Management")."
";
echo "".i18n("Judging Management")."
";
echo "".i18n("Translations Management")."
";
+if($config['tours_enable'] == 'yes') {
+ echo "".i18n("Tour Management")."
";
+}
echo "
";
echo "".i18n("Enter Winning Projects")."
";
echo "".i18n("One-Click CWSF Registration")."
";
diff --git a/admin/reports.php b/admin/reports.php
index bea8b494..4ccd173b 100644
--- a/admin/reports.php
+++ b/admin/reports.php
@@ -106,10 +106,27 @@ echo "";
echo "CSV ";
echo "PDF ";
+
echo "
";
echo "
";
echo i18n("Award Ceremony Script").": ";
echo "PDF ";
echo "CSV ";
+
+if($config['tours_enable'] == 'yes') {
+ echo "
";
+ echo "
";
+ echo i18n("Available Tours").": ";
+ echo "CSV ";
+ echo "
";
+ echo i18n("Participant Tour Choices").": ";
+ echo "CSV ";
+ echo "
";
+// echo i18n("Tour Volunteers").": ";
+// echo "CSV ";
+// echo "
";
+}
+
+
send_footer();
?>
diff --git a/admin/reports_tour_selection.php b/admin/reports_tour_selection.php
new file mode 100644
index 00000000..94632c1b
--- /dev/null
+++ b/admin/reports_tour_selection.php
@@ -0,0 +1,113 @@
+
+/*
+ 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
+ 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.
+*/
+?>
+
+ require("../common.inc.php");
+ auth_required('admin');
+ require("../lpdf.php");
+ require("../lcsv.php");
+
+ if(!$_GET['type']) $type="csv";
+ else $type=$_GET['type'];
+
+if($type=="pdf")
+{
+ $rep=new lpdf( i18n($config['fairname']),
+ i18n("Participant Tour Selections"),
+ $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
+ );
+
+ $rep->newPage();
+ $rep->setFontSize(11);
+}
+else if($type=="csv")
+{
+ $rep=new lcsv(i18n("Participant Tour Selections"));
+}
+
+$table=array();
+$table['header']=array( i18n("Student ID"));
+
+$choicesh=array();
+$max = $config['tours_choices_max'];
+for($x=0; $x<$max; $x++) {
+ $choicesh[] = i18n("Choice ".($x+1).($x==0?"(most preferred)":""));
+}
+$table['header']=array_merge($table['header'],$choicesh);
+$table['header'][] = "Name";
+$table['header'][] = "Grade";
+$table['header'][] = "Email";
+
+$q=mysql_query("SELECT DISTINCT students_id
+ FROM
+ tours_choice
+ WHERE
+ year='".$config['FAIRYEAR']."'");
+
+while($r=mysql_fetch_object($q))
+{
+
+// print_r($judge_divs);
+// print_r($judge_subdivs);
+
+ $qq = mysql_query("SELECT * FROM tours_choice WHERE ".
+ " year='".$config['FAIRYEAR']."' AND ".
+ " students_id='".$r->students_id."' ".
+ " ORDER BY rank ");
+ $c = array();
+ /* Define an array for tour choices */
+ for($x=0;$x<$max;$x++) {
+ $c[$x] = '';
+ }
+ /* Load up to $max tour choices */
+ $x = 0;
+ while($rr = mysql_fetch_object($qq)) {
+ $c[$x] = $rr->tour_id;
+ $x++;
+ if($x == $max) break;
+ }
+
+ $qq = mysql_query("SELECT * FROM students WHERE ".
+ " year='".$config['FAIRYEAR']."' AND ".
+ " id='".$r->students_id."' "
+ );
+ $rr = mysql_fetch_object($qq);
+ $name = $rr->firstname." ".$rr->lastname;
+ $grade = $rr->grade;
+ $email = $rr->email;
+
+ $tmp=array(
+ $r->students_id,
+ );
+ $tmp = array_merge($tmp,$c);
+ $tmp[] = $name;
+ $tmp[] = $grade;
+ $tmp[] = $email;
+// print_r($tmp);
+ $table['data'][]=$tmp;
+}
+
+$rep->addTable($table);
+$rep->output();
+
+?>
diff --git a/admin/reports_tours.php b/admin/reports_tours.php
new file mode 100644
index 00000000..413fe62d
--- /dev/null
+++ b/admin/reports_tours.php
@@ -0,0 +1,90 @@
+
+/*
+ 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
+ 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.
+*/
+?>
+
+ require("../common.inc.php");
+ auth_required('admin');
+ require("../lpdf.php");
+ require("../lcsv.php");
+
+ if(!$_GET['type']) $type="csv";
+ else $type=$_GET['type'];
+
+if($type=="pdf")
+{
+ $rep=new lpdf( i18n($config['fairname']),
+ i18n("Available Tours"),
+ $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
+ );
+
+ $rep->newPage();
+ $rep->setFontSize(11);
+}
+else if($type=="csv")
+{
+ $rep=new lcsv(i18n("Available Tours"));
+}
+
+$table=array();
+$table['header']=array( i18n("ID"),
+ i18n("Name"),
+ i18n("Description"),
+ i18n("Capacity"),
+ i18n("Minimum Grade"),
+ i18n("Maximum Grade"));
+
+
+$q=mysql_query("SELECT *
+ FROM
+ tours
+ WHERE
+ year='".$config['FAIRYEAR']."'
+ ORDER BY
+ id");
+while($r=mysql_fetch_object($q))
+{
+
+// print_r($judge_divs);
+// print_r($judge_subdivs);
+
+ $n = str_replace("\r","", $r->name);
+ $n = str_replace("\n","", $n);
+ $d = str_replace("\r","", $r->description);
+ $d = str_replace("\n","", $d);
+
+ $tmp=array(
+ $r->id,
+ mysql_escape_string($n),
+ mysql_escape_string($d),
+ $r->capacity,
+ $r->grade_min,
+ $r->grade_max
+ );
+// print_r($tmp);
+ $table['data'][]=$tmp;
+}
+
+$rep->addTable($table);
+$rep->output();
+
+?>
diff --git a/admin/tours_manager.php b/admin/tours_manager.php
new file mode 100644
index 00000000..96d37f1f
--- /dev/null
+++ b/admin/tours_manager.php
@@ -0,0 +1,65 @@
+
+/*
+ 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
+ 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.
+*/
+?>
+
+ require("../common.inc.php");
+ auth_required('admin');
+ require("../tours.class.php");
+ require("../tableeditor.class.php");
+
+ send_header("Administration - Tours - Manager");
+?>
+
+
+
+ echo "<< ".i18n("Back to Administration")."\n";
+ echo "<< ".i18n("Back to Tours")."\n";
+
+ $icon_path = $config['SFIABDIRECTORY']."/images/16/";
+ $icon_exitension = $config['icon_extension'];
+
+ print("
");
+
+ $editor = new TableEditor('tours');
+
+// $editor->setDebug(true);
+ $editor->filterList("(tours.year={$config['FAIRYEAR']} OR tours.year IS NULL)");
+
+ $editor->execute();
+
+
+ send_footer();
+?>
diff --git a/db/db.code.version.txt b/db/db.code.version.txt
index bb95160c..a7873645 100644
--- a/db/db.code.version.txt
+++ b/db/db.code.version.txt
@@ -1 +1 @@
-33
+34
diff --git a/db/db.update.34.sql b/db/db.update.34.sql
new file mode 100644
index 00000000..37c618be
--- /dev/null
+++ b/db/db.update.34.sql
@@ -0,0 +1,41 @@
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `tours` and `tours_choice`
+--
+
+CREATE TABLE `tours` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `year` int(10) unsigned NOT NULL default '0',
+ `name` tinytext NOT NULL,
+ `description` text NOT NULL,
+ `capacity` int(11) NOT NULL default '0',
+ `grade_min` int(11) NOT NULL default '7',
+ `grade_max` int(11) NOT NULL default '12',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+
+
+CREATE TABLE `tours_choice` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `students_id` int(10) unsigned NOT NULL default '0',
+ `registrations_id` int(10) unsigned NOT NULL default '0',
+ `tour_id` int(10) unsigned NOT NULL default '0',
+ `year` int(11) NOT NULL default '0',
+ `rank` int(11) NOT NULL default '0',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+
+
+--
+-- Dumping data for table `config`
+--
+
+INSERT INTO `config` (`var`, `val`, `description`, `year`) VALUES
+
+('tours_enable', 'no', 'Tours', 0, 'Enable the "tours" module. Set to "yes" to allow participants to select tours', -1),
+('tours_choices_min', '1', 'Tours', 100, 'Minimum number of tours a participant must select', -1),
+('tours_choices_max', '3', 'Tours', 200, 'Maximum number of tours a participant may select', -1);
+
+
+
diff --git a/register_participants.inc.php b/register_participants.inc.php
index 6e4c1694..c666311d 100644
--- a/register_participants.inc.php
+++ b/register_participants.inc.php
@@ -236,5 +236,24 @@ function spawardStatus($reg_id="")
return "incomplete";
}
+function tourStatus($reg_id="")
+{
+ global $config;
+
+ if($reg_id) $rid=$reg_id;
+ else $rid=$_SESSION['registration_id'];
+
+ //grab all of their tour prefs
+ $q=mysql_query("SELECT * FROM tours_choice WHERE registrations_id='$rid' and year='{$config['FAIRYEAR']}'");
+
+ $n_tours = mysql_num_rows($q);
+
+ if( ($n_tours >= $config['tours_choices_min']) && ($n_tours <= $config['tours_choices_max']) ){
+ return "complete";
+ }
+ return "incomplete";
+}
+
+
?>
diff --git a/register_participants_main.php b/register_participants_main.php
index 3835b347..581aec17 100644
--- a/register_participants_main.php
+++ b/register_participants_main.php
@@ -165,6 +165,23 @@ echo "";
echo outputStatus($statussafety);
echo " |
";
+ if($config['tours_enable']=="yes") {
+ echo "";
+ echo "";
+ echo i18n("Tour Selection");
+ echo "";
+ echo " | ";
+ //check to see if its complete
+ $statustour=tourStatus();
+ echo outputStatus($statustour);
+ echo " |
";
+ } else {
+ $statustour = "complete";
+ }
+
+
+
+
//FIXME: this should be a global detection so we can use the results elsewhere, especially for all the reports!
if(function_exists("pdf_new"))
$sigfile="register_participants_signature.php";
diff --git a/register_participants_tours.php b/register_participants_tours.php
new file mode 100644
index 00000000..429a45d2
--- /dev/null
+++ b/register_participants_tours.php
@@ -0,0 +1,237 @@
+
+/*
+ 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
+ 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.
+*/
+?>
+
+ require("common.inc.php");
+ include "register_participants.inc.php";
+
+ //authenticate based on email address and registration number from the SESSION
+ if(!$_SESSION['email'])
+ {
+ header("Location: register_participants.php");
+ exit;
+ }
+ if(!$_SESSION['registration_number'])
+ {
+ header("Location: register_participants.php");
+ exit;
+ }
+
+ $q=mysql_query("SELECT registrations.id AS regid, students.id AS studentid, students.firstname FROM registrations,students ".
+ "WHERE students.email='".$_SESSION['email']."' ".
+ "AND registrations.num='".$_SESSION['registration_number']."' ".
+ "AND registrations.id='".$_SESSION['registration_id']."' ".
+ "AND students.registrations_id=registrations.id ".
+ "AND registrations.year=".$config['FAIRYEAR']." ".
+ "AND students.year=".$config['FAIRYEAR']);
+echo mysql_error();
+
+ if(mysql_num_rows($q)==0)
+ {
+ header("Location: register_participants.php");
+ exit;
+
+ }
+ $authinfo=mysql_fetch_object($q);
+
+
+ //send the header
+ send_header("Participant Registration - Tour Information");
+
+ echo "<< ".i18n("Back to Participant Registration Summary")."
";
+ echo "
";
+
+ if($_POST['action']=="save")
+ {
+// if(registrationFormsReceived())
+// {
+// echo error(i18n("Cannot make changes to forms once they have been received by the fair"));
+// }
+// else
+ if(registrationDeadlinePassed())
+ {
+ echo error(i18n("Cannot make changes to forms after registration deadline"));
+ }
+ else
+ {
+ //first we will delete all their old answer, its easier to delete and re-insert in this case then it would be to find the corresponding answers and update them
+ mysql_query("DELETE FROM tours_choice WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
+ if(is_array($_POST['toursel']))
+ {
+ foreach($_POST['toursel'] AS $students_id=>$ts)
+ {
+ foreach($ts AS $rank=>$tid) {
+ if($tid == -1) continue;
+
+ mysql_query("INSERT INTO tours_choice (registrations_id,students_id,tour_id,year,rank) VALUES (".
+ "'".$_SESSION['registration_id']."', ".
+ "'".intval($students_id)."', ".
+ "'".intval($tid)."', ".
+ "'".$config['FAIRYEAR']."', ".
+ "'".intval($rank)."')");
+ echo mysql_error();
+ }
+
+ }
+ }
+ }
+ }
+
+ if($_POST['action']=="volunteer") {
+ $vname = mysql_escape_string(stripslashes($_POST['vname']));
+ $vemail = mysql_escape_string(stripslashes($_POST['vemail']));
+ mysql_query("INSERT INTO tours_volunteers (registrations_id,name,email,year) VALUES (".
+ "'".$_SESSION['registration_id']."', ".
+ "'".$vname."', ".
+ "'".$vemail."', ".
+ "'".$config['FAIRYEAR']."'); ");
+ echo happy(i18n("Tour volunteer added. They will be contacted soon."));
+
+ }
+
+
+//output the current status
+$newstatus=tourStatus();
+if($newstatus!="complete")
+{
+ echo error(i18n("Tour Selection Incomplete. You must select your tour preferences!"));
+}
+else if($newstatus=="complete")
+{
+ echo happy(i18n("Tour Selection Complete"));
+
+}
+
+
+ $q=mysql_query("SELECT * FROM tours_choice WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
+ while($r=mysql_fetch_object($q))
+ {
+ $tour_choice[$r->students_id][$r->rank] = $r->tour_id;
+ }
+
+ $tours = array();
+ $q=mysql_query("SELECT * FROM tours WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
+ if(mysql_num_rows($q) == 0)
+ {
+ echo notice(i18n("There is not tour information"));
+ send_footer();
+ exit;
+ }
+
+ while($r=mysql_fetch_object($q))
+ {
+ $tours[$r->id]['name'] = $r->name;
+ $tours[$r->id]['description'] = $r->description;
+ $tours[$r->id]['capacity'] = $r->capacity;
+ $tours[$r->id]['grade_min'] = $r->grade_min;
+ $tours[$r->id]['grade_max'] = $r->grade_max;
+ }
+
+
+ $min = $config['tours_choices_min'];
+ $max = $config['tours_choices_max'];
+
+/*
+ if($min == $max) {
+ $t = i18n("Please select %1 tour(s)", array($min));
+ } else if($min == 1) {
+ $t = i18n("Please select up to %1 tours", array($max));
+ } else {
+ $t = i18n("Please select between %1 and %2 tours", array($min, $max));
+ }
+ echo $t." ";
+ echo i18n("by placing a number from 1 (highest preference) to %1 (lowest preference) beside the tours you select", array($config['tours_choices_max']) );
+*/
+
+ echo "";
+
+ echo "
";
+ echo "".i18n("Tour Descriptions")."
";
+
+ /* Dump the tours */
+ foreach($tours as $id=>$t) {
+ echo i18n("Tour Name").": ".i18n($t['name'])."
";
+ echo i18n("Grade").": ".$t['grade_min']." - ".$t['grade_max'].", ";
+ echo i18n("Capacity").": ".$t['capacity']." ".i18n("students")."
";
+ echo i18n($t['description'])."
";
+
+ }
+
+
+/*
+ echo "Add A Parent/Teacher Volunteer for Tour Day
";
+ echo "If you have a parent / teacher who would like to accompany a group of students on a UBC tour (ask your parents right now and see if they want to volunteer on a tour!), please enter their name and email address below, and click on the Submit Volunteer button. The GVRSF will contact them by email to confirm additional details.";
+ echo "
";
+*/
+ send_footer();
+?>
diff --git a/tours.class.php b/tours.class.php
new file mode 100644
index 00000000..ed8f42fa
--- /dev/null
+++ b/tours.class.php
@@ -0,0 +1,143 @@
+
+
+/* Just the fields in the tours table, we use this twice */
+$tours_fields = array( 'name' => 'Tour Name',
+ 'description' => 'Description',
+ 'capacity' => 'Capacity',
+ 'grade_min' => 'Minimum Grade',
+ 'grade_max' => 'Maximum Grade',
+ 'year' => 'Year');
+
+class tours {
+
+/* Static members for the table editor */
+function tableEditorSetup($editor)
+{
+ global $tours_fields;
+ global $config;
+
+ /* Setup the table editor with the fields we want to display
+ * when displaying a list of tours, and also the type of each
+ * field where required */
+ $l = array( 'id' => 'ID',
+ 'name' => 'Tour Name',
+ 'capacity' => 'Capacity',
+ 'grade_min' => 'Minimum Grade',
+ 'grade_max' => 'Maximum Grade',
+ 'year' => 'Year',
+ );
+
+ /* Most of these should be moved to the base class, as they
+ * will be the same for all person groups */
+
+ $editor->setTable('tours');
+ $editor->setRecordType('Tour');
+ $editor->setListFields($l);
+ $editor->setEditFields($tours_fields);
+
+ $editor->setFieldOptions('year', array(
+ array('key' => 'NULL', 'val' => 'Inactive'),
+ array('key' => $config['FAIRYEAR'], 'val' => $config['FAIRYEAR'])));
+
+// print_r($e);
+ print("
\n");
+ /* Build an array of langauges that we support */
+
+ $gradechoices=array(
+ array('key' => 7, 'val' => "Grade 7"),
+ array('key' => 8, 'val' => "Grade 8"),
+ array('key' => 9, 'val' => "Grade 9"),
+ array('key' => 10, 'val' => "Grade 10"),
+ array('key' => 11, 'val' => "Grade 11"),
+ array('key' => 12, 'val' => "Grade 12") );
+
+ $editor->setFieldOptions("grade_min", $gradechoices);
+ $editor->setFieldInputType("grade_min", 'select');
+ $editor->setFieldOptions("grade_max", $gradechoices);
+ $editor->setFieldInputType("grade_max", 'select');
+}
+
+/* Functions for $this */
+
+
+function tours($tour_id=NULL)
+{
+ if($tour_id == NULL) {
+ $this->id = FALSE;
+ } else {
+ $this->id = $tour_id;
+ }
+}
+
+function tableEditorLoad()
+{
+ global $config;
+
+ $id = $this->id;
+
+// print("Loading Judge ID $id\n");
+
+ $q=mysql_query("SELECT tours.*
+ FROM tours
+ WHERE tours.id='$id'");
+ echo mysql_error();
+
+
+ /* We assume that the field names in the array we want to return
+ * are the same as those in the database, so we'll turn the entire
+ * query into a single associative array */
+ $j = mysql_fetch_assoc($q);
+
+ return $j;
+}
+
+function tableEditorSave($data)
+{
+ /* If $this->id == false, then we need to INSERT a new record.
+ * if it's a number, then we want an UPDATE statement */
+ global $tours_fields;
+ global $config;
+
+ $query = "";
+
+ /* Construct an insert query if we have to */
+ if($this->id == false) {
+ $query = "INSERT INTO tours (id) VALUES ('')";
+ mysql_query($query);
+ $this->id = mysql_insert_id();
+ }
+
+ /* Give it a proper year when saving */
+
+ /* Now just update the record */
+ $query="UPDATE `tours` SET ";
+
+ foreach($tours_fields AS $f=>$n) {
+ $n = $data[$f];
+ $query .= "`$f`=$n,";
+ }
+ //rip off the last comma
+ $query=substr($query,0,-1);
+
+ $query .= " WHERE id='{$this->id}'";
+
+// echo $query;
+ mysql_query($query);
+
+}
+
+function tableEditorDelete()
+{
+ global $config;
+
+ $id = $this->id;
+
+ mysql_query("DELETE FROM tours_choice WHERE tour_id='$id' AND year=".$config['FAIRYEAR']."'");
+ mysql_query("DELETE FROM tours WHERE id='$id' AND year='".$config['FAIRYEAR']."'");
+
+ echo happy(i18n("Successfully removed tour from this year's fair"));
+}
+
+};
+
+?>