From 6fc83836af2da02b76470b77cdc3122d24ae6be8 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 31 Jul 2006 18:17:37 +0000 Subject: [PATCH] Implemented a judges division editor, to be used before the automatic judge scheduler to set groups of divisions that judges can judge within. --- admin/judges.php | 1 + admin/judges_jdiv.php | 285 +++++++++++++++++++++++++++++++++++++++++ db/db.code.version.txt | 2 +- db/db.update.20.sql | 15 +++ questions.inc.php | 13 ++ 5 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 admin/judges_jdiv.php create mode 100644 db/db.update.20.sql diff --git a/admin/judges.php b/admin/judges.php index 57ed666..a3a0306 100644 --- a/admin/judges.php +++ b/admin/judges.php @@ -42,6 +42,7 @@ echo "".i18n("Assign Projects to Teams")."
"; echo "
"; + echo "".i18n("Manage Divisional Judging Groupings")."
"; echo "".i18n("Judging automatic scheduler")."
"; send_footer(); diff --git a/admin/judges_jdiv.php b/admin/judges_jdiv.php new file mode 100644 index 0000000..77fdb64 --- /dev/null +++ b/admin/judges_jdiv.php @@ -0,0 +1,285 @@ + + 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. +*/ +?> + + + +id]=$r->division_shortform; + $div[$r->id]=$r->division; + } + + $cat = array(); + $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); + while($r=mysql_fetch_object($q)) { + $cat[$r->id]=$r->category; + } + + $langr = array(); + $q=mysql_query("SELECT * FROM languages WHERE active='Y'"); + while($r=mysql_fetch_object($q)) { + $langr[$r->lang] = $r->langname; + } + + +function get_all_divs() +{ + global $config; + global $divshort, $div,$cat, $langr; + + $cdlcheck = array(); + $cdl = array(); + $q=mysql_query("SELECT * FROM judges_jdiv"); + while($r=mysql_fetch_object($q)) { + $cdl[$r->id]['id'] = $r->id; + $cdl[$r->id]['jdiv'] = $r->jdiv_id; + $cdl[$r->id]['div'] = $r->projectdivisions_id; + $cdl[$r->id]['cat'] = $r->projectcategories_id; + $cdl[$r->id]['lang'] = $r->lang; + + $cdlcheck[$r->projectcategories_id][$r->projectdivisions_id][$r->lang] = 1; + } + + /* Check for missing cdls */ + $divkeys = array_keys($divshort); + $catkeys = array_keys($cat); + $lankeys = array_keys($langr); + foreach($catkeys as $x) { + foreach($divkeys as $y) { + foreach($lankeys as $z) { + if($cdlcheck[$x][$y][$z] == 1) + continue; + + /* Also, make an entry in the DB, so that this isn't + * unassigned anymore */ + mysql_query("INSERT INTO judges_jdiv (id, jdiv_id, projectdivisions_id, projectcategories_id, lang) ". + " VALUES('', 0, '$y', '$x', '$z')"); + $q = mysql_query("SELECT id FROM judges_jdiv WHERE ". + " projectdivisions_id='$y' ". + " AND projectcategories_id='$x' ". + " AND lang='$z' "); + $r = mysql_fetch_object($q); + + $cdl[$r->id]['id'] = $r->id; + $cdl[$r->id]['jdiv'] = 0; /* Unassigned */ + $cdl[$r->id]['cat'] = $x; + $cdl[$r->id]['div'] = $y; + $cdl[$r->id]['lang'] = $z; + + } + reset($lankeys); + } + reset($catkeys); + } + reset($divkeys); + + /* Make names for all the DCLs, and count the number of projects */ + $dkeys = array_keys($cdl); + foreach($dkeys as $id) { + $x = $cat[$cdl[$id]['cat']]; + $y = $divshort[$cdl[$id]['div']]; + $z = $div[$cdl[$id]['div']]; + $q = mysql_query("SELECT count(id) AS cnt FROM projects WHERE ". + " projectdivisions_id='{$cdl[$id]['div']}' ". + " AND projectcategories_id='{$cdl[$id]['cat']}' ". + " AND language='{$cdl[$id]['lang']}' ". + " AND year='{$config['FAIRYEAR']}' "); + + $r = mysql_fetch_object($q); + $c = $r->cnt; + + $cdl[$id]['name'] = "$x $y ({$cdl[$id]['lang']}) ($c project".($c==1?'':'s').")"; + $cdl[$id]['lname'] = "$x $z ({$cdl[$id]['lang']}) ($c project".($c==1?'':'s').")"; + $cdl[$id]['projects'] = $c; + } + return $cdl; +} + + echo "<< ".i18n("Back to Administration")."\n"; + echo "<< ".i18n("Back to Judges")."\n"; + + if($_POST['action']=="add" && $_POST['jdiv_id'] && count($_POST['cdllist'])>0) + { + foreach($_POST['cdllist'] AS $selectedcdl) { + $q=mysql_query("UPDATE judges_jdiv SET jdiv_id='{$_POST['jdiv_id']}' WHERE ". + " id='$selectedcdl' "); + } + echo happy(i18n("Judging Division(s) successfully added")); + } + + if($_GET['action']=="del" && $_GET['cdl_id']) { + mysql_query("UPDATE judges_jdiv SET jdiv_id=0 WHERE id='{$_GET['cdl_id']}'"); + } + + if($_GET['action']=="empty" && $_GET['jdiv_id']) { + mysql_query("UPDATE judges_jdiv SET jdiv_id=0 WHERE jdiv_id='{$_GET['jdiv_id']}' "); + echo happy(i18n("Emptied all divisions from Judging Division Group %1",array($_GET['jdiv_id']))); + } + + + /* Sort out all the judging divisions */ + $cdl = get_all_divs(); + + $dkeys = array_keys($cdl); + + /* Count the divisions, or, use the posted variable so we can create new + * and empty judging divisions */ + if($_POST['jdivs'] > 0) { + $jdivs = $_POST['jdivs']; + } else { + $jdivs = 0; + foreach($dkeys as $d) { + if($cdl[$d]['jdiv'] > $jdivs) $jdivs = $cdl[$d]['jdiv']; + } + } + + + echo "
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
".i18n("Division List"); + echo "
"; + echo "
".i18n("Judging Division Groups")."
"; +// echo ""; +// echo "
"; + + + + echo ""; + echo "
"; + + /* Print he groupings of the assigned ones */ + for($jdiv = 1; $jdiv <= $jdivs; $jdiv++) { + echo "
"; + + echo ""; + echo "
"; + echo "
"; + echo "
"; + echo ""; + echo ""; + echo " ".i18n("Empty")." "; + echo ""; + + + echo "
"; + + $p = 0; + reset($dkeys); + foreach($dkeys as $id) { + if($cdl[$id]['jdiv'] != $jdiv) continue; + $p += $cdl[$id]['projects']; + } + + echo "\n"; + echo "\n"; + + $x = 0; + reset($dkeys); + foreach($dkeys as $id) { + if($cdl[$id]['jdiv'] != $jdiv) continue; + + echo ""; + $x++; + + } + + if($x) { + echo ""; + } else { + echo ""; + } + + echo "
Judging Division $jdiv ($p project".($p==1?'':'s').")"; + echo "
"; + echo ""; + echo ""; + + echo $cdl[$id]['lname']; + echo "
"; +// echo ""; +// echo " ".i18n("Empty All Divisions")." "; +// echo ""; +// echo ""; + echo "
"; + echo error(i18n("No divisions present"),"inline"); + echo "
"; + + echo "
"; + } + echo "
"; + + echo "
"; + + echo "
"; + echo "
"; + + send_footer(); + + + +?> diff --git a/db/db.code.version.txt b/db/db.code.version.txt index d6b2404..209e3ef 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -19 +20 diff --git a/db/db.update.20.sql b/db/db.update.20.sql new file mode 100644 index 0000000..f963795 --- /dev/null +++ b/db/db.update.20.sql @@ -0,0 +1,15 @@ +-- -------------------------------------------------------- + +-- +-- Table structure for table `judges_jdiv` +-- + +CREATE TABLE `judges_jdiv` ( + `id` int(10) unsigned NOT NULL auto_increment, + `jdiv_id` int(11) NOT NULL default '0', + `projectdivisions_id` int(11) NOT NULL default '0', + `projectcategories_id` int(11) NOT NULL default '0', + `lang` char(2) NOT NULL default '', + PRIMARY KEY (`id`) +) TYPE=MyISAM; + diff --git a/questions.inc.php b/questions.inc.php index e0b9d9e..167767a 100644 --- a/questions.inc.php +++ b/questions.inc.php @@ -89,6 +89,19 @@ function questions_save_answers($section, $id, $year, $answers) } } +function questions_find_question_id($section, $year, $dbheading) +{ + $q = mysql_query("SELECT id FROM questions WHERE ". + " section='$section' ". + " AND year='$year' ". + " AND db_heading='$dbheading' "); + if(mysql_num_rows($q) == 1) { + $r = mysql_fetch_object($q); + return $r->id; + } + return 0; +} + function questions_print_answer_editor($section, $id, $year, $array_name) {