<?php

  include("html_functions.php");



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

  $lgid=$_SESSION['lgid'];

  $date=new DateTime($_SESSION['lgdate']);

  

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

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

  

  ##### Export Results #####

  $query="SELECT round,supplemental,pick_round,ad.team_id,name,nickname,player_id FROM amateur_draft as ad,teams as t WHERE ad.team_id=t.team_id AND ad.league_id=$lgid ORDER BY round,supplemental,pick_round";

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

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

  if (mysqli_num_rows($result))

  {

	  $cnt=0;

	  $line[$cnt]=Array("//Format: Draft Round","Supplemental (1 = yes or 0 = no)","Pick in Round","Team Name","Team ID","Player ID");

	  $cnt++;



	  $sRndCnt=0;



	  while ($row=mysqli_fetch_array($result))

	  {

		  $tid=$row['team_id'];

		  $pid=$row['player_id'];

		  if ($pid=="") {$pid=0;}



		  $rnd=$row['round'];

		  $supp=$row['supplemental'];

		  $pick=$row['pick_round'];



		  $tname=$row['name']." ".$row['nickname'];



		  $line[$cnt]=Array($rnd,$supp,$pick,"$tname",$tid,$pid,"eol");

		  $cnt++;

	  }



	  header("Content-type: text/csv");

	  header("Content-Disposition: attachment; filename=draft_results.csv");

	  header("Pragma: no-cache");

	  header("Expires: 0");

	  outputCSV($line); 

  }

  else

  {

	  echo "Draft has not been configured";

  }



  mysqli_close($db);



?>

