<?php
/**
* Auction Management
*
* Displays {@link OFFL_AuctionValues auction values} and related interfaces.
* Admins may enter auction values for any player on auction day.
*
* @author Brad Schwie <hide@address.com>
* @version OFFL v0.2
* @package offl-ui
*/
$continue_with_page = TRUE;
if(empty($_REQUEST["action"]))
{ $_REQUEST["action"] = NULL; }
if(empty($_REQUEST["mode"]))
{ $_REQUEST["mode"] = NULL; }
if(empty($_REQUEST["view"]))
{ $_REQUEST["view"] = NULL; }
if(empty($_REQUEST["fflteam_id"]))
{ $_REQUEST["fflteam_id"] = NULL; }
$pageTitle = "Auction Values";
require_once("offlconfig.php");
require_once("$DOC_ROOT/lib/header.php");
$isAdmin = FALSE;
if(($_REQUEST["mode"] == "admin") && $_SESSION["admin"])
{ $isAdmin = TRUE; }
if(isset($_REQUEST["action"]))
{
// keep access consistent
$_REQUEST["action"] = $_REQUEST["action"];
$_REQUEST["player_id"] = $_REQUEST["player_id"];
}
if(empty($_REQUEST["year"]))
{ $_REQUEST["year"] = getThisYear(); }
if ($_REQUEST["mode"] == "admin" || $_REQUEST["mode"] == "admin")
{
if ($_REQUEST["step"] == "0" || $_REQUEST["step"] == "0")
{
?>
<table><tr><td>
<form name="auctionvalueentry" method="post" action="<?php echo $WEB_ROOT; ?>/auction.php" />
<input type="hidden" name="action" value="auctionvalueentry" />
<input type="hidden" name="step" value="1" />
<input type="submit" value="Update Auction" />
</form>
</td>
<td>
<form name="deletionofauctionvalues" method="post" action="<?php echo $WEB_ROOT; ?>/auction.php" />
<input type="hidden" name="mode" value="admin" />
<input type="hidden" name="step" value="1" />
<input type="submit" value="Delete All Auction Values" />
</form>
</table>
<?php
}
elseif ($_REQUEST["step"] == "1" || $_REQUEST["step"] == "1")
{
?>
Are you sure you'd like to delete all auction values from the database?<br>
<table><tr><td>
<form name="yes" method="post" action="<?php echo $WEB_ROOT; ?>/auction.php" />
<input type="hidden" name="mode" value="admin" />
<input type="hidden" name="step" value="2" />
<input type="submit" value="Yes" />
</form>
</td>
<td>
<form name="no" method="post" action="<?php echo $WEB_ROOT; ?>/auction.php" />
<input type="hidden" name="mode" value="admin" />
<input type="hidden" name="step" value="3" />
<input type="submit" value="No" />
</form>
</table>
<?php
}
elseif ($_REQUEST["step"] == "2" || $_REQUEST["step"] == "2")
{
$leagueid = 1;
$playerid = 1;
$auctionvalue = new OFFL_AuctionValue($playerid, $leagueid);
$auctionvalue->deleteAllAuctionValues();
$continue_with_page = FALSE;
?>
<div class="success">All auction values deleted from database.</div>
<META http-equiv="refresh" content="1;URL=<?php echo $WEB_ROOT; ?>/auction.php?mode=admin&step=0" /><?php
}
else // ($_REQUEST["step"] == "3" || $_REQUEST["step"] == "3")
{
?>
<div class="success">Auction values retained.</div>
<META http-equiv="refresh" content="1;URL=<?php echo $WEB_ROOT; ?>/auction.php?mode=admin&step=0" /><?php
}
}
else
{
if ($_REQUEST["action"] == "save")
// process the data!
{
// collect roster info
// DO NOT SAVE YET
// call FFLTeam->validateRosterFlex($roster)
// if no errors, save info (return to edit screen?)
// otherwise return errors and go back to edit screen
$thisTeam = new OFFL_FFLTeam($_REQUEST["fflteam_id"]);
$i = 1;
$roster = array();
$newstarters = array();
$newbenchers = array();
while(TRUE)
{
if(empty($_REQUEST["player$i"]))
{ break; }
$x = new OFFL_Player($_REQUEST["playerid$i"], $thisTeam->getLeagueID());
if ($x->getStarter() != $_REQUEST["player$i"])
{
if ($x->getStarter())
{ $newbenchers[] = $_REQUEST["playerid$i"]; }
else
{ $newstarters[] = $_REQUEST["playerid$i"]; }
}
$x->setStarter($_REQUEST["player$i"]);
array_push($roster, $x);
$i++;
}
// needs a sort, otherwise active WRs can lock out RB flex spots, etc.
usort($roster, "cmp_players");
$errors = $thisTeam->validateRosterFlex($roster);
foreach ($errors as $error)
{ echo "<p class=\"error\">Error: $error</p>\n"; }
if (sizeof($errors) == 0)
{
$transaction = new OFFL_Transaction();
$transaction->setTransType("lineup");
$transaction->setLeagueID($thisTeam->getLeagueID());
$transaction->save();
foreach($roster as $player)
{
if (in_array($player->getPlayerID(), $newbenchers))
{
$transItem = new OFFL_TransactionItem();
$transItem->setTransID($transaction->getTransID());
$transItem->setTransType("bench");
$transItem->setPlayerID($player->getPlayerID());
$transItem->setFromFFLTeamID($player->getFFLTeamID());
$transItem->setToFFLTeamID($player->getFFLTeamID());
$transItem->save();
}
elseif (in_array($player->getPlayerID(), $newstarters))
{
$transItem = new OFFL_TransactionItem();
$transItem->setTransID($transaction->getTransID());
$transItem->setTransType("start");
$transItem->setPlayerID($player->getPlayerID());
$transItem->setFromFFLTeamID($player->getFFLTeamID());
$transItem->setToFFLTeamID($player->getFFLTeamID());
$transItem->save();
}
$thisTeam->setStartStatus($player->getPlayerID(), $player->getStarter());
}
// finally, save the team
$thisTeam->save();
echo "<h2 class=\"success\">Roster changes saved</h2>";
}
else
{ echo "<p style=\"color:#F00; font-weight:bold;\">Changes not saved.</p>\n"; }
// add the meta here and die?
}
elseif ($_REQUEST["action"] == "auctionvalueentry" || $_REQUEST["action"] == "auctionvalueentry")
{
// we need a drop/add dialog.
// OK, start by listing free agents a la draft pick method
// then allow for dropping a roster player
// validate the proposed roster
// prompt for confirmation (step 2)
// save changes
// return to regular rosters display
if ($_REQUEST["step"] == "1" || $_REQUEST["step"] == "1")
{
$thisTeam = new OFFL_FFLTeam(1);
$thisLeague = new OFFL_League($thisTeam->getLeagueID());
$teams = $thisLeague->getAllFFLTeams();
$thisTeam_players = $thisTeam->getRoster();
// this array contains all active non-roster players (FAs and Waivers) in this league
$players = $thisLeague->getPlayers(2);
echo "<script type=\"text/javascript\">\n"
?>
var freeagentlist = new Array();
function populateList()
{
// draftform: freeagentpick
// first: position
// second: player_id
document.forms.freeagentpick.player_id.options.length = 0;
var positionSelected = document.forms.freeagentpick.position.options[document.forms.freeagentpick.position.selectedIndex].value;
var teamSelected = document.forms.freeagentpick.team.options[document.forms.freeagentpick.team.selectedIndex].value;
var count = 1;
var name = "";
document.forms.freeagentpick.player_id.options[0] = new Option("No Add", 0);
for (var i = 1; i < freeagentlist.length; i++)
{
if ( ( (positionSelected == freeagentlist[i][1]) || (positionSelected == "all") ) &&
( (teamSelected == freeagentlist[i][2]) || (teamSelected == "all") ) )
{
document.forms.freeagentpick.player_id.options[count] = new Option(freeagentlist[i][0] + ", " + freeagentlist[i][1] + " " + freeagentlist[i][2], freeagentlist[i][3]);
count++;
}
}
document.forms.freeagentpick.player_id.options[0].defaultSelected = true;
}
function updateWaivers()
{
for (var i = 0; i < freeagentlist.length; i++)
{
if (freeagentlist[i][3] == document.forms.freeagentpick.player_id.options[document.forms.freeagentpick.player_id.selectedIndex].value)
{
document.forms.freeagentpick.waiver_status.value = freeagentlist[i][4];
break;
}
}
}
freeagentlist[0] = ["No Add", "", "", 0, ""];
<?php
foreach($players as $i=>$player)
{
$waiver_status = $player->getWaiverStatus();
if (is_null($waiver_status))
{
$waiver_status = "Free Agent";
}
else
{
if ((time() - $waiver_status) > 0)
$waiver_status = "Waiver Pending";
else
{
$temp = date("D, F j", $waiver_status);
$waiver_status = "On Waivers until " . $temp;
}
}
echo " freeagentlist[" . ($i+1) . "] = [\"" . $player->getName() . "\", \"" . $player->getPositionAbbv() . "\", \"" . $player->getNFLTeamAbbv() . "\", " . $player->getPlayerID() . ", \"$waiver_status\"];\n";
}
?>
</script>
<form name="freeagentpick" method="post" action="<?php echo $WEB_ROOT; ?>/auction.php" onSubmit="checkform(fflteam_id)">
Select a team:
<select name="fflteam_id">
<option value="0"> -- Select One -- </option>
<?php
$fflteams = $myleague->getAllFFLTeams();
foreach($fflteams as $fflteam)
{
?>
<option value="<?php echo $fflteam->getFFLTeamID(); ?>"<?php
if(($_REQUEST["mode"] == "edit") && ($fflteam->getFFLTeamID() == $thisPlayer->getFFLTeamID())) { ?> selected<?php } ?>><?php echo $fflteam->getFFLTeamFullName(); ?></option>
<?php
}
?>
</select>
<input type="hidden" name="action" value="auctionvalueentry" />
<input type="hidden" name="step" value="2" />
<?php if ($isAdmin) echo " <input type=\"hidden\" name=\"mode\" value=\"admin\" />\n"; ?>
<table>
<tr>
<th colspan="3"></th>
<th>Available Players</th>
<th>Winning Bid Price</th>
</tr>
<tr valign="top">
<td align="right"></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%" onchange="updateWaivers()">
<option value="0" selected>No Add</option>
<?php
for ($i = 0; $i < sizeof($players); $i++)
{
?> <option value="<?php echo $players[$i]->getPlayerID(); ?>"><?php echo $players[$i]->getName() . ", " . $players[$i]->getPositionAbbv() . " " . $players[$i]->getNFLTeamAbbv(); ?></option>
<?php } ?>
</select>
</td>
<td align="center">
<input type="text" name="auction_value_entry" size="5" value="" />
</select>
</td>
</tr>
<tr>
<td colspan="4" align="right" style="padding-right: 50px;">
Waiver status: <input type="text" name="waiver_status" size="42" value="" disabled style="color:#000 !important; " />
</td>
<td colspan>
<input type="submit" value="Submit Transaction" />
</td>
</tr>
</table>
</form>
<?php
$continue_with_page = FALSE;
}
elseif ($_REQUEST["step"] == "2")
{
$thisTeam = new OFFL_FFLTeam($_REQUEST["fflteam_id"]);
$thisLeague = new OFFL_League($thisTeam->getLeagueID());
$player = new OFFL_Player($_REQUEST["player_id"], $thisTeam->getLeagueID());
$isWaiver = FALSE;
$auctionvalueentry = $_REQUEST["auction_value_entry"];
if ($_REQUEST["fflteam_id"] == 0 && $_REQUEST["auction_value_entry"] > 0)
{
echo "<h2 class=\"error\">No FFL team selected. Try again.</h2>\n";
$continue_with_page = FALSE;
}
elseif ($_REQUEST["fflteam_id"] > 0 && $_REQUEST["auction_value_entry"] > 0)
{
$auctionvalueentry = $_REQUEST["auction_value_entry"];
$roster_old = $thisTeam->getRoster();
$roster = array();
$roster_removed = array(); // catch the players who are dropped
if ($_REQUEST["player_id"] > 0)
{
$player->setStarter(0);
// $player->setFFLTeamID($thisTeam->getFFLTeamID());
$roster[] = $player;
$auctionvalue = new OFFL_AuctionValue($player->getPlayerID(), $thisTeam->getLeagueID());
$auctionvalue->setAuctionValue($auctionvalueentry);
$auctionvalue->deleteAuctionValue();
$auctionvalue->save();
}
foreach($roster_old as $plyr)
{
if ($plyr->getPlayerID() == $_REQUEST["drop_player_id"])
{
$roster_removed[] = $plyr;
continue;
}
$roster[] = $plyr;
}
usort($roster, "cmp_players");
$errors = $thisTeam->validateRosterFlex($roster);
if (!sizeof($errors))
{
echo "<h2 class=\"success\">Transaction complete!</h2>\n";
$continue_with_page = FALSE;
$thisTeam->addPlayer($_REQUEST["player_id"]);
$thisTeam->save();
?><META http-equiv="refresh" content="1;URL=<?php echo $WEB_ROOT; ?>/auction.php?action=auctionvalueentry&step=1" /><?php
}
} // end else player has an auction entry
}// end else for Step 2
}
if ($continue_with_page)
{
/* *******************************************************
REGULAR PAGE DISPLAY BEGINS HERE
*******************************************************
*/
// Default page view showing auction values of each player
// and the totals for each team.
// Stub team object -- needed?
$thisTeam = new OFFL_FFLTeam();
// No fflteam_id is selected, show list of teams and owners
?><table border="0" cellpadding="3" cellspacing="0" width="100%">
<?php
$teams = $myleague->getAllFFLTeams();
$t=0;
$total_players = $control->getValue("CONFIG_MAX_TOTAL_PLAYERS");
$min_per_player = $control->getValue("CONFIG_MIN_PER_PLAYER");
foreach($teams as $team)
{
$players = $team->getRoster();
$teampayroll = 0;
$p=0;
$t++;
if ($t == 1 || $t == 5 || $t == 9 || $t == 13)
{
?>
<tr><td>
<?php
}
?>
</td><td valign="top"><div class="big"><?php echo $team->getFFLTeamFullName(); ?></div>
<?php
foreach($players as $player)
{
$auctionvalue = new OFFL_AuctionValue($player->getPlayerID(), $myleague->getLeagueID());
?>
<?php echo $player->getName() . "; " . $player->getPositionAbbv() . " $" . $auctionvalue->getAuctionValue(); ?><br>
<?php
$teampayroll += $auctionvalue->getAuctionValue();
$p++;
}
echo "Team has spent $" . $teampayroll . "<br>";
$capremaining = $control->getValue("CONFIG_SALARY_CAP") - $teampayroll;
echo "Cap money remaining is $" . $capremaining;
if ($capremaining == 0 && $total_players - $p == 0)
{
echo "<br><div class =\"success\">Roster is complete.</div>";
}
elseif ($capremaining < 0)
{
echo "<br><div class =\"alert\">Team has overspent.</div>";
}
elseif ($capremaining >= 0 && $total_players - $p == 0)
{
echo "<br><blink><div class =\"success\">Roster is complete.</div></blink>";
}
elseif ($capremaining > 0 && ($capremaining / ($total_players - $p)) < 1)
{
echo "<br><div class =\"alert\">Team has overspent.</div>";
}
?><br><?php
}
?>
</td></table>
<?php
if($_SESSION["admin"])
{
?>
<form name="auctionvalueentry" method="post" action="<?php echo $WEB_ROOT; ?>/auction.php" />
<input type="hidden" name="action" value="auctionvalueentry" />
<input type="hidden" name="step" value="1" />
<input type="submit" value="Update Auction" />
</form>
<?php
if ($control->getValue("CONFIG_AUCTION_SCREEN_REFRESH") > 0)
{
?>
<META http-equiv="refresh" content="<?php
echo $control->getValue("CONFIG_AUCTION_SCREEN_REFRESH");
?>;URL=<?php
echo $WEB_ROOT;
?>/auction.php" />
<?php
}
}
?></td>
</table><?php
}
} // end if continue_with_page
require($DOC_ROOT . "/lib/footer.php"); ?>