Fix auto-create teams for special awards when divisional awards teams already exist (they shouldnt matter)

Create auto-assign special awards judges to special awards teams
This commit is contained in:
james 2011-03-31 20:28:28 +00:00
parent 529aa8ca38
commit 5d4d74fd0c
3 changed files with 104 additions and 27 deletions

View File

@ -205,17 +205,29 @@
award_types_order,
award_awards.order,
name");
$num=1;
while($r=mysql_fetch_object($q))
{
//startat
$q2=mysql_query("SELECT MAX(num) AS lastnum FROM judges_teams WHERE year='{$config['FAIRYEAR']}'");
$r2=mysql_fetch_object($q2);
if($r2->lastnum)
$num=$r2->lastnum+1;
else
$num=1;
while($r=mysql_fetch_object($q)) {
// print_r($r);
$name=mysql_escape_string("($r->award_type) $r->name");
mysql_query("INSERT INTO judges_teams(num,name,autocreate_type_id,year) VALUES ('$num','$name','$r->award_types_id','".$config['FAIRYEAR']."')");
echo mysql_error();
$team_id=mysql_insert_id();
//now link the new team to the award
mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('$r->id','$team_id','".$config['FAIRYEAR']."')");
message_push(happy(i18n("Created team #%1: %2",array($num,$name))));
if($team_id) {
//now link the new team to the award
mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('$r->id','$team_id','".$config['FAIRYEAR']."')");
message_push(happy(i18n("Created team #%1: %2",array($num,$name))));
}
else {
message_push(error(i18n("Error creating team #%1: %2",array($num,$name))));
}
$num++;
}
}
@ -365,15 +377,7 @@ function addclicked()
echo "<br />";
$teams=getJudgingTeams();
//print_r($teams);
if(!count($teams))
{
echo "<a href=\"judges_teams.php?action=createall\">".i18n("Automatically create one new team for every non-divisional award")."</a><br />";
echo "<a href=\"judges_teams.php?action=add&num=1\">".i18n("Manually add individual team")."</a><br />";
}
else
{
if(count($teams)) {
//grab an array of all the current team numbers
foreach($teams AS $team)
$teamnumbers[$team['num']]=1;
@ -384,12 +388,23 @@ function addclicked()
{
$newteamnum++;
}
}
//print_r($teams);
echo "<table width=\"95%\">";
echo "<tr><td>";
$q=mysql_query("SELECT COUNT(*) AS c FROM judges_teams WHERE autocreate_type_id!='1' AND year='".$config['FAIRYEAR']."'");
$r=mysql_fetch_object($q);
if(!$r->c) {
echo "<a href=\"judges_teams.php?action=createall\">".i18n("Automatically create one new team for every non-divisional award")."</a><br />";
}
echo "<a href=\"judges_teams.php?action=add&num=$newteamnum\">".i18n("Manually add individual team")."</a><br />";
echo "</td><td>";
if(count($teams))
{
echo "<table width=\"95%\">";
echo "<tr><td>";
echo "<a href=\"judges_teams.php?action=add&num=$newteamnum\">Add individual team</a><br />";
echo "</td><td>";
echo "<a onclick=\"return confirmClick('".i18n("Are you sure you want to delete all teams that are assigned to divisional awards?")."')\" href=\"judges_teams.php?action=deletealldivisional\">Delete all teams assigned to divisional awards</a>";
echo "<br />";
echo "<a onclick=\"return confirmClick('".i18n("Are you sure you want to delete all teams?")."')\" href=\"judges_teams.php?action=deleteall\">Delete all teams</a><br />";
@ -436,6 +451,9 @@ function addclicked()
echo "<script type=\"text/javascript\">$('.summarytable').tablesorter();</script>";
echo "<br />";
}
else {
echo "</td></tr></table>";
}
}
send_footer();

View File

