forked from science-ation/science-ation
234 lines
8.3 KiB
PHP
234 lines
8.3 KiB
PHP
<?
|
|
/*
|
|
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');
|
|
include "judges.inc.php";
|
|
|
|
send_header("Administration - Judge Scheduler Configuration");
|
|
|
|
echo "<a href=\"index.php\"><< ".i18n("Back to Administration")."</a>\n";
|
|
echo "<a href=\"judges.php\"><< ".i18n("Back to Judges")."</a>\n";
|
|
|
|
if($_GET['edit']) $edit=$_GET['edit'];
|
|
if($_POST['edit']) $edit=$_POST['edit'];
|
|
if($_GET['action']) $action=$_GET['action'];
|
|
if($_POST['action']) $action=$_POST['action'];
|
|
|
|
$q=mysql_query("SELECT * FROM judges_schedulerconfig WHERE year='-1'");
|
|
while($r=mysql_fetch_object($q))
|
|
{
|
|
mysql_query("INSERT INTO judges_schedulerconfig (var,val,description,year) VALUES (
|
|
'".mysql_escape_string($r->var)."',
|
|
'".mysql_escape_string($r->val)."',
|
|
'".mysql_escape_string($r->description)."',
|
|
'".$config['FAIRYEAR']."')");
|
|
}
|
|
|
|
if($_POST['action']=="save")
|
|
{
|
|
if($_POST['saveconfig'])
|
|
{
|
|
foreach($_POST['saveconfig'] as $key=>$val)
|
|
{
|
|
mysql_query("UPDATE judges_schedulerconfig SET val='".mysql_escape_string(stripslashes($val))."' WHERE year='".$config['FAIRYEAR']."' AND var='$key'");
|
|
}
|
|
}
|
|
echo happy(i18n("Judges Scheduler Configuration successfully saved"));
|
|
|
|
|
|
}
|
|
$q=mysql_query("SELECT * FROM config WHERE year=0 ORDER BY var");
|
|
echo "<form method=\"post\" action=\"judges_schedulerconfig.php\">";
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
|
|
echo "<table>";
|
|
|
|
echo "<tr><td colspan=\"3\"><hr /><br /><h3>".i18n("Scheduler configuration settings for fair year %1",array($config['FAIRYEAR']))."</h3></td></tr>";
|
|
|
|
$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 "<tr><td>$r->var</td><td>".i18n($r->description)."</td><td><input type=\"text\" name=\"saveconfig[$r->var]\" value=\"$r->val\" /></td></tr>";
|
|
|
|
|
|
}
|
|
echo "</table>";
|
|
echo "<input type=\"submit\" value=\"".i18n("Save Configuration")."\" />\n";
|
|
echo "</form>";
|
|
echo "<hr />";
|
|
echo i18n("Based on your configuration data above, here are some calculations");
|
|
echo "<br />";
|
|
|
|
$totalteams=0;
|
|
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade");
|
|
while($catr=mysql_fetch_object($catq))
|
|
{
|
|
echo "<h3>$catr->category</h3>";
|
|
echo "<table>";
|
|
echo "<tr><th>Division</th><th>Projects</th><th>Teams</th></tr>";
|
|
$divq=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id");
|
|
while($divr=mysql_fetch_object($divq))
|
|
{
|
|
$numq=mysql_query("SELECT COUNT(id) AS num FROM projects WHERE projectcategories_id='$catr->id' AND projectdivisions_id='$divr->id' AND year='{$config['FAIRYEAR']}'");
|
|
$numr=mysql_fetch_object($numq);
|
|
echo "<tr><td>".i18n($divr->division)."</td>";
|
|
echo "<td align=\"center\">$numr->num</td>";
|
|
$numteams=ceil($numr->num/$schedulerconfig['max_projects_per_team']*$schedulerconfig['num_times_judged']);
|
|
echo "<td align=\"center\">$numteams</td>";
|
|
$totalteams+=$numteams;
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
echo "<br />";
|
|
echo "<br />";
|
|
}
|
|
echo "<b>";
|
|
echo "Total judging teams required: $totalteams";
|
|
echo "<br />";
|
|
$minjudges=($totalteams*$schedulerconfig['min_judges_per_team']);
|
|
$maxjudges=($totalteams*$schedulerconfig['max_judges_per_team']);
|
|
echo "Minimum number of judges required: $minjudges";
|
|
echo "<br />";
|
|
echo "Maximum number of judges acceptable: $maxjudges";
|
|
echo "<br />";
|
|
|
|
$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 "<br />";
|
|
echo "<br />";
|
|
$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)));
|
|
else
|
|
echo happy(i18n("No judging teams are assigned to divisional awards (good!)"));
|
|
|
|
if($ok)
|
|
{
|
|
echo i18n("Everything looks in order, we're ready to create the divisional awards judging teams. Click 'Create Divisional Awards Judging Teams' below to start the scheduler. Please be patient as it may take 20-30 seconds to find an optimal solution to the judging team assignments");
|
|
echo "<br />";
|
|
echo "<br />";
|
|
|
|
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 "<br />";
|
|
echo "<a href=\"judges_sa.php\">".i18n("Create Divisional Awards Judging Teams")."</a>";
|
|
|
|
|
|
|
|
}
|
|
|
|
echo "</b>";
|
|
echo "<br />";
|
|
echo "<br />";
|
|
echo "<br />";
|
|
|
|
send_footer();
|
|
|
|
|
|
?>
|