Add Tour selection.

- Admin can use the tour manager to add tours
- Admin can use the config variables to enable tours, and select the min/max number of tour choices.
- Students will see a "Tour Selection" section of registration, which is incomplete until the student has selected at least a minimum number of tours.... actually, this may be broken.. Need to look at it further..
This commit is contained in:
dave 2007-01-09 19:05:23 +00:00
parent 2d17c8c21a
commit 900dab702d
11 changed files with 746 additions and 1 deletions

View File

@ -35,6 +35,9 @@
echo "<a href=\"schools.php\">".i18n("School Management")."</a> <br />";
echo "<a href=\"judges.php\">".i18n("Judging Management")."</a> <br />";
echo "<a href=\"translations.php\">".i18n("Translations Management")."</a> <br />";
if($config['tours_enable'] == 'yes') {
echo "<a href=\"tours_manager.php\">".i18n("Tour Management")."</a> <br />";
}
echo "<hr />";
echo "<a href=\"winners.php\">".i18n("Enter Winning Projects")."</a> <br />";
echo "<a href=\"cwsfregister.php\">".i18n("One-Click CWSF Registration")."</a> <br />";

View File

@ -106,10 +106,27 @@ echo "</table>";
echo "<a href=\"reports_projects_judges_teams.php?type=csv\">CSV</a> &nbsp; ";
echo "<a href=\"reports_projects_judges_teams.php?type=pdf\">PDF</a> &nbsp; ";
echo "<br />";
echo "<br />";
echo i18n("Award Ceremony Script").": ";
echo "<a href=\"reports_acscript.php?type=pdf\">PDF</a> &nbsp; ";
echo "<a href=\"reports_acscript.php?type=csv\">CSV</a> &nbsp; ";
if($config['tours_enable'] == 'yes') {
echo "<br />";
echo "<br />";
echo i18n("Available Tours").": ";
echo "<a href=\"reports_tours.php?type=csv\">CSV</a> &nbsp; ";
echo "<br />";
echo i18n("Participant Tour Choices").": ";
echo "<a href=\"reports_tour_selection.php?type=csv\">CSV</a> &nbsp; ";
echo "<br />";
// echo i18n("Tour Volunteers").": ";
// echo "<a href=\"reports_tour_volunteers.php?type=csv\">CSV</a> &nbsp; ";
// echo "<br />";
}
send_footer();
?>

View File

@ -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 <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.
*/
?>
<?
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();
?>

90
admin/reports_tours.php Normal file
View File

@ -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 <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.
*/
?>
<?
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();
?>

65
admin/tours_manager.php Normal file
View File

@ -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 <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.
*/
?>
<?
require("../common.inc.php");
auth_required('admin');
require("../tours.class.php");
require("../tableeditor.class.php");
send_header("Administration - Tours - Manager");
?>
<script language="javascript" type="text/javascript">
function opentoursinfo(id)
{
if(id)
currentid=id;
else
currentid=document.forms.tours["tourslist[]"].options[document.forms.tours["tourslist[]"].selectedIndex].value;
window.open("tours_info.php?id="+currentid,"JudgeInfo","location=no,menubar=no,directories=no,toolbar=no,width=770,height=500,scrollbars=yes");
return false;
}
</script>
<?
echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Administration")."</a>\n";
echo "<a href=\"tours.php\">&lt;&lt; ".i18n("Back to Tours")."</a>\n";
$icon_path = $config['SFIABDIRECTORY']."/images/16/";
$icon_exitension = $config['icon_extension'];
print("<br /><br />");
$editor = new TableEditor('tours');
// $editor->setDebug(true);
$editor->filterList("(tours.year={$config['FAIRYEAR']} OR tours.year IS NULL)");
$editor->execute();
send_footer();
?>

View File

@ -1 +1 @@
33
34

41
db/db.update.34.sql Normal file
View File

@ -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);

View File

@ -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";
}
?>

View File

@ -165,6 +165,23 @@ echo "<table><tr><td>";
echo outputStatus($statussafety);
echo "</td></tr>";
if($config['tours_enable']=="yes") {
echo "<tr><td>";
echo "<a href=\"register_participants_tours.php\">";
echo i18n("Tour Selection");
echo "</a>";
echo "</td><td>";
//check to see if its complete
$statustour=tourStatus();
echo outputStatus($statustour);
echo "</td></tr>";
} 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";

View File

@ -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 <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.
*/
?>
<?
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 "<a href=\"register_participants_main.php\">&lt;&lt; ".i18n("Back to Participant Registration Summary")."</a><br />";
echo "<br />";
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 "<form method=\"post\" action=\"register_participants_tours.php\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
echo "<table>\n";
$q=mysql_query("SELECT * FROM students WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
$num_found = mysql_num_rows($q);
while($r=mysql_fetch_object($q)) {
echo "<tr><td colspan=2>";
echo i18n("Tour Selection for")." <b>".$r->firstname." ".$r->lastname;
echo "</b></td></tr>";
for($x=0;$x<$max;$x++) {
echo "<tr><td align=right>";
$rank = $x+1;
if($x==0) echo i18n("(most preferred)")." ";
echo i18n("Choice")." $rank:";
echo "</td><td>";
echo "<select name='toursel[{$r->id}][$rank]'>";
echo "<option $sel value=\"-1\">".i18n("Choose")."</option>";
foreach($tours as $id=>$t) {
$sel = "";
if($tour_choice[$r->id][$rank] == $id)
$sel = "selected=selected";
echo "<option $sel value=\"$id\">{$t['name']}</option>";
}
echo "</select>";
echo "</td></tr>";
}
echo "<tr><td>&nbsp;</td><td></td></tr>";
}
echo ("</table");
/*
$rank = $tour_choice[$r->id];
if($rank < 1 || $rank > $max) $rank = "--";
echo "<tr><td><input type=\"text\" size=2 name=\"tours[$r->id]\" value=\"$rank\" />";
echo "<td>(tour&nbsp;$num). </td><td>";
echo i18n($r->description)."</td>";
echo "</tr>";
$num++;
*/
echo "<input type=\"submit\" value=\"".i18n("Save Tour Choices")."\" />\n";
echo "</form>";
echo "<br /><br />";
echo "<h4>".i18n("Tour Descriptions")."</h4><br />";
/* Dump the tours */
foreach($tours as $id=>$t) {
echo i18n("Tour Name").": <b>".i18n($t['name'])."</b><br />";
echo i18n("Grade").": <b>".$t['grade_min']." - ".$t['grade_max']."</b>, ";
echo i18n("Capacity").": <b>".$t['capacity']."</b> ".i18n("students")."<br />";
echo i18n($t['description'])."<br /><br />";
}
/*
echo "<h3>Add A Parent/Teacher Volunteer for Tour Day </h3><br />";
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 "<form method=\"post\" action=\"register_participants_tours.php\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"volunteer\">\n";
echo "Name: <input type=\"text\" name=\"vname\" /><br />";
echo "Email: <input type=\"text\" name=\"vemail\" /><br />";
echo "<input type=\"submit\" value=\"".i18n("Submit Volunteer")."\" />\n";
echo "</form><br />";
*/
send_footer();
?>

143
tours.class.php Normal file
View File

@ -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("<br>\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"));
}
};
?>