@ -106,8 +106,7 @@ jQuery(document).ready(function(){
</script>
<?
if($_POST['action']=="add" && $_POST['team_num'] && count($_POST['judgelist'])>0)
{
if($_POST['action']=="add" && $_POST['team_num'] && count($_POST['judgelist'])>0) {
//first check if this team exists.
$q=mysql_query("SELECT id,name FROM judges_teams WHERE num='".$_POST['team_num']."' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q))
@ -125,18 +124,15 @@ jQuery(document).ready(function(){
}
$added=0;
foreach($_POST['judgelist'] AS $selectedjudge)
{
foreach($_POST['judgelist'] AS $selectedjudge) {
//before we insert them, we need to make sure they dont already belong to this team. We can not have the same judge assigned to the same team multiple times.
$q=mysql_query("SELECT * FROM judges_teams_link WHERE users_id='$selectedjudge' AND judges_teams_id='$team_id'");
if(mysql_num_rows($q))
{
if(mysql_num_rows($q)) {
echo notice(i18n("Judge (%1) already belongs to judging team: %2",array($selectedjudge,$team_name)));
}
else
{
else {
//lets make the first one we add a captain, the rest, non-captains :)
mysql_query("INSERT INTO judges_teams_link (users_id,judges_teams_id,captain,year) VALUES ('$selectedjudge','$team_id','$captain','".$config['FAIRYEAR']."')");
$added++;
@ -231,6 +227,59 @@ jQuery(document).ready(function(){
}
}
if($_GET['action']=="autoassignspecial") {
/* Load all the judges (judge_complete=yes, deleted=no, year=fairyear) */
$judgelist = judges_load_all();
/* Load all the teams */
$teams = array();
$q = mysql_query("SELECT * FROM judges_teams WHERE year='{$config['FAIRYEAR']}'");
while($i = mysql_fetch_assoc($q)) {
$teams[$i['id']] = $i;
}
/* And the links */
$links = array();
$q = mysql_query("SELECT * FROM judges_teams_link WHERE year='{$config['FAIRYEAR']}'");
while($i = mysql_fetch_assoc($q)) {
$judgelist[$i['users_id']]['teams_links'][] = $i;
}
$jlist = array();
/* Remove all judges that have a link */
foreach($judgelist as $j) {
if(count($j['teams_links']) == 0 && $j['special_award_only']=="yes")
$jlist[] = $j['id'];
}
echo "We have ".count($jlist)." special awards judges to assign";
foreach($jlist AS $jid) {
$j=$judgelist[$jid];
if(is_array($j['special_award_selected']) && count($j['special_award_selected'])) {
//assing them to ALL teams for ALL awards
foreach($j['special_award_selected'] AS $awardid) {
echo "Looking for a team for award $awardid <br />";
//find the award id linked to a team
$q=mysql_query("SELECT * FROM judges_teams_awards_link WHERE award_awards_id='{$awardid}' AND year='{$config['FAIRYEAR']}'");
if(mysql_num_rows($q)) {
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO judges_teams_link (users_id,judges_teams_id,captain,year) VALUES ('$jid','$r->judges_teams_id','yes','{$config['FAIRYEAR']}')");
echo happy(i18n("%1 %2 to their special award(s) team(s)",array($j['firstname'],$j['lastname'])));
}
}
else {
echo error(i18n("%1 %2 not assigned - No team found that is judging award id %1",array($awardid)));
}
}
}
else {
echo error(i18n("%1 %2 has indicated special awards only, but didnt selected any awards",array($j['firstname'],$j['lastname'])));
}
}
}
if(!$_SESSION['viewstate']['judges_teams_list_show'])
$_SESSION['viewstate']['judges_teams_list_show']='unassigned';
//now update the judges_teams_list_show viewstate
@ -314,6 +363,8 @@ jQuery(document).ready(function(){
unset($u);
echo "</select>";
echo "<br />";
echo "<a href=\"judges_teams_members.php?action=autoassignspecial\">Auto-Assign Special Awards Judges to Special Awards Teams</a>\n";
echo "</td>";
echo "<td valign=\"top\">";

View File

@ -102,6 +102,14 @@ function user_load_judge(&$u)
foreach($should_be_arrays as $k) {
if(!is_array($u[$k])) $u[$k] = array();
}
$specialawards=array();
if($u['special_award_only']=='yes') {
$q=mysql_query("SELECT * FROM judges_specialaward_sel WHERE users_id='{$u['id']}'");
while($r=mysql_fetch_object($q)) {
$specialawards[]=$r->award_awards_id;
}
}
$u['special_award_selected']=$specialawards;
return true;
}