Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/drafts.php
<?php
/**
 * Draft interface
 *
 * Displays {@link OFFL_Draft drafts} by {@link OFFL_League league}, as well as draft pick interface and administrative options.
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */
	
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/functions.php");

if(empty($_REQUEST["mode"]))
{	$_REQUEST["mode"] = NULL;	}
if(empty($_REQUEST["action"]))
{	$_REQUEST["action"] = NULL;	}

if(empty($_REQUEST["year"]))
{	$_REQUEST["year"] = getThisYear();	}
if(empty($_REQUEST["round"]))
{	$_REQUEST["round"] = NULL;	}

// I messed with the order here for the purposes of round autodetection...
// I can't do that until after the header include but then it's too late to put the round
// in the page title.

$pageTitle = $_REQUEST["year"] . " Draft";
$adminEditOnly = 1 ;
require_once($DOC_ROOT . "/lib/header.php"); 

// because of user drafting, I must add security to prevent pick swaps

	$isAdmin = $myuser->getAdmin(); // 1 for admin, 0 for not.

	// this lets an admin draft via the normal means without losing the ability to use the draft-editing menu
	if (isset($_REQUEST["owner"])) // check isset instead of value in case of rewritten URLs
	{	$isAdmin = FALSE;	}

 /*
	Here I parse $wholeDraft to find the current pick
*/

	$wholeDraft = new OFFL_Draft($_SESSION["league_id"], $_REQUEST["year"], NULL, TRUE);
	$rds = $wholeDraft->getDraftRounds();
	$pks = $wholeDraft->getPicks();
	$maxrd = 0;
	$maxpk = 0;
	$curr_tm = 0;
	unset($wholeDraft); // and now get rid of it

	$highlightcolor = "#263";

	foreach($pks as $pk)
	{
		if (is_null($pk->getPlayerID()) || ($pk->getPlayerID() == 0)) // not picked here
		{
			$maxrd = $pk->getRoundNo();
			$maxpk = $pk->getPickNo();
			$curr_tm = new OFFL_FFLTeam($pk->getFFLTeamID());
			break;
		}
	}
	
	if ($_REQUEST["round"] == "all")
	{	$allrounds = TRUE;	}
	else
	{	$allrounds = FALSE;	}

	if (empty($_REQUEST["round"]) || $allrounds)
	{
		if ($maxrd == 0)
			$_REQUEST["round"]=1;
		else
			$_REQUEST["round"]=$maxrd;
	}

$thisDraft = new OFFL_Draft($_SESSION["league_id"], $_REQUEST["year"], $_REQUEST["round"], $allrounds);

