<?php

  include("html_functions.php");



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

  $lgid=$_SESSION['lgid'];

  $lgyear=$_SESSION['lgyear'];





  $title='Team Index';

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

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

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

  nav_toolbar("history","History");

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

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



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

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



  # Get Team Historical Record Data

  $query="SELECT team_id,MIN(year) as minYr,MAX(year) as maxYr,SUM(w) as w,SUM(l) as l FROM team_history_record WHERE league_id=$lgid GROUP BY team_id";

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

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

  $tlist="";

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];

		  $teams[$tid]['minYr']=$row['minYr'];

		  $teams[$tid]['maxYr']=$row['maxYr'];

		  $teams[$tid]['w']=$row['w'];

		  $teams[$tid]['l']=$row['l'];

		  $tlist.=",$tid";

	  }

  }

  $tlist=trim($tlist,",");



  # Get Historical Info

  $query="SELECT team_id,name,nickname,MIN(year) as year,SUM(made_playoffs) as made_playoffs,SUM(won_playoffs) as won_playoffs FROM team_history WHERE league_id=$lgid GROUP BY team_id,name,nickname ORDER BY team_id,year";

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];

		  $year=$row['year'];

		  if (!isset($teams[$tid]['made_playoffs'])) {$teams[$tid]['made_playoffs']=$row['made_playoffs'];} else {$teams[$tid]['made_playoffs']+=$row['made_playoffs'];}

		  if (!isset($teams[$tid]['won_playoffs'])) {$teams[$tid]['won_playoffs']=$row['won_playoffs'];} else {$teams[$tid]['won_playoffs']+=$row['won_playoffs'];}

		  $teams[$tid]['names'][$year]=$row['name']." ".$row['nickname'];

	  }

  }



  # Get Award Winners

  if ($tlist=="") {$tlist=-1;}

  $query="(SELECT team_id,award_id,COUNT(*) as cnt FROM league_history as lh,players_awards as pa WHERE lh.league_id=$lgid AND best_pitcher_id=pa.player_id AND award_id=4 AND lh.year=pa.season GROUP BY team_id,award_id)";

  $query.=" UNION (SELECT team_id,award_id,COUNT(*) as cnt FROM league_history as lh,players_awards as pa WHERE lh.league_id=$lgid AND best_hitter_id=pa.player_id AND award_id=5 AND lh.year=pa.season GROUP BY team_id,award_id)";

  $query.=" UNION (SELECT team_id,award_id,COUNT(*) as cnt FROM league_history as lh,players_awards as pa WHERE lh.league_id=$lgid AND best_rookie_id=pa.player_id AND award_id=6 AND lh.year=pa.season GROUP BY team_id,award_id)";

  $query.=" UNION (SELECT team_id,award_id,COUNT(*) as cnt FROM players_awards WHERE league_id=$lgid AND award_id IN (7,9,10) AND team_id IN ($tlist) GROUP BY team_id,award_id)";

  $query.=" ORDER BY team_id,award_id";

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];

		  $awid=$row['award_id'];

		  if (($awid==10)&&(!isset($fndCustomAW))) {$fndCustomAW=1;}

		  if (isset($defTeams[$tid])) {$defTeams[$tid]['awCnt'][$awid]=$row['cnt'];}

		  else {$teams[$tid]['awCnt'][$awid]=$row['cnt'];}

	  }



	  ## Get Award Names

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

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

	  $row=mysqli_fetch_array($result);

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

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

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

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

	  $awardName[9]='All-Star';

  }

  # Check Admin Table

  $query="SHOW TABLES LIKE 'ootp_sql_admin';";

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

  if (mysqli_num_rows($result)) 

  {

	  # Get Settings

	  $query="SELECT setting,value FROM ootp_sql_admin WHERE scope=$lgid AND module='Awards' AND (setting LIKE '%Abbr' OR setting='cmAwardName')";

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

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

	  if (mysqli_num_rows($result))

	  {

		  while ($row=mysqli_fetch_array($result))

		  {

			  $setting=$row['setting'];

			  $value=$row['value'];



			  $settings[$setting]=$value;

		  }

	  }

  }

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

  if ($settings['cmAwardAbbr']=="") {$settings['cmAwardAbbr']="Ctm";}

  if ($settings['boyAbbr']=="")     {$settings['boyAbbr']="BOY";}

  if ($settings['poyAbbr']=="")     {$settings['poyAbbr']="POY";}

  if ($settings['royAbbr']=="")     {$settings['royAbbr']="ROY";}

  if ($settings['ggAbbr']=="")      {$settings['ggAbbr']="GG";}



  # Get years won

  $query="SELECT team_id,year,made_playoffs,won_playoffs FROM team_history WHERE league_id=$lgid AND (made_playoffs=1 OR won_playoffs=1) ORDER BY year";

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];



		  if ($row['won_playoffs']==1) {$teams[$tid]['won_years']=$teams[$tid]['won_years'].",".$row['year'];}

		  if ($row['made_playoffs']==1) {$teams[$tid]['made_years']=$teams[$tid]['made_years'].",".$row['year'];}

	  }

  }



  # Get Active Teams

  $query="SELECT t.team_id,name,nickname,logo_file_name,w,l FROM teams as t,team_record as tr WHERE t.team_id=tr.team_id AND league_id=$lgid AND allstar_team=0 ORDER BY name,nickname";

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

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

  if (mysqli_num_rows($result))

  {

	  echo "<div class='textbox' style='width:100%;'>   <!-- open active team listing -->\n";

	  echo " <table border=0 cellpadding=4 cellspacing=0 width='100%' style='margin-left:auto;margin-right:auto;'>   <!-- open active team listing -->\n";

	  echo "  <tr class='title2'><td>Active Teams</td></tr>\n";

	  echo "  <tr><td style='padding:0px;'>\n";

	  echo "   <table border=0 cellpadding=2 cellspacing=0 width='100%' class='sortable'>\n";

	  echo "    <thead><tr class='headline'>";

	  echo "<td class='hsc2'>&nbsp;</td>";

	  echo "<td class='hsc2_l'>Team</td>";

	  echo "<td class='hsc2'>From</td>";

	  echo "<td class='hsc2'>To</td>";

	  echo "<td class='hsc2'>Yrs</td>";

	  echo "<td class='hsc2'>W</td>";

	  echo "<td class='hsc2'>L</td>";

	  echo "<td class='hsc2'>Pct</td>";

	  echo "<td class='hsc2'>&gt;.500</td>";

	  echo "<td class='hsc2' style='text-align:center;'>Playoffs</td>";

	  echo "<td class='hsc2' style='text-align:center;'>Champion</td>";

	  echo "<td class='hsc2' title='".$awardName[5]."'>".$settings['boyAbbr']."</td>";

	  echo "<td class='hsc2' title='".$awardName[4]."'>".$settings['poyAbbr']."</td>";

	  echo "<td class='hsc2' title='".$awardName[6]."'>".$settings['royAbbr']."</td>";

	  if ($fndCustomAW==1) {echo "<td class='hsc2' title='".$settings['cmAwardName']."'>".$settings['cmAwardAbbr']."</td>";}

	  echo "<td class='hsc2' title='".$awardName[7]."'>".$settings['ggAbbr']."</td>";

	  echo "<td class='hsc2' title='".$awardName[9]."'>AS</td>";

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



	  $rowCnt=0;

	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];

		  $teams[$tid]['name']=$row['name']." ".$row['nickname'];

		  $teams[$tid]['logo_file']=urlencode($row['logo_file_name']);

		  $teams[$tid]['w']=$row['w']+$teams[$tid]['w'];

		  $teams[$tid]['l']=$row['l']+$teams[$tid]['l'];



		  $teams[$tid]['maxYr']=$lgyear;

		  if (!isset($teams[$tid]['minYr'])) {$teams[$tid]['minYr']=$lgyear;}



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



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

		  echo "<td class='".$cls."_l' sorttable_customkey='".$teams[$tid]['name']."'><a href='./team_overview.php?team_id=$tid'><img src='".$_SESSION['lgpath']."/images/team_logos/".str_replace(".png","_40.png",$teams[$tid]['logo_file'])."' width=40 height=40></a></td>";

		  echo "<td class='".$cls."_l' sorttable_customkey='".$teams[$tid]['name']."'><a href='./team_overview.php?team_id=$tid'>".$teams[$tid]['name']."</a>";

		  if (isset($teams[$tid]['names']))

		  {

			  foreach ($teams[$tid]['names'] as $year => $oldName)

			  {

				  if ($teams[$tid]['name']===$oldName) {continue;}

				  echo "<br/>&nbsp;$oldName";

			  }

		  }

		  echo "</td>";

		  echo "<td>".$teams[$tid]['minYr']."</td>";

		  echo "<td>".$teams[$tid]['maxYr']."</td>";

		  echo "<td>".($teams[$tid]['maxYr']-$teams[$tid]['minYr']+1)."</td>";

		  echo "<td>".$teams[$tid]['w']."</td>";

		  echo "<td>".$teams[$tid]['l']."</td>";

		  $wpct=$teams[$tid]['w']/($teams[$tid]['w']+$teams[$tid]['l']);

		  echo "<td sorttable_customkey='$wpct'>";

		  $wpct=sprintf("%.3f",$wpct);

		  if ($wpct<1) {$wpct=strstr($wpct,".");}

		  echo "$wpct</td>";

		  echo "<td>".($teams[$tid]['w']-$teams[$tid]['l'])."</td>";

		  echo "<td sorttable_customkey='".$teams[$tid]['made_playoffs']."' title='".trim($teams[$tid]['made_years'],",")."' style='text-align:center;'>";

		  if ($teams[$tid]['made_playoffs']==0) {echo "-";} else {echo $teams[$tid]['made_playoffs'];}

		  echo "</td>";

		  echo "<td sorttable_customkey='".$teams[$tid]['won_playoffs']."' title='".trim($teams[$tid]['won_years'],",")."' style='text-align:center;'>";

		  if ($teams[$tid]['won_playoffs']==0) {echo "-";} else {echo $teams[$tid]['won_playoffs'];}

		  echo "</td>";

		  if ($teams[$tid]['awCnt'][5]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][5]."'>".$teams[$tid]['awCnt'][5]."</td>";}

		  if ($teams[$tid]['awCnt'][4]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][4]."'>".$teams[$tid]['awCnt'][4]."</td>";}

		  if ($teams[$tid]['awCnt'][6]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][6]."'>".$teams[$tid]['awCnt'][6]."</td>";}

		  if ($fndCustomAW==1) 

		  {

			  if ($teams[$tid]['awCnt'][10]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][10]."'>".$teams[$tid]['awCnt'][10]."</td>";}

		  }

		  if ($teams[$tid]['awCnt'][7]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][7]."'>".$teams[$tid]['awCnt'][7]."</td>";}

		  if ($teams[$tid]['awCnt'][9]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][9]."'>".$teams[$tid]['awCnt'][9]."</td>";}

		  echo "</tr>\n";



		  $rowCnt++;



	  }



	  echo "   </table>\n";

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

	  echo " </table>   <!-- close active team listing -->\n";

	  echo "</div>   <!-- close active team listing -->\n";



	  ## Get improving/declining teams

	  $query="SELECT t1.team_id,t2.winPct as prevWinPct,t1.winPct as newWinPct,t1.winPct-t2.winPct as imp FROM (SELECT team_id,SUM(w) as w,SUM(l) as l,if(SUM(w)+SUM(l)=0,0,SUM(w)/(SUM(w)+SUM(l))) as winPct FROM team_history_record WHERE league_id=$lgid AND year>".($lgyear-3)." GROUP BY team_id HAVING SUM(w)>0 ORDER BY winPct) as t1,(SELECT team_id,SUM(w) as w,SUM(l) as l,if(SUM(w)+SUM(l)=0,0,SUM(w)/(SUM(w)+SUM(l))) as winPct FROM team_history_record WHERE league_id=$lgid AND year<=".($lgyear-3)." AND year>".($lgyear-6)." GROUP BY team_id HAVING SUM(w)>0 ORDER BY winPct) as t2 WHERE t1.team_id=t2.team_id ORDER BY imp DESC LIMIT 3";

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

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

	  if (mysqli_num_rows($result))

	  {

		  echo "<div class='textbox' style='width:100%;'>   <!-- open active team listing -->\n";

		  echo " <table border=0 cellpadding=4 cellspacing=0 width='100%' style='margin-left:auto;margin-right:auto;'>   <!-- open active team listing -->\n";

		  echo "  <tr class='title2'><td colspan=2>Recent Trends</td></tr>\n";

		  echo "  <tr><td colspan=2 style='text-align:center;'>Past 3 seasons winning percentage compared to the 3 seasons prior</td></tr>\n";

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

		  echo "   <div class='textbox' style='float:none;width:400px;margin-left:auto;margin-right:auto;'>\n";

		  echo "    <table cellpadding=2 cellspacing=0 border=0 style='width:100%;'>\n";

		  echo "     <tr class='title'><td colspan=3>Improved</td></tr>\n";

		  $rowCnt=0;

		  while ($row=mysqli_fetch_array($result))

		  {

			  $tid=$row['team_id'];

			  $cls='s'.($rowCnt%2+1)."_l";

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

			  echo "<td";

			  if ($rowCnt==1) {echo " style='border-top:1px dotted gray;'";}

			  echo "><a href='./team_hist.php?team_id=$tid'>".$teams[$tid]['name']."</a></td>";

			  echo "<td title='From ".$row['prevWinPct']." to ".$row['newWinPct']."'";

			  if ($rowCnt==1) {echo " style='border-right:1px dotted gray;border-top:1px dotted gray;'";}

			  elseif ($rowCnt>1) {echo " style='border-right:1px dotted gray;'";}

			  echo ">+";

			  if (abs($row['imp'])<1) {echo strstr(sprintf("%.3f",$row['imp']),".");}

			  else {echo sprintf("%.3f",$row['imp']);}

			  echo "</td>";

			  if ($rowCnt==0) {echo "<td rowspan=3 style='width:50px;text-align:center;'><a href='./team_hist.php?team_id=$tid'><img src='".$_SESSION['lgpath']."/images/team_logos/".str_replace(".png","_40.png",$teams[$tid]['logo_file'])."' width=40 height=40></a></td>";}

			  echo "</tr>\n";

			  $rowCnt++;

		  }

		  echo "    </table>\n";

		  echo "   </div>\n";

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

		  echo "   <div class='textbox' style='float:none;width:400px;margin-left:auto;margin-right:auto;'>\n";

		  echo "    <table cellpadding=2 cellspacing=0 border=0 style='width:100%;'>\n";

		  echo "     <tr class='title'><td colspan=3>Regressed</td></tr>\n";

		  $query="SELECT t1.team_id,t2.winPct as prevWinPct,t1.winPct as newWinPct,t1.winPct-t2.winPct as imp FROM (SELECT team_id,SUM(w) as w,SUM(l) as l,if(SUM(w)+SUM(l)=0,0,SUM(w)/(SUM(w)+SUM(l))) as winPct FROM team_history_record WHERE league_id=$lgid AND year>".($lgyear-3)." GROUP BY team_id HAVING SUM(l)>0 ORDER BY winPct) as t1,(SELECT team_id,SUM(w) as w,SUM(l) as l,if(SUM(w)+SUM(l)=0,0,SUM(w)/(SUM(w)+SUM(l))) as winPct FROM team_history_record WHERE league_id=$lgid AND year<=".($lgyear-3)." AND year>".($lgyear-6)." GROUP BY team_id HAVING SUM(l)>0 ORDER BY winPct) as t2 WHERE t1.team_id=t2.team_id ORDER BY imp LIMIT 3";

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

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

		  $rowCnt=0;

		  while ($row=mysqli_fetch_array($result))

		  {

			  $tid=$row['team_id'];

			  $cls='s'.($rowCnt%2+1)."_l";

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

			  if ($rowCnt==0) {echo "<td rowspan=3 style='width:50px;text-align:center;'><a href='./team_hist.php?team_id=$tid'><img src='".$_SESSION['lgpath']."/images/team_logos/".str_replace(".png","_40.png",$teams[$tid]['logo_file'])."' width=40 height=40></a></td>";}

			  echo "<td";

			  if ($rowCnt==1) {echo " style='border-left:1px dotted gray;border-top:1px dotted gray;'";}

			  elseif ($rowCnt>1) {echo " style='border-left:1px dotted gray;'";}

			  echo "><a href='./team_hist.php?team_id=$tid'>".$teams[$tid]['name']."</a></td>";

			  echo "<td title='From ".$row['prevWinPct']." to ".$row['newWinPct']."'";

			  if ($rowCnt==1) {echo " style='border-top:1px dotted gray;'";}

			  echo ">";

			  if (abs($row['imp'])<1)

			  {

				  if ($row['imp']<0) {echo "-";}

				  echo strstr(sprintf("%.3f",$row['imp']),".");

			  }

			  else {echo sprintf("%.3f",$row['imp']);}

			  echo "</td>";

			  echo "</tr>\n";

			  $rowCnt++;

		  }

		  echo "    </table>\n";

		  echo "   </div>\n";

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

		  echo " </table>   <!-- close active team listing -->\n";

		  echo "</div>   <!-- close active team listing -->\n";

	  }

  }



  # Get historical teams

  $query="SELECT team_id,name,nickname,logo_file_name FROM teams WHERE team_id IN ($tlist) AND league_id!=$lgid AND allstar_team=0 ORDER BY name,nickname";

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

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

  if (mysqli_num_rows($result))

  {

	  echo "<div class='textbox' style='width:100%;'>   <!-- open historic team listing -->\n";

	  echo " <table border=0 cellpadding=4 cellspacing=0 width='100%' style='margin-left:auto;margin-right:auto;'>   <!-- open historic team listing -->\n";

	  echo "  <tr class='title2'><td>Historic Teams</td></tr>\n";

	  echo "  <tr><td style='padding:0px;'>\n";

	  echo "   <table border=0 cellpadding=2 cellspacing=0 width='100%' class='sortable'>\n";

	  echo "    <thead><tr class='headline'>";

	  echo "<td class='hsc2'>&nbsp;</td>";

	  echo "<td class='hsc2_l'>Team</td>";

	  echo "<td class='hsc2'>From</td>";

	  echo "<td class='hsc2'>To</td>";

	  echo "<td class='hsc2'>Yrs</td>";

	  echo "<td class='hsc2'>W</td>";

	  echo "<td class='hsc2'>L</td>";

	  echo "<td class='hsc2'>Pct</td>";

	  echo "<td class='hsc2'>&gt;.500</td>";

	  echo "<td class='hsc2' style='text-align:center;'>Playoffs</td>";

	  echo "<td class='hsc2' style='text-align:center;'>Champion</td>";

	  echo "<td class='hsc2' title='".$awardName[5]."'>".$settings['boyAbbr']."</td>";

	  echo "<td class='hsc2' title='".$awardName[4]."'>".$settings['poyAbbr']."</td>";

	  echo "<td class='hsc2' title='".$awardName[6]."'>".$settings['royAbbr']."</td>";

	  if ($fndCustomAW==1) {echo "<td class='hsc2' title='".$settings['cmAwardName']."'>".$settings['cmAwardAbbr']."</td>";}

	  echo "<td class='hsc2' title='".$awardName[7]."'>".$settings['ggAbbr']."</td>";

	  echo "<td class='hsc2' title='".$awardName[9]."'>AS</td>";

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



	  $rowCnt=0;

	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];

		  $teams[$tid]['name']=$row['name']." ".$row['nickname'];

		  $teams[$tid]['logo_file']=urlencode($row['logo_file_name']);



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



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

		  echo "<td class='".$cls."_l' sorttable_customkey='".$teams[$tid]['name']."'><a href='./team_overview.php?team_id=$tid'><img src='".$_SESSION['lgpath']."/images/team_logos/".str_replace(".png","_40.png",$teams[$tid]['logo_file'])."' width=40 height=40></a></td>";

		  echo "<td class='".$cls."_l' sorttable_customkey='".$teams[$tid]['name']."'><a href='./team_overview.php?team_id=$tid'>".$teams[$tid]['name']."</a>";

		  foreach ($teams[$tid]['names'] as $year => $oldName)

		  {

			  if ($teams[$tid]['name']===$oldName) {continue;}

			  echo "<br/>&nbsp;$oldName";

		  }

		  echo "</td>";

		  echo "<td>".$teams[$tid]['minYr']."</td>";

		  echo "<td>".$teams[$tid]['maxYr']."</td>";

		  echo "<td>".($teams[$tid]['maxYr']-$teams[$tid]['minYr']+1)."</td>";

		  echo "<td>".$teams[$tid]['w']."</td>";

		  echo "<td>".$teams[$tid]['l']."</td>";

		  $wpct=$teams[$tid]['w']/($teams[$tid]['w']+$teams[$tid]['l']);

		  echo "<td sorttable_customkey='$wpct'>";

		  $wpct=sprintf("%.3f",$wpct);

		  if ($wpct<1) {$wpct=strstr($wpct,".");}

		  echo "$wpct</td>";

		  echo "<td>".($teams[$tid]['w']-$teams[$tid]['l'])."</td>";

		  echo "<td sorttable_customkey='".$teams[$tid]['made_playoffs']."' title='".trim($teams[$tid]['made_years'],",")."' style='text-align:center;'>";

		  if ($teams[$tid]['made_playoffs']==0) {echo "-";} else {echo $teams[$tid]['made_playoffs'];}

		  echo "</td>";

		  echo "<td sorttable_customkey='".$teams[$tid]['won_playoffs']."' title='".trim($teams[$tid]['won_years'],",")."' style='text-align:center;'>";

		  if ($teams[$tid]['won_playoffs']==0) {echo "-";} else {echo $teams[$tid]['won_playoffs'];}

		  echo "</td>";

		  if ($teams[$tid]['awCnt'][5]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][5]."'>".$teams[$tid]['awCnt'][5]."</td>";}

		  if ($teams[$tid]['awCnt'][4]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][4]."'>".$teams[$tid]['awCnt'][4]."</td>";}

		  if ($teams[$tid]['awCnt'][6]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][6]."'>".$teams[$tid]['awCnt'][6]."</td>";}

		  if ($fndCustomAW==1) 

		  {

			  if ($teams[$tid]['awCnt'][10]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][10]."'>".$teams[$tid]['awCnt'][10]."</td>";}

		  }

		  if ($teams[$tid]['awCnt'][7]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][7]."'>".$teams[$tid]['awCnt'][7]."</td>";}

		  if ($teams[$tid]['awCnt'][9]==0) {echo "<td sorttable_customkey='0'>-</td>";} else {echo "<td sorttable_customkey='".$teams[$tid]['awCnt'][9]."'>".$teams[$tid]['awCnt'][9]."</td>";}

		  echo "</tr>\n";



		  $rowCnt++;



	  }



	  echo "   </table>\n";

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

	  echo " </table>   <!-- close historic team listing -->\n";

	  echo "</div>   <!-- close historic team listing -->\n";

  }



  mysqli_close($db);



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

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



  page_foot($_SESSION['lgpath']);





?>

