diff --git a/admin/judges_sa.php b/admin/judges_sa.php
index 00f240aa..8935e97c 100644
--- a/admin/judges_sa.php
+++ b/admin/judges_sa.php
@@ -24,6 +24,16 @@
require("../common.inc.php");
auth_required('admin');
+ require("judges_schedulerconfig_check.inc.php");
+
+ send_header("Judging teams automatic scheduler");
+ $ok=checkPrerequisites();
+ if(!$ok)
+ {
+ echo error(i18n("Schduler cannot run until the above problems are resolved. Use the links below each error to resolve the problem"));
+ send_footer();
+ exit;
+ }
function TRACE() { }
//function TRACE($str) { print($str); }
@@ -308,7 +318,10 @@ function judges_assign_anneal($divisions, $categories, $languages, $judges, &$te
$q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
while($r=mysql_fetch_object($q))
+{
+ $divshort[$r->id]=$r->division_shortform;
$div[$r->id]=$r->division;
+}
$q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
while($r=mysql_fetch_object($q))
@@ -513,7 +526,6 @@ judges_assign_anneal($div,$cat, $langr, $judges, $team, $data);
//print_r( $team);
$teamnums=array();
-send_header("Judging teams automatic scheduler");
echo i18n("Judging teams successfully created. You can review the teams and modify as desired using the following links");
echo " ";
echo " ";
@@ -536,7 +548,7 @@ while(list($tn, $t) = each($team)) {
if(!$teamnums[$t['division']][$t['category']]) $teamnums[$t['division']][$t['category']]=1;
else $teamnums[$t['division']][$t['category']]++;
- mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) VALUES ('$tn','(Divisional) {$div[$t['division']]} - {$cat[$t['category']]} #{$teamnums[$t['division']][$t['category']]} ({$t['language']})','1','{$config['FAIRYEAR']}')");
+ mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) VALUES ('$tn','(Div) {$divshort[$t['division']]} - {$cat[$t['category']]} #{$teamnums[$t['division']][$t['category']]} ({$t['language']})','1','{$config['FAIRYEAR']}')");
$team_id=mysql_insert_id();
//use tn-1 since we incremented it at the top :p
$team[$tn-1]['team_id']=$team_id;
diff --git a/admin/judges_schedulerconfig.php b/admin/judges_schedulerconfig.php
index 5ee9c9de..dee0d836 100644
--- a/admin/judges_schedulerconfig.php
+++ b/admin/judges_schedulerconfig.php
@@ -24,7 +24,8 @@
require("../common.inc.php");
auth_required('admin');
- include "judges.inc.php";
+ require("judges.inc.php");
+ require("judges_schedulerconfig_check.inc.php");
send_header("Administration - Judge Scheduler Configuration");
@@ -78,161 +79,10 @@
echo "";
echo "\n";
echo "";
+
echo "
";
- echo i18n("Based on your configuration data above, here are some calculations");
- echo " ";
-$totalteams=0;
-$catq=mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade");
-while($catr=mysql_fetch_object($catq))
-{
- echo "
$catr->category
";
- echo "
";
- echo "
Division
Projects
Teams
";
- $divq=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id");
- while($divr=mysql_fetch_object($divq))
- {
- $langq=mysql_query("SELECT * FROM languages WHERE active='Y'");
- while($langr=mysql_fetch_object($langq))
- {
- $numq=mysql_query("SELECT COUNT(id) AS num FROM projects WHERE projectcategories_id='$catr->id' AND projectdivisions_id='$divr->id' AND year='{$config['FAIRYEAR']}' AND language='$langr->lang'");
- $numr=mysql_fetch_object($numq);
- echo "
";
- echo " ";
- echo " ";
-}
-echo "";
-echo "Total judging teams required: $totalteams";
-echo " ";
-$minjudges=($totalteams*$schedulerconfig['min_judges_per_team']);
-$maxjudges=($totalteams*$schedulerconfig['max_judges_per_team']);
-echo "Minimum number of judges required: $minjudges";
-echo " ";
-echo "Maximum number of judges acceptable: $maxjudges";
-echo " ";
-
-$jq=mysql_query("SELECT COUNT(judges.id) AS num FROM judges,judges_years WHERE complete='yes' AND judges_years.year='{$config['FAIRYEAR']}' AND judges_years.judges_id=judges.id");
-$jr=mysql_fetch_object($jq);
-$currentjudges=$jr->num;
-echo "Current number of registered judges: $currentjudges";
-echo " ";
-echo " ";
-$ok=true;
-if($currentjudges<$minjudges)
-{
- echo error(i18n("You do not have sufficient number of judges based on your parameters"));
- $ok=false;
-}
-else
- echo happy(i18n("You have a sufficient number of judges based on your parameters"));
-
-//now check if we can find a divisional award for each division and category
-
-
-$q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
-while($r=mysql_fetch_object($q))
- $div[$r->id]=$r->division;
-
-$q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
-while($r=mysql_fetch_object($q))
- $cat[$r->id]=$r->category;
-
-$foundawards="";
-$notfoundawards="";
-$foundteams="";
-foreach($div AS $d_id=>$d_division)
-{
- foreach($cat AS $c_id=>$c_category)
- {
- $q=mysql_query("SELECT award_awards.id FROM
- award_awards,
- award_awards_projectcategories,
- award_awards_projectdivisions
- WHERE
- award_awards.year='{$config['FAIRYEAR']}'
- AND award_awards_projectcategories.year='{$config['FAIRYEAR']}'
- AND award_awards_projectdivisions.year='{$config['FAIRYEAR']}'
- AND award_awards.id=award_awards_projectcategories.award_awards_id
- AND award_awards.id=award_awards_projectdivisions.award_awards_id
- AND award_awards_projectcategories.projectcategories_id='$c_id'
- AND award_awards_projectdivisions.projectdivisions_id='$d_id'
- AND award_awards.award_types_id='1'
- ");
- echo mysql_error();
- if(mysql_num_rows($q)!=1)
- {
- while($r=mysql_fetch_object($q))
- print_r($r);
- $notfoundawards.="$c_category - $d_division, ";
- $ok=false;
- }
- else
- {
- $r=mysql_fetch_object($q);
- $foundawards.="$c_category - $d_division, ";
- //if we found an award thats good, but it would be bad if there's already a judges team
- //that is assigned to the award, so now lets check the judges teams to see if ones assigned
- //to this award.
-
- $q=mysql_query("SELECT judges_teams.num,judges_teams.name
- FROM judges_teams,
- judges_teams_awards_link
- WHERE
- judges_teams_awards_link.award_awards_id='$r->id'
- AND judges_teams.year='".$config['FAIRYEAR']."'
- AND judges_teams_awards_link.judges_teams_id=judges_teams.id");
- if(mysql_num_rows($q))
- {
- $r=mysql_fetch_object($q);
- $ok=false;
- $foundteams.=i18n("(%1) %2, ",array($r->num,$r->name));
- }
- }
- }
-}
-$notfoundawards=substr($notfoundawards,0,-2);
-$foundawards=substr($foundawards,0,-2);
-$foundteams=substr($foundteams,0,-2);
-
-if($notfoundawards)
- echo error(i18n("Cannot find awards for: %1. These awards must be created first",array($notfoundawards)));
-if($foundawards)
- echo happy(i18n("Found awards for: %1",array($foundawards)));
-if($foundteams)
-{
- echo error(i18n("Found judging teams that are currently assigned to divisional awards: %1. These teams must be removed first",array($foundteams)));
- echo " ".i18n("Judging Teams Manager")."";
-}
-else
- echo happy(i18n("No judging teams are assigned to divisional awards (good!)"));
-
-//now check if we have enough timeslots available...
-
-$q=mysql_query("SELECT COUNT(id) AS num FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' AND allowdivisional='yes'");
-$r=mysql_fetch_object($q);
-$numslots=$r->num;
-
-if($numslots<$schedulerconfig['max_projects_per_team'])
-{
- echo error(i18n("You do not have enough judging timeslots available for divisional judging. Please create more timeslots first. Available: %1, Required: %2",array($numslots,$schedulerconfig['max_projects_per_team'])));
- echo " ".i18n("Timeslot Manager")."";
- $ok=false;
-}
-else
-{
- echo happy(i18n("You have sufficient timeslots available. Available: %1, Required: %2",array($numslots,$schedulerconfig['max_projects_per_team'])));
-}
-//asdf
+ $ok=checkPrerequisites();
if($ok)
{
@@ -240,9 +90,6 @@ if($ok)
echo " ";
echo " ";
- echo error(i18n("WARNING WARNING WARNING WARNING: The Judging Team Scheduler is NOT YET COMPLETE and SHOULD NOT YET BE RELIED UPON! IT IS STILL MISSING KEY COMPONENTS AND DOES NOT YET FULLY UPDATE THE DATABASE WITH ITS RESULTS! USE FOR TESTING ONLY AT YOUR OWN RISK!"));
-
- echo " ";
echo "".i18n("Create Divisional Awards Judging Teams")."";
diff --git a/admin/judges_schedulerconfig_check.inc.php b/admin/judges_schedulerconfig_check.inc.php
new file mode 100644
index 00000000..61a1b18d
--- /dev/null
+++ b/admin/judges_schedulerconfig_check.inc.php
@@ -0,0 +1,180 @@
+
+
+function checkPrerequisites()
+{
+ global $config;
+
+ $q=mysql_query("SELECT * FROM judges_schedulerconfig WHERE year='".$config['FAIRYEAR']."' ORDER BY var");
+
+ $schedulerconfig=array();
+ while($r=mysql_fetch_object($q))
+ {
+ $schedulerconfig[$r->var]=$r->val;
+ }
+
+ echo i18n("Based on your configuration data above, here are some calculations");
+ echo " ";
+
+ $totalteams=0;
+ $catq=mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade");
+ while($catr=mysql_fetch_object($catq))
+ {
+ echo "
$catr->category
";
+ echo "
";
+ echo "
Division
Projects
Teams
";
+ $divq=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id");
+ while($divr=mysql_fetch_object($divq))
+ {
+ $langq=mysql_query("SELECT * FROM languages WHERE active='Y'");
+ while($langr=mysql_fetch_object($langq))
+ {
+ $numq=mysql_query("SELECT COUNT(id) AS num FROM projects WHERE projectcategories_id='$catr->id' AND projectdivisions_id='$divr->id' AND year='{$config['FAIRYEAR']}' AND language='$langr->lang'");
+ $numr=mysql_fetch_object($numq);
+ echo "
";
+ echo " ";
+ echo " ";
+ }
+ echo "";
+ echo "Total judging teams required: $totalteams";
+ echo " ";
+ $minjudges=($totalteams*$schedulerconfig['min_judges_per_team']);
+ $maxjudges=($totalteams*$schedulerconfig['max_judges_per_team']);
+ echo "Minimum number of judges required: $minjudges";
+ echo " ";
+ echo "Maximum number of judges acceptable: $maxjudges";
+ echo " ";
+
+ $jq=mysql_query("SELECT COUNT(judges.id) AS num FROM judges,judges_years WHERE complete='yes' AND judges_years.year='{$config['FAIRYEAR']}' AND judges_years.judges_id=judges.id");
+ $jr=mysql_fetch_object($jq);
+ $currentjudges=$jr->num;
+ echo "Current number of registered judges: $currentjudges";
+ echo " ";
+ echo " ";
+ $ok=true;
+ if($currentjudges<$minjudges)
+ {
+ echo error(i18n("You do not have sufficient number of judges based on your parameters"));
+ echo " ";
+ echo "".i18n("Update Scheduler Configuration")." (".i18n("or get more judges!").")";
+ $ok=false;
+ }
+ else
+ echo happy(i18n("You have a sufficient number of judges based on your parameters"));
+
+ //now check if we can find a divisional award for each division and category
+
+
+ $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
+ while($r=mysql_fetch_object($q))
+ $div[$r->id]=$r->division;
+
+ $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
+ while($r=mysql_fetch_object($q))
+ $cat[$r->id]=$r->category;
+
+ $foundawards="";
+ $notfoundawards="";
+ $foundteams="";
+ foreach($div AS $d_id=>$d_division)
+ {
+ foreach($cat AS $c_id=>$c_category)
+ {
+ $q=mysql_query("SELECT award_awards.id FROM
+ award_awards,
+ award_awards_projectcategories,
+ award_awards_projectdivisions
+ WHERE
+ award_awards.year='{$config['FAIRYEAR']}'
+ AND award_awards_projectcategories.year='{$config['FAIRYEAR']}'
+ AND award_awards_projectdivisions.year='{$config['FAIRYEAR']}'
+ AND award_awards.id=award_awards_projectcategories.award_awards_id
+ AND award_awards.id=award_awards_projectdivisions.award_awards_id
+ AND award_awards_projectcategories.projectcategories_id='$c_id'
+ AND award_awards_projectdivisions.projectdivisions_id='$d_id'
+ AND award_awards.award_types_id='1'
+ ");
+ echo mysql_error();
+ if(mysql_num_rows($q)!=1)
+ {
+ while($r=mysql_fetch_object($q))
+ print_r($r);
+ $notfoundawards.="$c_category - $d_division, ";
+ $ok=false;
+ }
+ else
+ {
+ $r=mysql_fetch_object($q);
+ $foundawards.="$c_category - $d_division, ";
+ //if we found an award thats good, but it would be bad if there's already a judges team
+ //that is assigned to the award, so now lets check the judges teams to see if ones assigned
+ //to this award.
+
+ $q=mysql_query("SELECT judges_teams.num,judges_teams.name
+ FROM judges_teams,
+ judges_teams_awards_link
+ WHERE
+ judges_teams_awards_link.award_awards_id='$r->id'
+ AND judges_teams.year='".$config['FAIRYEAR']."'
+ AND judges_teams_awards_link.judges_teams_id=judges_teams.id");
+ if(mysql_num_rows($q))
+ {
+ $r=mysql_fetch_object($q);
+ $ok=false;
+ $foundteams.=i18n("(%1) %2, ",array($r->num,$r->name));
+ }
+ }
+ }
+ }
+ $notfoundawards=substr($notfoundawards,0,-2);
+ $foundawards=substr($foundawards,0,-2);
+ $foundteams=substr($foundteams,0,-2);
+
+ if($notfoundawards)
+ {
+ echo error(i18n("Cannot find awards for: %1. These awards must be created first",array($notfoundawards)));
+ echo " ";
+ echo "".i18n("Awards Manager")."";
+ }
+ if($foundawards)
+ echo happy(i18n("Found awards for: %1",array($foundawards)));
+ if($foundteams)
+ {
+ echo error(i18n("Found judging teams that are currently assigned to divisional awards: %1. These teams must be removed first",array($foundteams)));
+ echo " ".i18n("Judging Teams Manager")."";
+ }
+ else
+ echo happy(i18n("No judging teams are assigned to divisional awards (good!)"));
+
+ //now check if we have enough timeslots available...
+
+ $q=mysql_query("SELECT COUNT(id) AS num FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' AND allowdivisional='yes'");
+ $r=mysql_fetch_object($q);
+ $numslots=$r->num;
+
+ if($numslots<$schedulerconfig['max_projects_per_team'])
+ {
+ echo error(i18n("You do not have enough judging timeslots available for divisional judging. Please create more timeslots first. Available: %1, Required: %2",array($numslots,$schedulerconfig['max_projects_per_team'])));
+ echo " ".i18n("Timeslot Manager")."";
+ $ok=false;
+ }
+ else
+ {
+ echo happy(i18n("You have sufficient timeslots available. Available: %1, Required: %2",array($numslots,$schedulerconfig['max_projects_per_team'])));
+ }
+ //asdf
+
+
+ return $ok;
+}
+
+?>
diff --git a/db/db.update.13.sql b/db/db.update.13.sql
index c7ee199b..7c6d1a18 100644
--- a/db/db.update.13.sql
+++ b/db/db.update.13.sql
@@ -4,3 +4,5 @@ ALTER TABLE `projects` ADD `summarycountok` TINYINT( 1 ) DEFAULT '1' NOT NULL AF
ALTER TABLE `judges_timeslots` ADD `allowdivisional` ENUM( 'no', 'yes' ) DEFAULT 'no' NOT NULL AFTER `endtime` ;
ALTER TABLE `schools` ADD `board` VARCHAR( 64 ) NOT NULL AFTER `school`;
ALTER TABLE `schools` ADD `district` VARCHAR( 64 ) NOT NULL AFTER `board`;
+DELETE FROM `judges_schedulerconfig` WHERE var='timeslot_length';
+DELETE FROM `judges_schedulerconfig` WHERE var='timeslot_break';