From 5d4d74fd0c0385b61f3caa224b9086870bf2c25c Mon Sep 17 00:00:00 2001 From: james Date: Thu, 31 Mar 2011 20:28:28 +0000 Subject: [PATCH] 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 --- admin/judges_teams.php | 56 ++++++++++++++++++---------- admin/judges_teams_members.php | 67 ++++++++++++++++++++++++++++++---- user.inc.php | 8 ++++ 3 files changed, 104 insertions(+), 27 deletions(-) diff --git a/admin/judges_teams.php b/admin/judges_teams.php index 7132300..9f10fd8 100644 --- a/admin/judges_teams.php +++ b/admin/judges_teams.php @@ -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 "
"; $teams=getJudgingTeams(); - //print_r($teams); - - if(!count($teams)) - { - echo "".i18n("Automatically create one new team for every non-divisional award")."
"; - echo "".i18n("Manually add individual team")."
"; - } - 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 ""; + echo ""; echo "
"; + $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 "".i18n("Automatically create one new team for every non-divisional award")."
"; + } + echo "".i18n("Manually add individual team")."
"; + echo "
"; + + if(count($teams)) + { - echo ""; - echo "
"; - echo "Add individual team
"; - echo "
"; echo "Delete all teams assigned to divisional awards"; echo "
"; echo "Delete all teams
"; @@ -436,6 +451,9 @@ function addclicked() echo ""; echo "
"; } + else { + echo "
"; + } } send_footer(); diff --git a/admin/judges_teams_members.php b/admin/judges_teams_members.php index 8235b2a..0cb322d 100644 --- a/admin/judges_teams_members.php +++ b/admin/judges_teams_members.php @@ -106,8 +106,7 @@ jQuery(document).ready(function(){ 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
"; + //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 ""; + echo "
"; + echo "Auto-Assign Special Awards Judges to Special Awards Teams\n"; echo "
"; diff --git a/user.inc.php b/user.inc.php index 070d0fc..e21ca25 100644 --- a/user.inc.php +++ b/user.inc.php @@ -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; }