Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/leagues.php
<?php
/**
 * League interface
 *
 * Displays {@link OFFL_League leagues} segregated by presence of user team.  Will also allow league edits to admins.
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

$pageTitle = "League Overview";
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php"); 

if (isset($_POST["action"]) && ($_POST["action"] == "save") && $_SESSION["admin"])
{
	if ($_POST["mode"] == "edit")
	{	$league = new OFFL_League($_POST["league_id"]);	}
	else // add
	{	$league = new OFFL_League();	}

	$league->setLeagueName($_POST["league_name"]);
	$league->setLeagueAbbv($_POST["league_abbv"]);
	$league->setLeagueMotto($_POST["league_motto"]);
	$league->setCommishEmail($_POST["commish_email"]);

	if (isset($_POST["public"]) && ($_POST["public"] == "on"))
	{	$league->setPublic(1);	}
	else
	{	$league->setPublic(0);	}

	$league->save();
}
if (isset($_POST["action"]) && ($_POST["action"] == "archive") && $_SESSION["admin"])
{
	$PL = new OFFL_PastLeague();
	$PL->storeCurrentLeague($_POST["league_id"], $_POST["year"]);
}

switch ($_GET["mode"])
{
	case "admin":
		if (!$_SESSION["admin"])
		{
			require($DOC_ROOT . "/lib/footer.php");
			die();
		}
		// list leagues for edit, allow add option
?>
<table>
	<thead>
		<tr><th colspan="2">Edit Leagues</th></tr>
	</thead>
	<tfoot><tr><td colspan="2"></td></tr></tfoot>
	<tbody>
<?php
		$leagues = $myleague->getAllLeagues();
		foreach ($leagues as $league)
		{
			echo "		<tr><td>" . $league->getLeagueName() . "</td><td><a href=\"" . $WEB_ROOT . "/leagues.php?mode=edit&amp;league_id=" . $league->getLeagueID() . "\">[EDIT]</a></td></tr>\n";
		}
?>
		<tr><td>Add New League</td><td><a href="<?php echo $WEB_ROOT; ?>/leagues.php?mode=add">[ADD]</a></td></tr>
	</tbody>
</table>
<?php
		break;
	case "edit":
		if (!$_SESSION["admin"])
		{
			require($DOC_ROOT . "/lib/footer.php");
			die();
		}
		if(isset($_GET["league_id"]))
		{	$league = new OFFL_League($_GET["league_id"]);	}
		else
		{	$league = new OFFL_League($_SESSION["league_id"]);	}
?>
<div id="edit-league">
	<form method="post" action="<?php echo $WEB_ROOT; ?>/leagues.php">
		<input type="hidden" name="league_id" value="<?php echo $league->getLeagueID(); ?>" />
		<input type="hidden" name="mode" value="edit" />
		<input type="hidden" name="action" value="save" />
		<table>
			<thead><tr class="evenrow"><th colspan="2">Edit <?php echo $league->getLeagueName(); ?></th></tr></thead>
			<tfoot><tr><th colspan="2"></th></tr></tfoot>
			<tbody>
				<tr class="oddrow">
					<th>League Name</th>
					<td><input type="text" name="league_name" size="30" maxlength="80" value="<?php echo $league->getLeagueName() ?>" /></td>
				</tr>
				<tr class="evenrow">
					<th>League Abbreviation</th>
					<td><input type="text" name="league_abbv" size="30" maxlength="10" value="<?php echo $league->getLeagueAbbv() ?>" /></td>
				</tr>
				<tr class="oddrow">
					<th>League Motto</th>
					<td><input type="text" name="league_motto" size="30" maxlength="100" value="<?php echo $league->getLeagueMotto() ?>" /></td>
				</tr>
				<tr class="evenrow">
					<th>Commissioner Email</th>
					<td><input type="text" name="commish_email" size="30" maxlength="60" value="<?php echo $league->getCommishEmail() ?>" /></td>
				</tr>
				<tr class="oddrow">
					<th>Public</th>
					<td><input type="checkbox" name="public" <?php if ($league->getPublic()) { echo "checked "; } ?>/></td>
				</tr>
			</tbody>
		</table>
		<input type="submit" />
	</form>
	<form method="post" action="<?php echo $WEB_ROOT; ?>/leagues.php">
		<p>Use the below button to archive this league's division/team configuration.  This allows you to alter the league in future years while preserving the historical records.</p>
		<input type="hidden" name="league_id" value="<?php echo $league->getLeagueID(); ?>" />
		<input type="hidden" name="year" value="<?php echo getThisYear(); ?>" />
		<input type="hidden" name="mode" value="edit" />
		<input type="hidden" name="action" value="archive" />
		<input type="submit" value="Archive League" />
	</form>

</div>
<?php
		break;
	case "add":
		if (!$_SESSION["admin"])
		{
			require($DOC_ROOT . "/lib/footer.php");
			die();
		}
?>
<div id="add-league">
	<form method="post" action="<?php echo $WEB_ROOT; ?>/leagues.php">
		<input type="hidden" name="mode" value="add" />
		<input type="hidden" name="action" value="save" />
		<table>
			<thead><tr class="evenrow"><th colspan="2">Add League</th></tr></thead>
			<tfoot><tr><th colspan="2"></th></tr></tfoot>
			<tbody>
				<tr class="oddrow">
					<th>League Name</th>
					<td><input type="text" name="league_name" size="30" maxlength="80" /></td>
				</tr>
				<tr class="evenrow">
					<th>League Abbreviation</th>
					<td><input type="text" name="league_abbv" size="30" maxlength="10" /></td>
				</tr>
				<tr class="oddrow">
					<th>League Motto</th>
					<td><input type="text" name="league_motto" size="30" maxlength="100" /></td>
				</tr>
				<tr class="evenrow">
					<th>Commissioner Email</th>
					<td><input type="text" name="commish_email" size="30" maxlength="60" /></td>
				</tr>
				<tr class="oddrow">
					<th>Public</th>
					<td><input type="checkbox" name="public" checked /></td>
				</tr>
			</tbody>
		</table>
		<input type="submit" />
	</form>
</div>
<?php
		break;
	default:
		if (!isset($_GET["league_id"]))
		// overview
		{
			if (isset($myuser))
			{
				$myleague_ids = $myuser->getLeagueIDs();

				foreach ($myleague_ids as $league_id)
				{
					$league = new OFFL_League($league_id);
					echo "<a href=\"$WEB_ROOT/leagues.php?league_id=$league_id\">" . $league->getLeagueName() . "</a><br />\n";
				}
			}
			else
			{	$myleague_ids = array();	}
			echo "<div class=\"line\"></div>\n";
			$lg = new OFFL_League;
			$league_ids = array_diff($lg->getAllLeagues("ID"), $myleague_ids);
			foreach ($league_ids as $league_id)
			{
				$league = new OFFL_League($league_id);
				echo "<a href=\"$WEB_ROOT/leagues.php?league_id=$league_id\">" . $league->getLeagueName() . "</a><br />\n";
			}

		}
		else
		// league-specific info
		// I may break this up with a refresh to allow $_SESSION to update in header.  Maybe I could put this above header?  probably not....
		{
			$_SESSION["league_id"] = $_GET["league_id"];
			$league = new OFFL_League($_GET["league_id"]);
			echo "<h3>" . $league->getLeagueName() . "</h3>\n";
			unset($_SESSION["fflteam_id"]);

			$teams = $league->getAllFFLTeams();
			foreach ($teams as $team)
			{
				if ($team->getUserID() == $_SESSION["user_id"])
				{	$_SESSION["fflteam_id"] = $team->getFFLTeamID();	}
				echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $team->getFFLTeamID() . "\">" . $team->getFFLTeamFullName() . "</a><br />\n";
			}
		}
		break;
} // end switch

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