From a20dfdbd7a5e3e9a590252fa30cd0fc690fcbb3f Mon Sep 17 00:00:00 2001 From: james Date: Wed, 1 Feb 2006 16:29:08 +0000 Subject: [PATCH] Merge Jamie's changes from Peterborough, allowing different divisions to be available to the different age categories. -- default is 'no' --- config/categories.php | 6 ++- config/divisions.php | 71 ++++++++++++++++++++++++++++++- db/db.update.13.sql | 9 ++++ register_participants_project.php | 8 +++- 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/config/categories.php b/config/categories.php index 2ab9d69..70fd291 100644 --- a/config/categories.php +++ b/config/categories.php @@ -85,7 +85,11 @@ if($_GET['action']=="remove" && $_GET['remove']) { - mysql_query("DELETE FROM projectcategories WHERE id='".$_GET['remove']."'"); + //###### Feature Specific - filtering divisions by category - not conditional, cause even if they have the filtering turned off..if any links + //for this division exist they should be deleted + mysql_query("DELETE FROM projectcategoriesdivisions_link where projectcategories_id='".$_GET['remove']."' AND year='".$config['FAIRYEAR']."'"); + //#### + mysql_query("DELETE FROM projectcategories WHERE id='".$_GET['remove']."' AND year='".$config['FAIRYEAR']."'"); echo happy(i18n("Category successfully removed")); } diff --git a/config/divisions.php b/config/divisions.php index 58acbb5..0d327c9 100644 --- a/config/divisions.php +++ b/config/divisions.php @@ -43,6 +43,20 @@ "division='".mysql_escape_string(stripslashes($_POST['division']))."', ". "division_shortform='".mysql_escape_string(stripslashes($_POST['division_shortform']))."' ". "WHERE id='".$_POST['saveid']."'"); + + //###### Feature Specific - filtering divisions by category + if($config['filterdivisionbycategory']=="yes"){ + mysql_query("DELETE FROM projectcategoriesdivisions_link WHERE projectdivisions_id='".$_POST['saveid']."' AND year='".$config['FAIRYEAR']."'"); + + foreach($_POST['divcat'] as $tempcat){ + mysql_query("INSERT INTO projectcategoriesdivisions_link (projectdivisions_id,projectcategories_id,year) VALUES ( ". + "'".$_POST['id']."', ". + "'".$tempcat."', ". + "'".$config['FAIRYEAR']."') "); + } + } + //########### + echo happy(i18n("Division successfully saved")); } } @@ -68,6 +82,17 @@ "'".mysql_escape_string(stripslashes($_POST['division']))."', ". "'".mysql_escape_string(stripslashes($_POST['division_shortform']))."', ". "'".$config['FAIRYEAR']."') "); + + + //###### Feature Specific - filtering divisions by category + if($config['filterdivisionbycategory']=="yes"){ + foreach($_POST['divcat'] as $tempcat){ + mysql_query("INSERT INTO projectcategoriesdivisions_link (projectdivisions_id,projectcategories_id,year) VALUES ( ". + "'".$tempcat."', ". + "'".$config['FAIRYEAR']."') "); + } + } + //####### echo happy(i18n("Division successfully added")); } } @@ -79,7 +104,10 @@ if($_GET['action']=="remove" && $_GET['remove']) { - mysql_query("DELETE FROM projectdivisions WHERE id='".$_GET['remove']."'"); + //###### Feature Specific - filtering divisions by category - not conditional, cause even if they have the filtering turned off..if any links + //for this division exist they should be deleted + mysql_query("DELETE FROM projectcategoriesdivisions_link where projectdivisions_id='".$_GET['remove']."' AND year='".$config['FAIRYEAR']."'"); + mysql_query("DELETE FROM projectdivisions WHERE id='".$_GET['remove']."' AND year='".$config['FAIRYEAR']."'"); echo happy(i18n("Division successfully removed")); } @@ -95,6 +123,10 @@ echo "".i18n("Division ID")."\n"; echo "".i18n("Division Name")."\n"; echo "".i18n("Short Form")."\n"; +//###### Feature Specific - filtering divisions by category + if($config['filterdivisionbycategory']=="yes") + echo "".i18n("Categories")."\n"; +//##### echo "".i18n("Actions")."\n"; echo ""; @@ -116,6 +148,23 @@ echo " id\" />"; echo " division\" />"; echo " division_shortform\" />"; + + //###### Feature Specific - filtering divisions by category + if($config['filterdivisionbycategory']=="yes"){ + echo " "; + $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY mingrade"); + while($categoryr=mysql_fetch_object($q)){ + $query="SELECT * FROM projectcategoriesdivisions_link WHERE projectdivisions_id=".$divisionr->id." AND projectcategories_id=".$categoryr->id." AND year='".$config['FAIRYEAR']."'"; + $t=mysql_query($query); + if($t && mysql_num_rows($t)>0) + echo "id\" checked=\"checked\" /> $categoryr->category
"; + else + echo "id\" /> $categoryr->category
"; + + } + echo ""; + } + echo " "; echo ""; } @@ -128,6 +177,26 @@ echo " $r->id"; echo " ".i18n($r->division).""; echo " $r->division_shortform"; + //###### Feature Specific - filtering divisions by category + if($config['filterdivisionbycategory']=="yes"){ + + $c=mysql_query("SELECT category FROM projectcategoriesdivisions_link, projectcategories + WHERE projectcategoriesdivisions_link.projectcategories_id = projectcategories.id + AND projectdivisions_id='$r->id' + AND projectcategoriedivisions_link.year='".$config['FAIRYEAR']."' + ORDER BY projectcategories.mingrade"); + if(!$c){ + $tempcat=" "; + }else{ + $tempcat=""; + while($categoryr=mysql_fetch_object($c)){ + $tempcat.=",".$categoryr->category; + } + $tempcat=substr($tempcat,1); + } + echo " {$tempcat} "; + } + //############ echo " "; echo "id\">"; echo "   "; diff --git a/db/db.update.13.sql b/db/db.update.13.sql index dbb04bf..4f08ee6 100644 --- a/db/db.update.13.sql +++ b/db/db.update.13.sql @@ -9,3 +9,12 @@ DELETE FROM `judges_schedulerconfig` WHERE var='timeslot_break'; ALTER TABLE `award_awards` ADD `excludefromac` TINYINT( 1 ) DEFAULT '0' NOT NULL; ALTER TABLE `award_prizes` ADD `excludefromac` TINYINT( 1 ) DEFAULT '0' NOT NULL; UPDATE `config` SET `description`='C=Category, D=Division, N=2 digit Number' WHERE `var`='project_num_format'; +INSERT INTO `config` VALUES ('filterdivisionbycategory', 'no', 'Allows for setup of divisions on a categorical basis. Students can then only choose divisions that apply to their category. Only use if you want to offer a different set of divisions to each age category (no, yes).', -1); +CREATE TABLE `projectcategoriesdivisions_link` ( + `id` int(10) unsigned NOT NULL auto_increment, + `projectdivisions_id` int(10) unsigned NOT NULL default '0', + `projectcategories_id` int(10) unsigned NOT NULL default '0', + `year` int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`id`), + KEY `categories_id` (`projectcategories_id`) +) TYPE=MyISAM; diff --git a/register_participants_project.php b/register_participants_project.php index d74713f..1926fbc 100644 --- a/register_participants_project.php +++ b/register_participants_project.php @@ -195,7 +195,13 @@ function countwords() echo " (".i18n("Grades %1-%2",array($agecategories[$projectcategories_id]['mingrade'],$agecategories[$projectcategories_id]['maxgrade'])).")"; echo ""; echo "".i18n("Division").": "; - $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division"); + +//###### Feature Specific - filtering divisions by category + if($config['filterdivisionbycategory']=="yes"){ + $q=mysql_query("SELECT projectdivisions.* FROM projectdivisions,projectcategoriesdivisions_link WHERE projectdivisions.id=projectdivisions_id AND projectcategories_id=".$projectcategories_id." AND year='".$config['FAIRYEAR']."' ORDER BY division"); +//### +}else + $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division"); echo "