diff --git a/TODO b/TODO index d0ab2e05..13b7e0cf 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,3 @@ - Make auto-logout on email address change work properly on the FIRST submit, not on first action after the submit - same for judges changing email address -- Judges CSV contain categories and sub-categories info -- Judge 'info' button on judge teams page to view allt he judge info -- diff --git a/admin/judges_teams.php b/admin/judges_teams.php index d81d774c..00e6ffa7 100644 --- a/admin/judges_teams.php +++ b/admin/judges_teams.php @@ -95,6 +95,7 @@ function switchjudgeinfo() $r=mysql_fetch_object($q); $team_id=$r->id; $team_name=$r->name; + $captain='no'; } else { @@ -102,14 +103,31 @@ function switchjudgeinfo() mysql_query("INSERT INTO judges_teams (num,name,year) VALUES ('".$_POST['team_num']."','".$_POST['new_team_name']."','".$config['FAIRYEAR']."')"); $team_id=mysql_insert_id(); $team_name=$_POST['new_team_name']; + $captain='yes'; } $added=0; foreach($_POST['judgelist'] AS $selectedjudge) { - mysql_query("INSERT INTO judges_teams_link (judges_id,judges_teams_id,year) VALUES ('$selectedjudge','$team_id','".$config['FAIRYEAR']."')"); - $added++; + //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 judges_id='$selectedjudge' AND judges_teams_id='$team_id'"); + if(mysql_num_rows($q)) + { + echo notice(i18n("Judge (%1) already belongs to judging team: %2",array($selectedjudge,$team_name))); + + } + else + { + //lets make the first one we add a captain, the rest, non-captains :) + mysql_query("INSERT INTO judges_teams_link (judges_id,judges_teams_id,captain,year) VALUES ('$selectedjudge','$team_id','$captain','".$config['FAIRYEAR']."')"); + $added++; + } + //if this is alreayd no, then who cares, but if its the first one that is going into the new team, then + //captain will be yes, and we only want the first one assigned to a new team to be the captain + //sno now we can set this back to no + $captain='no'; } if($added==1) $j=i18n("judge"); @@ -147,6 +165,35 @@ function switchjudgeinfo() } + if($_GET['action']=="addcaptain") + { + + //teams can have as many captains as they want, so just add it. + mysql_query("UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id='".$_GET['team_id']."' AND judges_id='".$_GET['judge_id']."'"); + echo happy(i18n("Team captain assigned")); + } + + if($_GET['action']=="removecaptain") + { + //teams must always have at least one captain, so if we only have one, and we are trying to remove it, dont let them! + $q=mysql_query("SELECT * FROM judges_teams_link WHERE captain='yes' AND judges_teams_id='".$_GET['team_id']."'"); + if(mysql_num_rows($q)<2) + { + echo error(i18n("A judge team must always have at least one captain")); + } + else + { + mysql_query("UPDATE judges_teams_link SET captain='no' WHERE judges_teams_id='".$_GET['team_id']."' AND judges_id='".$_GET['judge_id']."'"); + echo happy(i18n("Team captain removed")); + } + } + + if(!$_SESSION['viewstate']['judges_teams_list_show']) + $_SESSION['viewstate']['judges_teams_list_show']='unassigned'; + //now update the judges_teams_list_show viewstate + if($_GET['judges_teams_list_show']) + $_SESSION['viewstate']['judges_teams_list_show']=$_GET['judges_teams_list_show']; + echo "