Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/waivers.php
<?php
/**
 * Waiver Claims Management
 *
 * Displays {@link OFFL_Waiver waiver claims} and related interfaces.  Users may alter their claim priorities or drop their claims.  Admins may alter the same for any team.
 *
 * DESIRED ADDITIONS
 * It'd be nice to claim a player on waivers from this page.  I'd need an interface to allow a player drop as well.
 * Should be pretty much a copy/paste from rosters.php
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

$pageTitle = "Waiver Claims Management";
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php");

	$continue_with_page = TRUE;

	if ($_GET["mode"] == "edit")
	{
		$this_waiver = new OFFL_Waiver($_GET["waiver_id"]);
		if ($_SESSION["fflteam_id"] != $this_waiver->getFFLTeamID())
		{
			echo "<h2 class=\"error\">Waiver management action unauthorized.  Check your login</h2>\n";
		}
		else
		{
			$waivers = $this_waiver->getAllTeamWaivers($_SESSION["fflteam_id"]);
			switch ($_GET["action"])
			{
				case "moveup":
					if ($this_waiver->getPriority() > 1)
					{
						foreach ($waivers as $waiver)
						{
							if ($waiver->getPriority() == ($this_waiver->getPriority() - 1))
							{
								$waiver->setPriority($waiver->getPriority() + 1);
								$this_waiver->setPriority($this_waiver->getPriority() - 1);
								
								$waiver->save();
								$this_waiver->save();
								echo "<h2 class=\"success\">Waiver priority change successful</h2>\n";
								break;
							}
						}
					}
					break;
				case "movedown":
					foreach ($waivers as $waiver)
					{
						if ($waiver->getPriority() == ($this_waiver->getPriority() + 1))
						{
							$waiver->setPriority($waiver->getPriority() - 1);
							$this_waiver->setPriority($this_waiver->getPriority() + 1);
							
							$waiver->save();
							$this_waiver->save();
							echo "<h2 class=\"success\">Waiver priority change successful</h2>\n";
							break;
						}
					}
					break;
				case "delete":
					$player = new OFFL_Player($this_waiver->getPlayerID(), $_SESSION["league_id"]);
					if ($this_waiver->getDropPlayerID() != 0)
						$dropPlayer = new OFFL_Player($this_waiver->getDropPlayerID(), $_SESSION["league_id"]);
					$this_waiver->deleteWaiver();
					$message = "<h2 class=\"success\">Waiver claim to add " . $player->getName();
					if ($this_waiver->getDropPlayerID() != 0)
						$message .= " for " . $dropPlayer->getName();
					$message .= " deleted successfully.</h2>\n";
					echo $message;
					break;
			}
		}
	}
	if ($continue_with_page)
	{

		$x = new OFFL_Waiver();
		$waivers = $x->getAllTeamWaivers($_SESSION["fflteam_id"]);
		$num_waivers = sizeof($waivers);
?>
<table><tr>
	<th>Pending Waiver Claims</th><th>Players on Waivers</th><th>Team Waiver Priority</th>
  </tr><tr>
	<td valign="top" >
<?php
		if ($num_waivers == 0)
		{
			echo "No waiver claims pending.";
		}
		else
		{
	?>		<table><?php
			foreach ($waivers as $waiver)
			{
				echo "	<tr>\n";
				echo "		<td class=\"droplink\">\n";
				if ($num_waivers > 1)
				// add ability to move waivers up or down
				{
					echo " <a href=\"$WEB_ROOT/waivers.php?mode=edit&waiver_id=" . $waiver->getWaiverID() . "&action=moveup\">UP</a> \n";
					echo " <a href=\"$WEB_ROOT/waivers.php?mode=edit&waiver_id=" . $waiver->getWaiverID() . "&action=movedown\">DOWN</a> \n";
				}
				echo " <a href=\"$WEB_ROOT/waivers.php?mode=edit&waiver_id=" . $waiver->getWaiverID() . "&action=delete\">DELETE</a> \n";
				echo "		</td>\n";

				$player = new OFFL_Player($waiver->getPlayerID(), $_SESSION["league_id"]);
				if ($waiver->getDropPlayerID() != 0)
					$dropPlayer = new OFFL_Player($waiver->getDropPlayerID(), $_SESSION["league_id"]);
				echo "		<td style=\"text-align:right;\">Add " . $player->getName() . "</td>\n";
				if ($waiver->getDropPlayerID() != 0)
				{
					echo "		<td>for</td>\n		<td>" . $dropPlayer->getName() . "</td>\n";
				}
				else
				{
					echo "		<td colspan=\"2\"></td>\n";
				}
				echo "	</tr>\n";
			}
?>		</table><?php
		}
?>	</td>
	<td valign="top">
<?php
//	$waiverPlayers = $p->getAllActiveFreeAgentPlayers(0,-1);
	$waiverPlayers = $myleague->getPlayers(2,1); // get all players on waivers
	if (sizeof($waiverPlayers) == 0)
	{
		echo "No players currently on waivers\n";
	}
	else
	{
		echo "<table>\n";
		foreach ($waiverPlayers as $player)
		{
			echo "<tr><td><a href=\"$WEB_ROOT/players.php?player_id=" . $player->getPlayerID() . "\">" . $player->getName() . "</a>, " . $player->getPositionAbbv() . " " . $player->getNFLTeamAbbv() . "</td><td>until " . gmdate("n/j/y", GMTOffsetTime($player->getWaiverStatus())) . "</td></tr>\n";
		}
		echo "</table>\n";
	}

?>

	</td>
	<td valign="top">
		<table>
<?php
		function sortFFLPriority($t1, $t2)
		{
			if ($t1->getWaiverPriority() < $t2->getWaiverPriority())
				return -1;
			if ($t1->getWaiverPriority() > $t2->getWaiverPriority())
				return 1;
			return 0;
		}

		$teams = $myleague->getAllFFLTeams();
		usort ($teams, "sortFFLPriority");

		foreach ($teams as $team)
		{
			echo "	<tr>\n";
			echo "		<td><a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $team->getFFLTeamID() . "\">" . $team->getFFLTeamCity() . " " . $team->getFFLTeamName() . "</a></td>\n";
			echo "	</tr>\n";
		}
?>		</table>
	</td>
</tr></table>
<?php
	} // end if mode

/**
 * Adds the page footer (Copyright notice, contact info, FFL info, and such as that)
 */
require($DOC_ROOT . "/lib/footer.php"); ?>
Return current item: Online Fantasy Football League