// user is saving info (edit or add)
if($_REQUEST["action"] == "save")
{
	$thisDraftPick = new OFFL_DraftPick($_SESSION["league_id"], $_REQUEST["year"], $_REQUEST["round"], $_REQUEST["pick_no"]);
	// If edit, get the existing record
	// This should also remove the preexisting record in the player table
	if($_REQUEST["mode"] == "edit")
	{
		$thisDraftPick = new OFFL_DraftPick($_SESSION["league_id"], $_REQUEST["year"],$_REQUEST["round"],$_REQUEST["pick_no"]); // get existing record
		$oldPlayerID = $thisDraftPick->getPlayerID(); // retrieve player ID being replaced
		if ($oldPlayerID != 0)
		{
			$oldPlayer = new OFFL_Player($oldPlayerID, $_SESSION["league_id"]); // retrieve player being replaced
			$oldTeam = new OFFL_FFLTeam($oldPlayer->getFFLTeamID());
			$oldTeam->dropPlayer($oldPlayer->getPlayerID());
			$oldTeam->save(); // and save
		}
	}

	// what if the new pick is elsewhere in the draft?
	// check for pick elsewhere (might happen on admin edits)
	$oldDraft = new OFFL_Draft($_SESSION["league_id"], $_REQUEST["year"], $_REQUEST["round"], 1); // 1 pulls all rounds
	$oldPicks = $oldDraft->getPicks();
	foreach ($oldPicks as $oldPick)
	{
		if ($oldPick->getPlayerID() == $_REQUEST["player_id"]) // oops!  Remove the other pick
		{
			$oldPlayer = new OFFL_Player($_REQUEST["player_id"], $_SESSION["league_id"]);
			$oldTeam = new OFFL_FFLTeam($oldPlayer->getFFLTeamID());
			$oldTeam->dropPlayer($oldPlayer->getPlayerID());
			$oldTeam->save(); // and save
			$oldPick->setPlayerID(0);
			$oldPick->save("edit");
			break;
		}
	}
	// garbage collection
	unset($oldPlayerID);
	unset($oldPlayer);
	unset($oldDraft);
	unset($oldPicks);

	// Populate fields with form data
	if ($_SESSION["admin"])
	{
		$thisDraftPick->setFFLTeamID($_REQUEST["fflteam_id"]);
		$thisDraftPick->setFromFFLTeamID($_REQUEST["fromfflteam_id"]);
		$thisDraftPick->setFromFromFFLTeamID($_REQUEST["fromfromfflteam_id"]);
	}

	$thisDraftPick->setPlayerID($_REQUEST["player_id"]);
	$thisDraftPick->save($_REQUEST["mode"]);

?><div class="success"><?php echo $thisDraftPick->getYear(); ?> Draft Pick <?php echo $thisDraftPick->getPickNo(); ?> successfully saved.</div><p>
<a href="<?php echo $WEB_ROOT; ?>/drafts.php?mode=<?php echo $_REQUEST["mode"] ?>&year=<?php echo $_REQUEST["year"] ?>&round=<?php echo $_REQUEST["round"] ?>">Back to <?php echo $_REQUEST["year"] ?> Draft Administration</a>
<META http-equiv="refresh" content="1; URL=<?php echo $WEB_ROOT; ?>/drafts.php?<?php if ($isAdmin) echo "mode=$_REQUEST[mode]&"; ?>year=<?php echo $_REQUEST["year"] ?>&round=<?php echo $_REQUEST["round"] ?>">
<?php
}
else
{
	if(($_REQUEST["mode"] == "display") || (!isset($_REQUEST["mode"])))
	{
		if ($allrounds == 0)
		{
			// Present display (read-only) information

			// $thisDraft = new Draft($_REQUEST["year"],$_REQUEST["round"]);
			$years = $thisDraft->getDraftYears();
			$rounds = $thisDraft->getDraftRounds();

			$picks = $thisDraft->getPicks();

			?>
			View Draft Season: <?php
			for($i=0; $i<sizeof($years); $i++)
			{
				if($i>0)
					echo " | ";
				?><a href="<?php echo $WEB_ROOT; ?>/drafts.php?year=<?php echo $years[$i] ?>" <?php if ($_REQUEST["year"] == $years[$i]) echo "style=\"color: $highlightcolor; font-weight: bold;\""; ?>><?php echo $years[$i] ?></a><?php
			}
			?><br>
			View Round: <?php
			for($i=0; $i<sizeof($rounds); $i++)
			{
				if($i>0)
					echo " | ";
				?><a href="<?php echo $WEB_ROOT; ?>/drafts.php?year=<?php echo $_REQUEST["year"] ?>&round=<?php echo $rounds[$i] ?>" <?php if ($_REQUEST["round"] == $rounds[$i]) echo "style=\"color: $highlightcolor; font-weight: bold;\""; ?>><?php echo $rounds[$i] ?></a><?php
			}
			echo " | <a href=\"$WEB_ROOT/drafts.php?year=$_REQUEST[year]&round=all\">ALL</a>";
			?>
			<table border="0" width="75%">
				<tr bgcolor="#cccccc">
					<th align="right" width="10">Pick&nbsp;No</th>
					<th align="left">Team</th>
					<th align="left">Player</th>
				</tr>
			<?php
			foreach($picks as $i=>$pick)
			{
				$team = new OFFL_FFLTeam($pick->getFFLTeamID());
				if (!is_null($pick->getFromFFLTeamID()))
				{	$fromTeam = new OFFL_FFLTeam($pick->getFromFFLTeamID());	}
				if (!is_null($pick->getFromFromFFLTeamID()))
				{	$fromFromTeam = new OFFL_FFLTeam($pick->getFromFromFFLTeamID());	}
				$overall = (($_REQUEST["round"]-1)*sizeof($picks)) + ($i+1)
				?>
				<tr valign="top"<?php if($i%2){ ?> class="altline"<?php } ?>>
					<td align="right"><?php echo $pick->getPickNo() . " (" . $overall . ")"; ?></td>  
					<td align="left"><?php
				echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $pick->getFFLTeamID() . "\">" . $team->getFFLTeamFullName() . "</a>";
				if(isset($fromTeam))
				{	echo "<div class=\"small\">From <a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $pick->getFromFFLTeamID() . "\">" . $fromTeam->getFFLTeamFullName() . "</a></div>";	}
				if(isset($fromFromTeam))
				{	echo "<div class=\"small\">From <a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $pick->getFromFromFFLTeamID() . "\">" . $fromFromTeam->getFFLTeamFullName() . "</a></div>";	}
				?>
					</td>  
				<td align="left"><?php if ($pick->getPlayerID() != 0) { $plyr = new OFFL_Player($pick->getPlayerID()); ?><a href="<?php echo $WEB_ROOT; ?>/players.php?player_id=<?php echo $plyr->getPlayerID(); ?>"><?php echo $plyr->getName("FL"); ?></a>, <?php echo $plyr->getPositionAbbv() . " " . $plyr->getNFLTeamAbbv(); }
				else // if $pick...
				{
					if (($_REQUEST["round"] == $maxrd) && ($pick->getPickNo() == $maxpk))
					{
						if ($curr_tm->getUserID() == $_SESSION["user_id"])
						{
							echo "<b><a class=\"red\"";
							echo "href=\"$WEB_ROOT/drafts.php?mode=edit&year=$_REQUEST[year]&round=$maxrd&pick_no=$maxpk&owner=yes\"";
							echo ">[PICK]</a></b>";
						}
						else
						{
							echo "<b>[CURRENT PICK]</b>";
						}
					}
				  
				}?></td>  
				</tr>
				<?php
			}
			?>
			</table>
			<?php
		} // end if allrounds
		else
		{
			// $thisDraft should hold all rounds
			/*
				General procedure
				1) get teams (table columns)
				2) parse draft rounds individually.
					2a) match team ids
					2b) display pick/current/picklink as needed

				No admin mode at present.
			*/
			$years = $thisDraft->getDraftYears();
			$rounds = $thisDraft->getDraftRounds();
			?>
			View Draft Season: <?php
			for($i=0; $i<sizeof($years); $i++)
			{
				if($i>0)
					echo " | ";
				?><a href="<?php echo $WEB_ROOT; ?>/drafts.php?year=<?php echo $years[$i] ?>" <?php if ($_REQUEST["year"] == $years[$i]) echo "style=\"color: $highlightcolor; font-weight: bold;\""; ?>><?php echo $years[$i] ?></a><?php
			}
			?><br>
			View Round: <?php
			for($i=0; $i<sizeof($rounds); $i++)
			{
				if($i>0)
					echo " | ";
				?><a href="<?php echo $WEB_ROOT; ?>/drafts.php?year=<?php echo $_REQUEST["year"] ?>&round=<?php echo $rounds[$i] ?>"><?php echo $rounds[$i] ?></a><?php
			}
			echo " | <a href=\"$WEB_ROOT/drafts.php?year=$_REQUEST[year]&round=all\" style=\"color: $highlightcolor; font-weight: bold;\">ALL</a>";

			$fflteams = $myleague->getAllFFLTeams();

			$fflteam_id_array = Array();
			$fflteam_array = Array();

			$numrounds = sizeof($rounds);
			$numpicks = ceil(sizeof($pks) / $numrounds);

			for ($i = 1; $i <= $numpicks; $i++)
			{
				$x = new OFFL_DraftPick($myleague->getLeagueID(), $_REQUEST["year"], 1, $i);
				$fflteam_id_array[] = $x->getFFLTeamID();
				$fflteam_array[] = new OFFL_FFLTeam($x->getFFLTeamID());
			}
			
			echo "<table class=\"alldraft\" width=\"100%\">\n    <tr>\n        <td></td>\n";
			foreach ($fflteam_array as $fflteam)
				echo "        <th width=\"*\">" . $fflteam->getFFLTeamFullName() . "</th>\n";
			echo "    </tr>\n";

			for ($i = 1; $i <= $numrounds; $i++)
				// $rds was set at the beginning of the script (where current pick was found)
			{
				$x = new OFFL_Draft($myleague->getLeagueID(), $_REQUEST["year"], $i);
				$picks_rd = $x->getPicks();

				echo "    <tr>\n";
				echo "        <th>Round $i</th>\n";
				for ($j = 0; $j < $numpicks; $j++)
				{
					foreach ($picks_rd as $pk_rd)
					// find the correct pick (as table is not necessarily in order)
					{
						if ($pk_rd->getFFLTeamID() == $fflteam_id_array[$j])
						{
							$this_pick = $pk_rd; // put the correct pick here
							break;
						}
					}
					echo "        <td>";
					if ($this_pick->getPlayerID() != 0) // this slot taken
					{ $plyr = new OFFL_Player($this_pick->getPlayerID());
?><a href="<?php echo $WEB_ROOT; ?>/players.php?player_id=<?php echo $plyr->getPlayerID(); ?>"><?php echo $plyr->getName("FL"); ?></a>, <?php echo $plyr->getPositionAbbv() . " " . $plyr->getNFLTeamAbbv();
					}
					else // not picked yet, is it current?
					{
						if (($i == $maxrd) && ($this_pick->getPickNo() == $maxpk))
						{
							if ($curr_tm->getUserID() == $_SESSION["user_id"])
							{
								echo "<b><a class=\"red\"";
								echo "href=\"$WEB_ROOT/drafts.php?mode=edit&year=$_REQUEST[year]&round=$maxrd&pick_no=$maxpk&owner=yes\"";
								echo ">[PICK]</a></b>";
							}
							else
							{
								echo "<b>[CURRENT PICK]</b>";
							}
						}
					}
					echo "</td>\n";
				}

				echo "    </tr>\n";
			}
			echo "</table>\n";
		}
	}
	elseif($_REQUEST["mode"] == "admin")
  {
    // Present page of add/edit option
    //  Edit has drop-down of options
      $years = $thisDraft->getDraftYears();
      ?>
      <table border="0" cellpadding="3" cellspacing="0" width="50%">
        <tr valign="top">
          <td>
            <form name="adddraft" method="post" action="<?php echo $WEB_ROOT; ?>/drafts.php">
              <input type="hidden" name="mode" value="add">
              <input type="hidden" name="step" value="1">
              <input type="submit" value="Add Draft">
            </form>
          </td>
        </tr>
        <tr valign="top">
          <td>&nbsp;</td>
        </tr>
        <tr valign="top">
          <td>
            <form name="editdraft" action="<?php echo $WEB_ROOT; ?>/drafts.php">
              <input type="hidden" name="mode" value="edit">
              <select name="year" size="1">
                <option value="0"> -- Select One -- </option>
        <?php
        for($i=0; $i<sizeof($years); $i++)
        {
          ?>
                <option value="<?php echo $years[$i]; ?>"><?php echo $years[$i]; ?></option>
          <?php
        }
        ?>
              </select>
              <input type="submit" value="Edit Draft">
            </form>
          </td>
        </tr>
      </table>
      <?php

  }
  elseif($_REQUEST["mode"] == "edit")
  {
    $teams = $myleague->getAllFFLTeams();

// This prevents regular users from double drafting.
// It also protects admins using the regular draft interface.
	if ($isAdmin)
	{	$players = $myleague->getPlayers();	}
	else
	{	$players = $myleague->getPlayers(2);	}

echo "<script type=\"text/javascript\">\n"
?>
	var draftlist = new Array();

	function populateList()
	{
		// draftform: draftpick
		// first: position
		// second: player_id

		document.forms.draftpick.player_id.options.length = 0;
		var positionSelected = document.forms.draftpick.position.options[document.forms.draftpick.position.selectedIndex].value;
		var teamSelected = document.forms.draftpick.team.options[document.forms.draftpick.team.selectedIndex].value;

		var count = 0;

		for (var i = 0; i < draftlist.length; i++)
		{
			if ( ( (positionSelected == draftlist[i][1]) || (positionSelected == "all") ) && 
				 ( (teamSelected == draftlist[i][2]) || (teamSelected == "all") ) )
			{
				document.forms.draftpick.player_id.options[count] = new Option(draftlist[i][0] + ", " + draftlist[i][1] + " " + draftlist[i][2], draftlist[i][3]);
				count++;
			}
		}
	}
	
	draftlist[0] = ["No Pick", "", "", 0];
<?php
	for($i = 0; $i < sizeof($players); $i++)
	{
		echo "    draftlist[" . ($i+1) . "] = [\"" . $players[$i]->getName() . "\", \"" . $players[$i]->getPositionAbbv() . "\", \"" . $players[$i]->getNFLTeamAbbv() . "\", " . $players[$i]->getPlayerID() . "];\n";
	}
?>

</script>
<?php
    if(!empty($_REQUEST["year"]))
    {

      if(empty($_REQUEST["round"]))
        $_REQUEST["round"]=0;
      // $thisDraft = new Draft($_REQUEST["year"],$_REQUEST["round"]);
      if(isset($_REQUEST["pick_no"]))
      {
        $thisDraftPick = new OFFL_DraftPick($_SESSION["league_id"], $_REQUEST["year"],$_REQUEST["round"],$_REQUEST["pick_no"]);
        if(!empty($thisDraftPick->_emsg))
        {
          ?><div class="alert"><?php echo $thisDraft->_emsg; ?></div><?php
        }

        // Here we want to edit an individual pick
// $thisDraft variable contains what we need

?>
<form name="draftpick" method="post" action="<?php echo $WEB_ROOT; ?>/drafts.php">
  <input type="hidden" name="mode" value="<?php echo $_REQUEST["mode"] ?>">
  <input type="hidden" name="type" value="<?php echo $_REQUEST["type"] ?>">
  <input type="hidden" name="action" value="save">

  <table border="0">
    <tr valign="top">
      <td align="right">Year:</td>
      <td align="left" colspan="3">
    <?php echo $thisDraftPick->getYear(); ?>
    <input type="hidden" name="year" value="<?php echo $thisDraftPick->getYear() ?>">
      </td>
    </tr>
    <tr valign="top">
      <td align="right">Round:</td>
      <td align="left" colspan="3">
    <?php echo $thisDraftPick->getRoundNo(); ?>
    <input type="hidden" name="round" value="<?php echo $thisDraftPick->getRoundNo() ?>">
      </td>
    </tr>
    <tr valign="top">
      <td align="right">Pick No:</td>
      <td align="left" colspan="3">
    <?php echo $thisDraftPick->getPickNo(); ?>
    <input type="hidden" name="pick_no" value="<?php echo $thisDraftPick->getPickNo() ?>">
      </td>
    </tr>
    <tr valign="top">
      <td align="right">Team:</td>
      <td align="left" colspan="3">
<?php if ($isAdmin) { ?>
        <select name="fflteam_id" size="1">
          <option value="0"> -- Select One -- </option>
      <?php
        foreach($teams as $team)
        {
          ?>
            <option value="<?php echo $team->getFFLTeamID(); ?>"<?php if($team->getFFLTeamID() == $thisDraftPick->getFFLTeamID()) { ?> selected<?php } ?>><?php echo $team->getFFLTeamFullName(); ?></option>
          <?php
        }
      ?>
        </select>
<?php } else // not an admin
	{ ?>
		<?php $thisTeam = new OFFL_FFLTeam($thisDraftPick->getFFLTeamID()); echo $thisTeam->getFFLTeamFullName(); ?>
		<input type="hidden" name="fflteam_id" value="<?php echo $thisDraftPick->getFFLTeamID(); ?>">
<?php } ?>
      </td>
    </tr>
    <tr valign="top">
      <td align="right">From Team:</td>
      <td align="left" colspan="3">
<?php if ($isAdmin) { ?>
        <select name="fromfflteam_id" size="1">
          <option value="0"></option>
      <?php
        foreach($teams as $team)
        {
          ?>
            <option value="<?php echo $team->getFFLTeamID(); ?>"<?php if($team->getFFLTeamID() == $thisDraftPick->getFromFFLTeamID()) { ?> selected<?php } ?>><?php echo $team->getFFLTeamFullName(); ?></option>
          <?php
        }
      ?>
        </select>
<?php } else // not an admin
	{ ?>
		<?php $thisFromTeam = new OFFL_FFLTeam($thisDraftPick->getFromFFLTeamID()); echo $thisFromTeam->getFFLTeamFullName(); ?>
		<input type="hidden" name="fromfflteam_id" value="<?php echo $thisDraftPick->getFromFFLTeamID(); ?>">
<?php } ?>
      </td>
    </tr>
    <tr valign="top">
      <td align="right">From From Team:</td>
      <td align="left" colspan="3">
<?php if ($isAdmin) { ?>
        <select name="fromfromfflteam_id" size="1">
          <option value="0"></option>
      <?php
        foreach($teams as $team)
        {
          ?>
            <option value="<?php echo $team->getFFLTeamID(); ?>"<?php if($team->getFFLTeamID() == $thisDraftPick->getFromFromFFLTeamID()) { ?> selected<?php } ?>><?php echo $team->getFFLTeamFullName(); ?></option>
          <?php
        }
      ?>
        </select>
<?php } else // not an admin
	{ ?>
		<?php $thisFromFromTeam = new OFFL_FFLTeam($thisDraftPick->getFromFromFFLTeamID()); echo $thisFromFromTeam->getFFLTeamFullName(); ?>
		<input type="hidden" name="fromfromfflteam_id" value="<?php echo $thisDraftPick->getFromFromFFLTeamID(); ?>">
<?php } ?>
      </td>
    </tr>
    <tr valign="top">
		<td align="right">Player:</td>
		<td align="left">
			<select name="position" size="10" style="overflow:hidden; padding-right:15px;" onchange="populateList()">
				<option value="all" selected>All</option>
<?php
	$x = new OFFL_Position();
	$positions = $x->getAllPositions();
	foreach ($positions as $position)
		if (!strstr($position->getPositionAbbv(), "FLEX"))
			echo "				<option value=\"" . $position->getPositionAbbv() . "\">" . $position->getPositionAbbv() . "s</option>\n";
	unset ($positions);
	unset ($x);
	?>
			</select>
		</td><td>
			<select name="team" size="10" style="padding-right: 5px;" onchange="populateList()">
				<option value="all" selected>All</option>
<?php
	$x = new OFFL_NFLTeam();
	$nflteams = $x->getAllNFLTeams();
	foreach ($nflteams as $nflteam)
		echo "				<option value=\"" . $nflteam->getNFLTeamAbbv() . "\">" . $nflteam->getNFLTeamAbbv() . "</option>\n";
	unset ($nflteams);
	unset ($x);
	?>
			</select>
		</td><td width="270px">
			<select name="player_id" size="10" style="width:100%">
				<option value="0">No Pick</option>
<?php
			for ($i = 0; $i < sizeof($players); $i++)
			{
?>				<option value="<?php echo $players[$i]->getPlayerID(); ?>"<?php if($players[$i]->getPlayerID() == $thisDraftPick->getPlayerID()) { ?> selected<?php } ?>><?php echo $players[$i]->getName() . ", " . $players[$i]->getPositionAbbv() . " " . $players[$i]->getNFLTeamAbbv(); ?></option>
<?php		} ?>
			</select>
		</td>

<!-- begin old player pick section -->	  
<!-- end old player pick section -->	
	
	</tr>
    <tr valign="top">
      <td colspan="3"><input type="submit" value="Save Pick"></td>
    </tr>
  </table>

</form>

<?php
      }
      else
      {
        // Here we present a table similar to the display table
        // $thisDraft = new Draft($_REQUEST["year"],$_REQUEST["round"]);
        $years = $thisDraft->getDraftYears();
        $rounds = $thisDraft->getDraftRounds();
    
        $picks = $thisDraft->getPicks();
        ?>
        Edit Draft Season: <?php
        for($i=0; $i<sizeof($years); $i++)
        {
          if($i>0)
            echo " | ";
          ?><a href="<?php echo $WEB_ROOT; ?>/drafts.php?mode=edit&year=<?php echo $years[$i] ?>"><?php echo $years[$i] ?></a><?php
        }
        ?><br>
        Edit Round: <?php
        for($i=0; $i<sizeof($rounds); $i++)
        {
          if($i>0)
            echo " | ";
          ?><a href="<?php echo $WEB_ROOT; ?>/drafts.php?mode=edit&year=<?php echo $_REQUEST["year"] ?>&round=<?php echo $rounds[$i] ?>"><?php echo $rounds[$i] ?></a><?php
        }
        ?>
        <table border="0" width="75%">
          <tr bgcolor="#cccccc">
            <th align="right" width="10">Pick&nbsp;No</th>
            <th align="left">Team</th>
            <th align="left">Player</th>
          </tr>
          <?php
          foreach($picks as $i=>$pick)
          {
			$pick_team = new OFFL_FFLTeam($pick->getFFLTeamID());
            $overall = (($_REQUEST["round"]-1)*sizeof($picks)) + ($i+1)
            ?>
            <tr valign="top"<?php if($i%2){ ?> class="altline"<?php } ?>>
              <td align="right"><strong><a class="red" href="<?php echo $WEB_ROOT; ?>/drafts.php?mode=edit&year=<?php echo $_REQUEST["year"] ?>&amp;round=<?php echo $_REQUEST["round"] ?>&amp;pick_no=<?php echo $pick->getPickNo() ?>">[EDIT]</a></strong> <?php echo $pick->getPickNo() . " (" . $overall . ")"; ?></td>
              <td align="left"><?php
                echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $pick->getFFLTeamID() . "\">" . $pick_team->getFFLTeamFullName() . "</a>";
                if($pick->getFromFFLTeamID() > 0)
			    {
					$pick_fromteam = new OFFL_FFLTeam($pick->getFromFFLTeamID());
					echo "<div class=\"small\">From <a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $pick->getFromFFLTeamID() . "\">" . $pick_fromteam->getFFLTeamFullName() . "</a></div>";
				}
                if($pick->getFromFromFFLTeamID() > 0)
				{
					$pick_fromfromteam = new OFFL_FFLTeam($pick->getFromFromFFLTeamID());
					echo "<div class=\"small\">From <a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $pick->getFromFromFFLTeamID() . "\">" . $pick_fromfromteam->getFFLTeamFullName() . "</a></div>";
				}
                ?>
              </td>
              <td align="left"><?php if ($pick->getPlayerID() != 0) { ?><a href="<?php echo $WEB_ROOT; ?>/players.php?player_id=<?php echo $pick->getPlayerID(); $pick_pl = new OFFL_Player($pick->getPlayerID()); ?>"><?php echo $pick_pl->getName("FL"); ?></a>, <?php echo $pick_pl->getPositionAbbv(); } ?></td>
            </tr>
            <?php
          }
          ?>
        </table>
        <?php
    
      }
    }
    else
    {
      // Print error
      ?><div class="alert">No year specified.</div><?php
    }
  }
  elseif($_REQUEST["mode"] == "add")
  {
    if($_REQUEST["step"] == "1")
	/*
		VARIABLES POSTED IN THIS STEP:
		mode // aliased to $_REQUEST
		step
		picks
		year
		rounds
		type

	*/
    {
      // Get number of teams from teams table
      $numteams = $myleague->getNumberOfFFLTeams();
      ?><h3>Step 1:  Draft Format</h3>
      There are <?php echo $numteams; ?> teams in this league.  Therefore, we will create a draft with <?php echo $numteams; ?> picks per round.
      <p>
      Please fill out the form for the remaining needed information.
      <form name="adddraft" method="post" action="<?php echo $WEB_ROOT; ?>/drafts.php">
        <input type="hidden" name="mode" value="add">
        <input type="hidden" name="step" value="2">
        <input type="hidden" name="picks" value="<?php echo $numteams; ?>">
        <table border="0">
          <tr valign="top">
            <th align="right">Year:</th>
            <td align="left"><input type="text" name="year" size="4" maxlength="4" value="<?php echo $thisDraft->getMaxDraftYear()+1; ?>"></td>
          </tr>
          <tr valign="top">
            <th align="right">No. of Rounds:</th>
            <?php
            // Assume that number of rounds would be number of roster spots
            $roster_size = $control->getValue("CONFIG_MAX_TOTAL_PLAYERS");
            ?>
            <td align="left"><input type="text" name="rounds" size="4" maxlength="4" value="<?php echo $roster_size; ?>"></td>
          </tr>
          <tr valign="top">
            <th align="right">Draft Type:</th>
            <td align="left">
              <input type="radio" name="type" value="straight" checked>Straight
              <br /><input type="radio" name="type" value="serpentine">Serpentine
			  <br /><input type="radio" name="type" value="random">Random
            </td>
          </tr>
          <tr valign="top">
            <td colspan="2">
              <input type="submit" value="Proceed to Step 2">
            </td>
          </tr>
        </table>
      </form>
      <?php
    }
    elseif($_REQUEST["step"] == "2")
	/*
		VARIABLES POSTED IN THIS STEP:
		mode // aliased to $_REQUEST
		step
		picks
		year
		rounds
		type

		size$j
		random
	*/
    {
      $teams = $myleague->getAllFFLTeams();
      ?>
      <form name="adddraft" method="post" action="<?php echo $WEB_ROOT; ?>/drafts.php">
        <input type="hidden" name="mode" value="add">
        <input type="hidden" name="step" value="3">
        <input type="hidden" name="picks" value="<?php echo $_REQUEST["picks"] ?>">
        <input type="hidden" name="year" value="<?php echo $_REQUEST["year"] ?>">
        <input type="hidden" name="rounds" value="<?php echo $_REQUEST["rounds"] ?>">
        <input type="hidden" name="type" value="<?php echo $_REQUEST["type"] ?>">
        <h3>Step 2:  Draft Order</h3>
        <p>Please enter the base order of the rounds.  This order will be used to create the draft picks for the entire draft.  Do not try to reflect pick transactions or lottery assignments, unless you want them reflected in every round of the draft.  Alternately, select the "Random Draft Order" box and the system will order for you.
		<p>If you selected a Random draft in the previous step, you may skip this step.
        <table border="0">
          <tr valign="top">
            <th align="right">#</th>
            <th align="left">FFL Team</th>
          </tr>
          <?php  for($i = 1; $i <= sizeof($teams); $i++)
              { ?>       
          <tr valign="top">
            <td align="right"><?php echo $i ?></td>
            <td>
              <select name="slot<?php echo $i ?>" size="1">
                <option value="0"> -- Select One -- </option>
                <?php  foreach($teams as $team)
                    { ?>
                <option value="<?php echo $team->getFFLTeamID(); ?>"><?php echo $team->getFFLTeamFullName(); ?></option>
                <?php  } ?>
              </select>
            </td>
          </tr>
          <?php  } ?>
		  <tr>
			<td>Random draft order</td><td><input type="checkbox" name="random" /></td>
		  </tr>
          <tr>
            <td colspan="2"><input type="submit" value="Proceed to Step 3"></td>
          </tr>
        </table>
      </form>
      <?php
    }
    elseif($_REQUEST["step"] == "3")
    {
      // Should have everything we need to create the draft
      ?><h3>Step 3:  Creating Draft</h3><?php
	    $order = "";
        if (($_REQUEST["random"] == "on") || ($_REQUEST["type"] == "random"))
		{
			$teams = $myleague->getAllFFLTeams();
			$tm_order = array();
			$tm_count = sizeof($teams);
			$tms_left = $tm_count;
			while ($tms_left > 0)
			{
				$tm = mt_rand(0, $tm_count-1);
				if(!in_array($teams[$tm]->getFFLTeamID(), $tm_order))
				{
					$tm_order[] = $teams[$tm]->getFFLTeamID();
					$tms_left--;
				}
			}
			// now we have the draft order (by teamid) in $tm_order, map it to order
			foreach($tm_order as $tm)
			{
				$order .= $tm . "|";
			}
			$order = substr($order, 0, strlen($order)-1);
		}
		else
		{
	    for($j=1; $j<=$_REQUEST["picks"]; $j++)
		    {
			if($j>1)
				$order .= "|";
		    $order .= $_REQUEST["slot$j"];
		}
	}
//	echo "<br>order = $order<br>";
//	echo "year = $_REQUEST[year]<br>";
//	echo "rounds = $_REQUEST[rounds]<br>";
//	echo "type = $_REQUEST[type]<br>";
    $thisDraft->createDraft($myleague->getLeagueID(), $_REQUEST["year"], $_REQUEST["rounds"], $_REQUEST["type"], $order);
      ?><div class="success"><?php echo $thisDraft->getYear(); ?> Draft successfully created and saved.</div><p>
<a href="<?php echo $WEB_ROOT; ?>/drafts.php?mode=edit&year=<?php echo "$_REQUEST[year]"; ?>">Back to <?php echo "$_REQUEST[year]"; ?> Draft Administration</a><?php

    }
  }
}

require($DOC_ROOT . "/lib/footer.php"); ?>
Return current item: Online Fantasy Football League