<?php

  include("html_functions.php");



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

  $lgid=$_SESSION['lgid'];

  $lgyear=$_SESSION['lgyear'];

  $yr=$_GET['year'];

  $slid=$_GET['sub_league_id'];



  $title="Draft History";

  

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

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

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

  nav_toolbar("history","History");

  nav_toolbar("leagues","",$lgid,$slid,"",$yr,"position^b");

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

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



  ## Close if unselected

  if (($slid=="")||($yr==""))

  {

	  echo "<p>Please choose a sub-league and year.</p>\n";

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

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

	  page_foot($_SESSION['lgpath']);

	  exit;

  }



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

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



  #Get Team Names

  $query="SELECT team_id,name,nickname,abbr";

  if ($lgyear==$yr) {$query.=" FROM teams WHERE league_id=$lgid AND allstar_team=0";}

  else {$query.=",made_playoffs,won_playoffs FROM team_history WHERE league_id=$lgid AND year=$yr";}

  $query.=" AND sub_league_id=$slid;";

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

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

  $tlist="";

  $tmCnt=0;

  while ($row=mysqli_fetch_array($result))

  {

	  $tid=$row['team_id'];

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

	  $teams[$tid]['city']=$row['name'];

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

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

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

	  $tlist.="$tid,";

	  $tmCnt++;

  }

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



  ##### Get Drafted Players #####

  $dquery="SELECT player_id,first_name,last_name,date_of_birth,draft_round,draft_pick,draft_team_id FROM players WHERE draft_league_id=$lgid AND draft_year=$yr ORDER BY draft_round,draft_pick";



  $statArray=Array("g","ab","h","hr","sb","avg","obp","slg","war");



  $statArray=Array("g","gs","ip","w","l","s","k","era","whip","war");







  mysqli_close($db);



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

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

  page_foot($_SESSION['lgpath']);





?>

