<?php

  include("html_functions.php");

  ################## PAGE INITIALIZATION #########################
  $lgid=$_SESSION['lgid'];
  $lgpath=$_SESSION['lgpath'];
  $adminpath=$_SESSION['adminpath'];
  $htmlpath=$_SESSION['htmlpath'];
  $date=new DateTime($_SESSION['lgdate']);
  $lgyear=$_SESSION['lgyear'];
  
  if (!isset($_GET['showq'])||($_GET['showq']!=1)) {$_GET['showq']=0;}

  $module="Awards";

  include($_SESSION['adminpath']."/dbopen.php");

  # Check if awards vote table exists
  $query="SHOW TABLES LIKE 'awards_vote';";
  $result=mysqli_query($db,$query);
  if (!mysqli_num_rows($result))
  {
	  ##### Initialize Table #####
	  $query="CREATE TABLE IF NOT EXISTS awards_vote (player_id INT, league_id INT, sub_league_id INT, year SMALLINT, human_manager_id INT, award_id SMALLINT, position SMALLINT, vote INT DEFAULT 0, PRIMARY KEY (player_id, league_id, sub_league_id, year, human_manager_id, award_id));";
	  $result=mysqli_query($db,$query);
  }

  # Check Admin Table
  $query="SHOW TABLES LIKE 'ootp_sql_admin';";
  $result=mysqli_query($db,$query);
  if (mysqli_num_rows($result)) 
  {
	  # Get Settings
	  $query="SELECT * FROM ootp_sql_admin WHERE scope IN ('ALL',$lgid) AND (module='$module' OR setting='showAllUsers')";
	  if ($_GET['showq']==1) {echo "$query<br/>\n";}

	  $result=mysqli_query($db,$query);

	  if (mysqli_num_rows($result))

	  {

		  while ($row=mysqli_fetch_array($result))

		  {

			  $scope=$row['scope'];

			  $module=$row['module'];

			  $setting=$row['setting'];

			  $identifier=$row['identifier'];

			  $value=$row['value'];



			  if ($setting=='showAllUsers') {$showAllUsers=$value;}

			  else {$settings[$scope][$module][$identifier][$setting]=$value;}

		  }

	  }

  }

  if ($settings[$lgid]['Awards'][-1]['maxPlyrs']=="")    {$settings[$lgid]['Awards'][-1]['maxPlyrs']=40;}

  if ($settings[$lgid]['Awards'][-1]['minPA']=="")       {$settings[$lgid]['Awards'][-1]['minPA']=3.1;}

  if ($settings[$lgid]['Awards'][-1]['minIP']=="")       {$settings[$lgid]['Awards'][-1]['minIP']=1.0;}

  if ($settings[$lgid]['Awards'][-1]['maxServ']=="")     {$settings[$lgid]['Awards'][-1]['maxServ']=45;}

  if ($settings[$lgid]['Awards'][-1]['minFIP']=="")      {$settings[$lgid]['Awards'][-1]['minFIP']=4.5;}	

  if ($settings[$lgid]['Awards'][-1]['boyVotes']=="")    {$settings[$lgid]['Awards'][-1]['boyVotes']=10;}

  if ($settings[$lgid]['Awards'][-1]['poyVotes']=="")    {$settings[$lgid]['Awards'][-1]['poyVotes']=5;}

  if ($settings[$lgid]['Awards'][-1]['royVotes']=="")    {$settings[$lgid]['Awards'][-1]['royVotes']=3;}

  if ($settings[$lgid]['Awards'][-1]['cmVotes']=="")     {$settings[$lgid]['Awards'][-1]['cmVotes']=3;}

  if ($settings[$lgid]['Awards'][-1]['gmVotes']=="")     {$settings[$lgid]['Awards'][-1]['gmVotes']=3;}

  if ($settings[$lgid]['Awards'][-1]['cmAwardName']=="") {$settings[$lgid]['Awards'][-1]['cmAwardName']="Custom Award";}

  if ($settings[$lgid]['Awards'][-1]['cmAwardAbbr']=="") {$settings[$lgid]['Awards'][-1]['cmAwardAbbr']="Ctm";}

  if ($settings[$lgid]['Awards'][-1]['cmWho']=="")       {$settings[$lgid]['Awards'][-1]['cmWho']='batters';}

  if ($settings[$lgid]['Awards'][-1]['cmQual']=="")      {$settings[$lgid]['Awards'][-1]['cmQual']='all';}

  if ($settings[$lgid]['Awards'][-1]['boyAbbr']=="")     {$settings[$lgid]['Awards'][-1]['boyAbbr']="BOY";}

  if ($settings[$lgid]['Awards'][-1]['poyAbbr']=="")     {$settings[$lgid]['Awards'][-1]['poyAbbr']="POY";}

  if ($settings[$lgid]['Awards'][-1]['royAbbr']=="")     {$settings[$lgid]['Awards'][-1]['royAbbr']="ROY";}

  if ($settings[$lgid]['Awards'][-1]['ggAbbr']=="")      {$settings[$lgid]['Awards'][-1]['ggAbbr']="GG";}



  # Get Award Info

  $query="SELECT mvp_award_name,pitcher_award_name,rookie_award_name,defense_award_name FROM leagues WHERE league_id=$lgid;";

  if ($_GET['showq']==1) {echo "$query<br/>\n";}

  $result=mysqli_query($db,$query);

  $row=mysqli_fetch_array($result);

  $awardName['boy']=$row['mvp_award_name'];

  $awardName['poy']=$row['pitcher_award_name'];

  $awardName['roy']=$row['rookie_award_name'];

  $awardName['gg']=$row['defense_award_name'];

  $awCnt=3;



  mysqli_close($db);



  ################## PAGE INITIALIZATION #########################

  $title='Awards Voting Admin';



  page_head($title,$_SESSION['lgpath']);

  echo " <div id='topbar'>\n";

  main_titlebar($_SESSION['lgid'],$_SESSION['lgpath'],$title);



  if ($_SESSION['user_is_commish']!=1)

  {

	  nav_toolbar("awards","Awards Voting");

	  echo " </div>   <!-- END topbar DIV -->\n";

	  echo " <div id='contentpane'>\n";

	  echo "You must be a commisioner to access this page";

	

	  ################## END OF PAGE #########################

	  echo " </div>   <!-- END contentpane DIV -->\n";

	  page_foot($_SESSION['lgpath']);

	  exit;

  }

  else

  {

	  nav_toolbar('admin','Admin Pages');

	  nav_toolbar("awards","Awards Voting");

	  echo " </div>   <!-- END topbar DIV -->\n";

	  echo " <div id='contentpane'>\n";

  }



  ################## START OF PAGE CONTENT #########################

  echo " <table cellpadding=0 cellspacing=0 border=0 width='910px'><tr><td valign='top'>\n";

  echo "  <div class='textbox'>\n";



  echo "   <FORM ACTION=\"save_settings.php\" METHOD=\"post\">\n";

  echo "    <input type='hidden' name='module' value='Awards'>\n";

  if ($_GET['debug']==1) {echo "    <input type='hidden' name='debug' value='1'>\n";}

  echo "    <table cellpadding=2 cellspacing=0>";

  echo "     <TR class='title'><TD colspan=5>Awards Voting Settings</TD></TR>\n";



  echo "     <TR><TD>Enable Voting:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"awVotingOn\" value=1";

  if ($settings[$lgid]['Awards'][-1]['awVotingOn']==1) {echo " checked";}

  echo "></TD></TR>\n";

  echo "     <TR><TD>Allow Users To Change Their Vote:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"awModEnable\" value=1";

  if ($settings[$lgid]['Awards'][-1]['awModEnable']==1) {echo " checked";}

  echo "></TD></TR>\n";

  echo "     <TR><TD>Show Results To All (else, only after voting):</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"awResults\" value=1";

  if ($settings[$lgid]['Awards'][-1]['awResults']==1) {echo " checked";}

  echo "></TD></TR>\n";

  echo "     <TR><TD>Maximum Players Per Ballot:</TD><TD align='left' colspan=4><INPUT type=\"text\" name=\"maxPlyrs\" value=\"".$settings[$lgid]['Awards'][-1]['maxPlyrs']."\"></TD></TR>\n";

  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>Ballot Size</TD></TR>\n";

  echo "     <TR>";

  echo "      <TD>".$awardName['boy']." Votes</TD>\n";

  echo "      <TD align='left' colspan=4>\n";

  echo "       <select name='boyVotes'>\n";

  echo "        <option value=10";

  if ($settings[$lgid]['Awards'][-1]['boyVotes']==10) {echo " selected";}

  echo ">10</option>\n";

  echo "        <option value=5";

  if ($settings[$lgid]['Awards'][-1]['boyVotes']==5) {echo " selected";}

  echo ">5</option>\n";

  echo "        <option value=3";

  if ($settings[$lgid]['Awards'][-1]['boyVotes']==3) {echo " selected";}

  echo ">3</option>\n";

  echo "        <option value=1";

  if ($settings[$lgid]['Awards'][-1]['boyVotes']==1) {echo " selected";}

  echo ">1</option>\n";

  echo "       </select>\n";

  echo "      </TD>\n";

  echo "     </TR>\n";

  echo "     <TR>";

  echo "      <TD>".$awardName['poy']." Votes</TD>\n";

  echo "      <TD align='left' colspan=4>\n";

  echo "       <select name='poyVotes'>\n";

  echo "        <option value=10";

  if ($settings[$lgid]['Awards'][-1]['poyVotes']==10) {echo " selected";}

  echo ">10</option>\n";

  echo "        <option value=5";

  if ($settings[$lgid]['Awards'][-1]['poyVotes']==5) {echo " selected";}

  echo ">5</option>\n";

  echo "        <option value=3";

  if ($settings[$lgid]['Awards'][-1]['poyVotes']==3) {echo " selected";}

  echo ">3</option>\n";

  echo "        <option value=1";

  if ($settings[$lgid]['Awards'][-1]['poyVotes']==1) {echo " selected";}

  echo ">1</option>\n";

  echo "       </select>\n";

  echo "      </TD>\n";

  echo "     </TR>\n";

  echo "     <TR>";

  echo "      <TD>".$awardName['roy']." Votes</TD>\n";

  echo "      <TD align='left' colspan=4>\n";

  echo "       <select name='royVotes'>\n";

  echo "        <option value=10";

  if ($settings[$lgid]['Awards'][-1]['royVotes']==10) {echo " selected";}

  echo ">10</option>\n";

  echo "        <option value=5";

  if ($settings[$lgid]['Awards'][-1]['royVotes']==5) {echo " selected";}

  echo ">5</option>\n";

  echo "        <option value=3";

  if ($settings[$lgid]['Awards'][-1]['royVotes']==3) {echo " selected";}

  echo ">3</option>\n";

  echo "        <option value=1";

  if ($settings[$lgid]['Awards'][-1]['royVotes']==1) {echo " selected";}

  echo ">1</option>\n";

  echo "       </select>\n";

  echo "      </TD>\n";

  echo "     </TR>\n";

  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>Award Abbreviations</TD></TR>\n";

  echo "     <TR><TD>".$awardName['boy']." Abbr:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"boyAbbr\" value=\"".$settings[$lgid]['Awards'][-1]['boyAbbr']."\"></TD></TR>\n";

  echo "     <TR><TD>".$awardName['poy']." Abbr:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"poyAbbr\" value=\"".$settings[$lgid]['Awards'][-1]['poyAbbr']."\"></TD></TR>\n";

  echo "     <TR><TD>".$awardName['roy']." Abbr:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"royAbbr\" value=\"".$settings[$lgid]['Awards'][-1]['royAbbr']."\"></TD></TR>\n";

  echo "     <TR><TD>".$awardName['gg']." Abbr:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"ggAbbr\" value=\"".$settings[$lgid]['Awards'][-1]['ggAbbr']."\"></TD></TR>\n";

  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>Player Qualifications (per team game)</TD></TR>\n";

  echo "     <TR><TD>Minimum Plate Appearances:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"minPA\" value=\"".$settings[$lgid]['Awards'][-1]['minPA']."\"></TD></TR>\n";

  echo "     <TR><TD>Minimum Innings Pitched:</TD><TD align='left' colspan=4><INPUT type=\"text\" name=\"minIP\" value=\"".$settings[$lgid]['Awards'][-1]['minIP']."\"></TD></TR>\n";

  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>Rookie Qualification</TD></TR>\n";

  echo "     <TR><TD>Maximum Service Days Prior to Current Season:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"maxServ\" value=\"".$settings[$lgid]['Awards'][-1]['maxServ']."\"></TD></TR>\n";

  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>".$awardName['gg']." Voting</TD></TR>\n";

  echo "     <TR><TD>Enable Voting:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"ggEnable\" value=1";

  if ($settings[$lgid]['Awards'][-1]['ggEnable']==1) {echo " checked";$awCnt++;}

  echo "></TD></TR>\n";

  echo "     <TR><TD>Split Outfielders by Position:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"splitOF\" value=1";

  if ($settings[$lgid]['Awards'][-1]['splitOF']==1) {echo " checked";}

  echo "></TD></TR>\n";

  echo "     <TR><TD>Minimum Fielding Innings for Position Qualification:</TD><TD align='left' colspan=4><INPUT type=\"text\" name=\"minFIP\" value=\"".$settings[$lgid]['Awards'][-1]['minFIP']."\"></TD></TR>\n";



  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>".$settings[$lgid]['Awards'][-1]['cmAwardName']." Voting (custom award)</TD></TR>\n";

  echo "     <TR><TD>Enable Voting:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"cmEnable\" value=1";

  if ($settings[$lgid]['Awards'][-1]['cmEnable']==1) {echo " checked";$awCnt++;}

  echo "></TD></TR>\n";

  echo "     <TR><TD>Award Name:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"cmAwardName\" value=\"".$settings[$lgid]['Awards'][-1]['cmAwardName']."\"></TD></TR>\n";

  echo "     <TR><TD>Award Abbr:</TD><TD align='left' colspan=4><INPUT type=\"text\" size=20 name=\"cmAwardAbbr\" value=\"".$settings[$lgid]['Awards'][-1]['cmAwardAbbr']."\"></TD></TR>\n";

  echo "     <TR>";

  echo "      <TD>".$settings[$lgid]['Awards'][-1]['cmAwardName']." Votes</TD>\n";

  echo "      <TD align='left' colspan=4>\n";

  echo "       <select name='cmVotes'>\n";

  echo "        <option value=10";

  if ($settings[$lgid]['Awards'][-1]['cmVotes']==10) {echo " selected";}

  echo ">10</option>\n";

  echo "        <option value=5";

  if ($settings[$lgid]['Awards'][-1]['cmVotes']==5) {echo " selected";}

  echo ">5</option>\n";

  echo "        <option value=3";

  if ($settings[$lgid]['Awards'][-1]['cmVotes']==3) {echo " selected";}

  echo ">3</option>\n";

  echo "        <option value=1";

  if ($settings[$lgid]['Awards'][-1]['cmVotes']==1) {echo " selected";}

  echo ">1</option>\n";

  echo "       </select>\n";

  echo "      </TD>\n";

  echo "     </TR>\n";

  echo "     <TR><TD>Player Pool:</TD>\n";

  echo "      <TD align='left' colspan=4>\n";

  echo "       <select name='cmWho'>\n";

  echo "        <option value='batters'";

  if ($settings[$lgid]['Awards'][-1]['cmWho']=='batters') {echo " selected";}

  echo ">All Batters</option>\n";

  echo "        <option value='pitchers'";

  if ($settings[$lgid]['Awards'][-1]['cmWho']=='pitchers') {echo " selected";}

  echo ">All Pitchers</option>\n";

  echo "        <option value='relievers'";

  if ($settings[$lgid]['Awards'][-1]['cmWho']=='relievers') {echo " selected";}

  echo ">Relievers</option>\n";

  echo "        <option value='all'";

  if ($settings[$lgid]['Awards'][-1]['cmWho']=='all') {echo " selected";}

  echo ">All</option>\n";

  echo "       </select>\n";

  echo "      </TD>\n";

  echo "     </TR>\n";echo "     <TR><TD>Player Qualification:</TD>\n";

  echo "       <TD align='left'><INPUT type=\"radio\" name=\"cmQual\" value='all' id='all'";

  if ($settings[$lgid]['Awards'][-1]['cmQual']=='all') {echo " checked='checked'";}

  echo "></TD><TD valign='top'><label for='all'>All Players</label></TD>\n";

  echo "       <TD align='left'><INPUT type=\"radio\" name=\"cmQual\" value='rookies' id='rookies'";

  if ($settings[$lgid]['Awards'][-1]['cmQual']=='rookies') {echo " checked='checked'";}

  echo "></TD><TD valign='top'><label for='rookies'>Rookies Only</label></TD>\n";

  echo "     </TR>\n";



  echo "     <TR class='headline'><TD colspan=5 class='hsc2_l'>General Manager of the Year Voting</TD></TR>\n";

  echo "     <TR><TD>Enable Voting:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"gmEnable\" value=1";

  if ($settings[$lgid]['Awards'][-1]['gmEnable']==1) {echo " checked";}

  echo "></TD></TR>\n";

  echo "     <TR>";

  echo "      <TD>General Manager Votes</TD>\n";

  echo "      <TD align='left' colspan=4>\n";

  echo "       <select name='gmVotes'>\n";

  echo "        <option value=10";

  if ($settings[$lgid]['Awards'][-1]['gmVotes']==10) {echo " selected";}

  echo ">10</option>\n";

  echo "        <option value=5";

  if ($settings[$lgid]['Awards'][-1]['gmVotes']==5) {echo " selected";}

  echo ">5</option>\n";

  echo "        <option value=3";

  if ($settings[$lgid]['Awards'][-1]['gmVotes']==3) {echo " selected";}

  echo ">3</option>\n";

  echo "        <option value=1";

  if ($settings[$lgid]['Awards'][-1]['gmVotes']==1) {echo " selected";}

  echo ">1</option>\n";

  echo "       </select>\n";

  echo "      </TD>\n";

  echo "     </TR>\n";

  echo "     <TR><TD>Allow GM's to vote for themselves:</TD><TD align='left' colspan=4><INPUT type=\"checkbox\" name=\"gmSelfVote\" value=1";

  if ($settings[$lgid]['Awards'][-1]['gmSelfVote']==1) {echo " checked";}

  echo "></TD></TR>\n";

  

  echo "     <TR><TD colspan=5><INPUT type=\"submit\" value=\"Save\"></TD></TR>\n";

  echo "   </FORM>\n";

  echo "     <TR><TD></TD><TD colspan=4>\n";

  echo "      <form method='get' action='./awSubmit.php'>\n";

  echo "       <input type='hidden' name='clear_votes' value=1 />\n";

  echo "       <input type='hidden' name='lgid' value='$lgid' />\n";

  echo "       <input type='hidden' name='year' value=$lgyear />\n";

  echo "       <INPUT type='submit' value=\"Clear This Year's Votes\">\n";

  echo "      </form>\n";

  echo "     </TD></TR>\n";

  echo "     <TR><TD></TD><TD colspan=4>\n";

  echo "      <form method='get' action='./awSubmit.php'>\n";

  echo "       <input type='hidden' name='clear_votes' value=1 />\n";

  echo "       <input type='hidden' name='lgid' value='$lgid' />\n";

  echo "       <INPUT type='submit' value=\"Clear All Votes\">\n";

  echo "      </form>\n";

  echo "     </TD></TR>\n";

  echo "    </table>";

  echo "  </div>\n";



  ## Display Users

  include($_SESSION['adminpath']."/dbopen.php");

  ## Get Subleagues

  $query="SELECT sub_league_id,name FROM sub_leagues WHERE league_id=$lgid ORDER BY sub_league_id;";

  $result=mysqli_query($db,$query);

  $prevSL=0;

  $SLcnt=0;

  while ($row=mysqli_fetch_array($result))

  {

	  $sub_league_id=$row['sub_league_id'];

	  $subleagues[$sub_league_id]['name']=$row['name'];

	  $SLcnt++;

  }

  

  ## Get leagues

  $query="SELECT l.league_id,name FROM leagues as l,human_managers as hm WHERE l.league_id=hm.league_id";

  $result=mysqli_query($db,$query);

  if (mysqli_num_rows($result)>0)

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $uLeagueID=$row['league_id'];

		  $leagues[$uLeagueID]['name']=$row['name'];

	  }

  }



  ## Display Summary of Users

  $query="SELECT human_manager_id,award_id,sub_league_id FROM awards_vote WHERE league_id=$lgid AND year=$lgyear AND award_id IN (4,5,6,7,200,300) GROUP BY human_manager_id,award_id,sub_league_id";

  $result=mysqli_query($db,$query);

  if (mysqli_num_rows($result)>0)

  {

	  while ($row=mysqli_fetch_array($result))

      	  {

		  $hmid=$row['human_manager_id'];

  		  $awid=$row['award_id'];

		  $slid=$row['sub_league_id'];

	    	  $votes[$hmid][$awid][$slid]=1;

		  if (!isset($votes[$hmid]['total'])) {$votes[$hmid]['total']=1;} else {$votes[$hmid]['total']++;}

      	  }

  }

  $expVotes=$SLcnt*$awCnt+$settings[$lgid]['Awards'][-1]['gmEnable'];

  

  $query="SELECT hm.human_manager_id,t.name,t.nickname,first_name,last_name,hm.league_id FROM human_managers AS hm,teams AS t WHERE hm.team_id=t.team_id UNION SELECT human_manager_id,IF(is_commish=1,'Commissioner','No team') as name,'' as nickname,first_name,last_name,9999-is_commish as league_id FROM human_managers WHERE team_id=0 ORDER BY league_id,last_name,first_name;";

  $result=mysqli_query($db,$query);

  $cnt=0;

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

	    	  if (($showAllUsers!=1)&&($row['name']=='No team')) {continue;}

		  $hmid=$row['human_manager_id'];

		  $managers[$hmid]['name']=$row['first_name']." ".$row['last_name']." (".$row['name']." ".$row['nickname'].")";

		  $managers[$hmid]['lgid']=$row['league_id'];

	  }

  }

  

  echo " </tr>";



  ## Display User Detail

  echo " <tr><td>\n";

  echo "  <div class='textbox'>\n";

  echo "    <table cellpadding=2 cellspacing=0 border=0 width='935px'>\n";

  echo "     <tr class='title'><td colspan=".(2+$SLcnt*$awCnt+$settings[$lgid]['Awards'][-1]['gmEnable']).">Voting Detail</td></tr>\n";

  echo "     <tr class='headline'><td class='hsc2_l' colspan=2>&nbsp;</td>";

  foreach ($subleagues as $slid => $val)

  {

	  echo "<td class='hsc2' colspan='$awCnt' style='text-align:center;border-left:1px dotted #999999;'>".$subleagues[$slid]['name']."</td>";

  }

  if ($settings[$lgid]['Awards'][-1]['gmEnable']==1) {echo "<td class='hsc2' style='text-align:center;border-left:1px dotted #999999;'>All</td>";}

  echo "</tr>\n";

  echo "     <tr class='headline'><td class='hsc2_l'>User</td><td class='hsc2_l'>Status</td>";

  foreach ($subleagues as $slid => $val)

  {

	  echo "<td class='hsc2' style='text-align:center;border-left:1px dotted #999999;' title='".$awardName['boy']." (BOY)'>".$settings[$lgid]['Awards'][-1]['boyAbbr']."</td>";

	  echo "<td class='hsc2' style='text-align:center;' title='".$awardName['poy']." (POY)'>".$settings[$lgid]['Awards'][-1]['poyAbbr']."</td>";

	  echo "<td class='hsc2' style='text-align:center;' title='".$awardName['roy']." (ROY)'>".$settings[$lgid]['Awards'][-1]['royAbbr']."</td>";

	  if ($settings[$lgid]['Awards'][-1]['ggEnable']==1) {echo "<td class='hsc2' style='text-align:center;' title='".$awardName['gg']." (GG)'>".$settings[$lgid]['Awards'][-1]['ggAbbr']."</td>";}

	  if ($settings[$lgid]['Awards'][-1]['cmEnable']==1) {echo "<td class='hsc2' style='text-align:center;' title='".$settings[$lgid]['Awards'][-1]['cmAwardName']."'>".$settings[$lgid]['Awards'][-1]['cmAwardAbbr']."</td>";}

  }

  if ($settings[$lgid]['Awards'][-1]['gmEnable']==1) {echo "<td class='hsc2' style='text-align:center;border-left:1px dotted #999999;' title='General Manager of the Year'>GM</td>";}

  echo "</tr>\n";

  $mCnt=0;

  foreach ($managers as $hmid => $val)

  {

	  $hmLeagueID=$managers[$hmid]['lgid'];



	  if ($hmLeagueID!=$oldHMLeagueID)

	  {

		  $mCnt=0;

		  echo "     <tr class='headline'><td class='hsc2_l' colspan=".(2+$SLcnt*$awCnt+$settings[$lgid]['Awards'][-1]['gmEnable']).">";

		  if ($hmLeagueID==9998) {echo "Unaffiliated Commissioners";}

		  elseif ($hmLeagueID==9999) {echo "Unaffiliated Users";}

		  else {echo $leagues[$hmLeagueID]['name'];}

		  echo "</td></tr>\n";

	  }



	  $cls='s'.($mCnt%2+1);

	  echo "     <tr class='$cls'>";

	  $voted="Not voted";

	  if ($votes[$hmid]['total']==$expVotes) {$voted="Yes";}

	  elseif ($votes[$hmid]['total']>0) {$voted="Partial";}

	  if ($voted!="Yes") {echo "<td class='".$cls."_l'><font color='red'>".$managers[$hmid]['name']."</font></td>";}

	  else {echo "<td class='".$cls."_l'>".$managers[$hmid]['name']."</td>";}

  	  if ($voted=="Not voted")

	  {

		  echo "<td class='".$cls."_l'><font weight='bold' color='red'>$voted</font></td>";

	  }

	  else

	  {

		  echo "<td class='".$cls."_l'><a href='./eos_ballot.php?page=results&human_manager_id=$hmid'>$voted</a> (<a title='Clear entire ballot' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid'>X</a>)</td>";

	  }

	  foreach ($subleagues as $slid => $val)

	  {

		  echo "<td style='text-align:center;border-left:1px dotted #999999;'>";

		  if ($votes[$hmid][5][$slid]==1) {echo "Yes (<a title='Clear votes for this award' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid&award=5'>X</a>)";}

		  else {echo "<font weight='bold' color='red'>No</font>";}

		  echo "</td>";

		  echo "<td style='text-align:center;'>";

		  if ($votes[$hmid][4][$slid]==1) {echo "Yes (<a title='Clear votes for this award' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid&award=4'>X</a>)";}

		  else {echo "<font weight='bold' color='red'>No</font>";}

		  echo "</td>";

		  echo "<td style='text-align:center;'>";

		  if ($votes[$hmid][6][$slid]==1) {echo "Yes (<a title='Clear votes for this award' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid&award=6'>X</a>)";}

		  else {echo "<font weight='bold' color='red'>No</font>";}

		  echo "</td>";

		  if ($settings[$lgid]['Awards'][-1]['ggEnable']==1) 

		  {

			  echo "<td style='text-align:center;'>";

			  if ($votes[$hmid][7][$slid]==1) {echo "Yes (<a title='Clear votes for this award' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid&award=7'>X</a>)";}

			  else {echo "<font weight='bold' color='red'>No</font>";}

			  echo "</td>";

		  }

		  if ($settings[$lgid]['Awards'][-1]['cmEnable']==1) 

		  {

			  echo "<td style='text-align:center;'>";

			  if ($votes[$hmid][200][$slid]==1) {echo "Yes (<a title='Clear votes for this award' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid&award=200'>X</a>)";}

			  else {echo "<font weight='bold' color='red'>No</font>";}

			  echo "</td>";

		  }

	  }

	  if ($settings[$lgid]['Awards'][-1]['gmEnable']==1) 

	  {

		  echo "<td style='text-align:center;border-left:1px dotted #999999;'>";

		  if ($votes[$hmid][300][0]==1) {echo "Yes (<a title='Clear votes for this award' href='./awSubmit.php?lgid=$lgid&year=$lgyear&clear_votes=1&human_manager_id=$hmid&award=300'>X</a>)";}

		  else {echo "<font weight='bold' color='red'>No</font>";}

		  echo "</td>";

	  }		

	  echo "</tr>\n";

	  $mCnt++;

	  $oldHMLeagueID=$hmLeagueID;

  }

  echo "    </table>\n";

  echo "   </div>\n";

  echo " </td></tr>\n";



  echo "</table>\n";



  mysqli_close($db);



  ################## END OF PAGE #########################

  echo " </div>   <!-- END contentpane DIV -->\n";

  page_foot($_SESSION['lgpath']);





?>

