Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/header.php
<?php
/**
 * Page header for OFFL UI
 *
 * Includes all the major include files, save {@link offlconfig.php}
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

require_once($DOC_ROOT . "/lib/config.php");

// Enable sessions (yay)
session_start();
// IE and Safari fix
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
// IE and Safari fix
header("Cache-Control: post-check=0, pre-check=0", false);

$expireTime = 60*60*24*100; 			// 100 days
session_set_cookie_params($expireTime); // cookie will expire 100 days from current date

// load up fflteam and control classes for cookie check purposes
// fflteam pulls session info, control checks if cookie reg enabled (EVENTUALLY -- NOT WRITTEN YET)

require_once($DOC_ROOT . "/lib/classes/offl_control.php");
require_once($DOC_ROOT . "/lib/classes/offl_user.php");
require_once($DOC_ROOT . "/lib/classes/offl_league.php");
require_once($DOC_ROOT . "/lib/classes/offl_fflteam.php");

// put this above cookie check to avoid redefinition of objects
if (isset($_SESSION["user_id"]))
{
	if ($_SESSION["user_id"] > 0)
	{	$myuser = new OFFL_User($_SESSION["user_id"]);	}
}
else {	$_SESSION["user_id"] = NULL;	}

if (isset($_COOKIE[OFFL_COOKIE_NAME]))
{
	$x = new OFFL_User();
	$uid = $x->getUserIDByHash($_COOKIE[OFFL_COOKIE_NAME]);
	if ($uid !== FALSE)
	{
		$myuser = new OFFL_User($uid);
		$_SESSION["user_id"] = $uid;
		if ($myuser->getAdmin() == 1)
		{	$_SESSION["admin"] = TRUE;	}
	}
}
if (!isset($_SESSION["login_time"]))
{	$_SESSION["login_time"] = time();	}

// INITIALIZE MAIN STATUS VARIABLES
if (!isset($_SESSION["league_id"]) && isset($_GET["league_id"]))
{	$_SESSION["league_id"] = $_GET["league_id"];	}

if (isset($_SESSION["league_id"]))
{	$myleague = new OFFL_League($_SESSION["league_id"]);	}
else {	$_SESSION["league_id"] = NULL;	}
if (isset($_SESSION["fflteam_id"]))
{	$myteam = new OFFL_FFLTeam($_SESSION["fflteam_id"]);	}
else {	$_SESSION["fflteam_id"] = NULL;	}

// Variables that may not be set.
if (!isset($public))
{	$public = FALSE;	}
if (!isset($_SESSION["admin"]))
{	$_SESSION["admin"] = FALSE;	}
if (!isset($maintenance))
{	$maintenance = FALSE;	}
// MAY BE UNNECESSARY?
if (!isset($_GET["mode"]))
{  $_GET["mode"] = "display";	}

// prep for maintenance scripts
// This will probably need revision for league-specific stuff.  look at later
if ($maintenance)
{
	if (!isset($_SESSION["user_id"]))
	{
		$_SESSION["fflteamid"] = -1;
		$_SESSION["user_id"] = -1;
		$_SESSION["league_id"] = -1;
	}
}

if (isset($_GET["offset"]))
{
	$_SESSION["offset"] = $_GET["offset"] * 60; // session offset in seconds, negative of normal offset (e.g. EST is positive)
}
if (isset($_GET["osconfirm"]))
// allows for a default time zone w/o preventing actual TZ loading.
{
	$_SESSION["osconfirm"] = TRUE;
}

// Import functions 
require_once($DOC_ROOT . "/lib/functions.php");

// Import classes
require_once($DOC_ROOT . "/lib/classes/offl_auctionvalue.php");
require_once($DOC_ROOT . "/lib/classes/offl_control.php");
require_once($DOC_ROOT . "/lib/classes/offl_division.php");
require_once($DOC_ROOT . "/lib/classes/offl_draft.php");
require_once($DOC_ROOT . "/lib/classes/offl_draftpick.php");
require_once($DOC_ROOT . "/lib/classes/offl_fflteam.php");
require_once($DOC_ROOT . "/lib/classes/offl_game.php");
require_once($DOC_ROOT . "/lib/classes/offl_league.php");
require_once($DOC_ROOT . "/lib/classes/offl_lpl.php");
require_once($DOC_ROOT . "/lib/classes/offl_news.php");
require_once($DOC_ROOT . "/lib/classes/offl_nflgame.php");
require_once($DOC_ROOT . "/lib/classes/offl_nflteam.php");
require_once($DOC_ROOT . "/lib/classes/offl_pastleague.php");
require_once($DOC_ROOT . "/lib/classes/offl_pastroster.php");
require_once($DOC_ROOT . "/lib/classes/offl_player.php");
require_once($DOC_ROOT . "/lib/classes/offl_playerstat.php");
require_once($DOC_ROOT . "/lib/classes/offl_position.php");
require_once($DOC_ROOT . "/lib/classes/offl_rosterplayer.php");
require_once($DOC_ROOT . "/lib/classes/offl_trade.php");
require_once($DOC_ROOT . "/lib/classes/offl_tradeplayer.php");
require_once($DOC_ROOT . "/lib/classes/offl_tradeprotest.php");
require_once($DOC_ROOT . "/lib/classes/offl_transaction.php");
require_once($DOC_ROOT . "/lib/classes/offl_transactionitem.php");
require_once($DOC_ROOT . "/lib/classes/offl_user.php");
require_once($DOC_ROOT . "/lib/classes/offl_waiver.php");
require_once($DOC_ROOT . "/lib/classes/offl_waiverplayer.php");

// Instantiate Control object
$control = new OFFL_Control($_SESSION["league_id"]);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<?php
if(!$public)
{
	if(!isset($_SESSION["user_id"]))
	{
		echo "<meta http-equiv=\"refresh\" content=\"0; URL=$WEB_ROOT/?login=failed\" /><title></title></head><body></body></html>";
		// header("Location: $DOC_ROOT/");
		exit;
	}
}
?>
<title><?php echo isset($myleague) ? $myleague->getLeagueAbbv() : "OFFL"; ?> - <?php echo $pageTitle ?></title>

	<!-- compliance patch for microsoft browsers -->
	<!--[if lt IE 7]>
	<script src="<?php echo $WEB_ROOT; ?>/lib/js/ie7-core.js" type="text/javascript"></script>
	<script src="<?php echo $WEB_ROOT; ?>/lib/js/ie7-css2.js" type="text/javascript"></script>
	<script src="<?php echo $WEB_ROOT; ?>/lib/js/ie7-box-model.js" type="text/javascript"></script>
	<![endif]-->
<link rel="stylesheet" href="<?php echo $WEB_ROOT; ?>/lib/css/stylesheet.css" type="text/css" />
<?php

// Grab page-specific stylesheet
$script = basename($_SERVER["SCRIPT_NAME"], ".php");
if (file_exists($DOC_ROOT . "/lib/css/" . $script . ".css"))
{	echo "<link rel=\"stylesheet\" href=\"" . $WEB_ROOT . "/lib/css/$script.css\" type=\"text/css\" />\n";	}

echo "<script language=\"JavaScript\" src=\"" . $WEB_ROOT . "/lib/js/md5.js\"></script>\n";

// Adjust for DST+Timezone offset.  URL rewrite magic
if ( !isset($_SESSION["osconfirm"]) && !$maintenance ) {
echo "<script type=\"text/javascript\">\n";
?>
  function setLinks()
  {
    now = new Date();
    offset = now.getTimezoneOffset();

    for ( i = 0; i != document.links.length; i++ )
	{
      with ( document.links[i] )
	  {
        if ( href.indexOf('http://<?php echo $_SERVER["HTTP_HOST"]; ?>') == 0 )
		{
          if ( href.indexOf('?') == -1 )
		  {
            href += '?osconfirm=yes&amp;offset=' + offset;
          }
		  else
		  {
            href += '&amp;osconfirm=yes&amp;offset=' + offset;
          }
        }
      }
    }
  }

window.onLoad = setLinks();

// -->
<?php echo "</script>\n"; $_SESSION["offset"] = 300*60; /* set default to CDT / EST. */ } ?>

</head>
<body>
<h1 id="league-title"><?php echo isset($myleague) ? $myleague->getLeagueName() : "Online Fantasy Football League";  ?></h1>
<?php
if ((isset($_SESSION["user_id"])) && ($_SESSION["user_id"] != -1))
{
	if (isset($myuser))
	{
?>      <div class="small" style="position: relative; float: right; display: inline;">	<?php
		echo $myuser->getName(FALSE);
		if (isset($myteam))
		{
			// I NEED TO REVISE THIS FOR EDITING PURPOSES
			// (moving the edit link might be best)
			echo " - <a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $myteam->getFFLTeamID() . "\">" . $myteam->getFFLTeamFullName() . "</a> | <a class=\"header\" href=\"$WEB_ROOT/teams.php?mode=edit\">Edit Team Info</a>";
		}
		if (isset($myuser))
		{
			echo " | <a class=\"header\" href=\"$WEB_ROOT/users.php?mode=edit\">Edit User Info</a>";
		}
		echo "</div>\n";
	}
}
else
{ ?>
      <div class="small" style="position: relative; float: right; display: inline;">
        Browsing as Guest (<a href="<?php echo $WEB_ROOT; ?>/logout.php">Login</a>)
      </div>
<?php } 
// new menu starts here ?>
<div id="nav">
<?php if (isset($_SESSION["user_id"]))
{

	?>
	<ul class="level1">
<?php // links are league-specific (save maybe admin) except user controls like edit and league select
if (isset($myleague))
{ ?>
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/leagues.php">Leagues</a>
			<ul class="level2">
<?php
		$lg = new OFFL_League();
		$leagues = $lg->getAllLeagues();
		$otherLeagues = FALSE;
?>
<?php		foreach ($leagues as $lg)
			{
				if ($lg->inLeague($_SESSION["user_id"], "USER") || ($_SESSION["user_id"] == -1))
				{
					echo "					<li><a href=\"$WEB_ROOT/leagues.php?league_id=" . $lg->getLeagueID() . "\">" . $lg->getLeagueName() . "</a></li>\n";
				}
				else
				{	$otherLeagues = TRUE;	}
			}
			if ($otherLeagues)
			{
?>				<li class="submenu"><a href="javascript:void()" style="pointer:normal;">More</a>
					<ul class="level3">
<?php
				foreach ($leagues as $lg)
				{
					if (($_SESSION["user_id"] != -1) && !$lg->inLeague($_SESSION["user_id"], "USER"))
					{
						echo "						<li><a href=\"$WEB_ROOT/leagues.php?league_id=" . $lg->getLeagueID() . "\">" . $lg->getLeagueName() . "</a></li>\n";
					}
				}

?>
					</ul>
				</li>
<?php		}
?>
				
				<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/controls.php">Setup</a>
					<ul class="level3">
						<li><a href="<?php echo $WEB_ROOT; ?>/controls.php?view=config">League Config</a></li>
						<li><a href="<?php echo $WEB_ROOT; ?>/controls.php?view=scoring">Scoring</a></li>
					</ul>
				</li>
			</ul>
		</li>
		
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/news.php">News</a>
			<ul class="level2">
			<?php if (isset($_SESSION["user_id"]) && ($_SESSION["user_id"] >= 1)) {
?>				<li><a href="<?php echo $WEB_ROOT; ?>/news.php?mode=post">Post News</a></li>
			<?php } // end if ?>
			<?php // PHORUM LINK ADDED HERE ?>
				<li><a href="<?php echo $WEB_ROOT; ?>/forum/">Forum</a></li>
			</ul>
		</li>
<?php
/**
 * Only show the teams dropdown if league is set.
 *
 * Actually, this should probably move to the master menu.  Log in and then select
 * your current league.  I think I like that better.
 * 
 * I'll also need to decide where to put the list of user teams/leagues.
 * The user control panel might be a good place for a big listing.
 */
	$teams = $myleague->getAllFFLTeams();
	if (sizeof($teams))
	{
?>		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/teams.php">Teams</a>
<?php
		echo "			<ul class=\"level2\">\n";

		foreach ($teams as $team)
		{
			echo "				<li";
			if (isset($myteam) && ($team->getFFLTeamID() == $myteam->getFFLTeamID()))
				echo " class=\"active\"";
			echo "><a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $team->getFFLTeamID() . "\">" . $team->getFFLTeamCity() . " " . $team->getFFLTeamName() . "</a></li>\n";
		}

		echo "			</ul>\n";
	}
	else
	{	echo "		<li><a href=\"$WEB_ROOT/teams.php\">Teams</a>";	}
?></li>
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/rosters.php<?php if (!isset($myteam)) echo "?view=allteams"; ?>">Rosters</a>
			<ul class="level2">
<?php if (isset($myteam))
	echo "				<li><a href=\"$WEB_ROOT/rosters.php\">My Team</a></li>\n"; ?>
				<li><a href="<?php echo $WEB_ROOT; ?>/rosters.php?view=allteams">League Breakdown</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/transactions.php">Transaction Report</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/trades.php">Trades</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/waivers.php">Waivers</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/players.php">Free Agents</a></li>
<?php
if ($control->getValue("CONFIG_USE_DRAFT") == "Yes")
{
?>
<li><a href="<?php echo $WEB_ROOT; ?>/drafts.php">Draft</a></li>
<?php
}

if ($control->getValue("CONFIG_USE_AUCTION") == "Yes")
{
?>
<li><a href="<?php echo $WEB_ROOT; ?>/auction.php">Auction</a></li>
<?php
}
?>
			</ul>
		</li>
<?php
		$game = new OFFL_Game();
		$game->setLeagueID($myleague->getLeagueID());
		$year = getThisYear();
		if (in_array($year, $game->getGameYears()))
		{
?>
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/games.php">Schedule</a>
<?php	
			$game->setYear($year);
			$curr_week = getCurrentWeek($year);
			$weeks = $game->getGameWeeks();
			echo "			<ul class=\"level2\">\n";
			foreach ($weeks as $week)
			{
				echo "				<li><a href=\"$WEB_ROOT/games.php?year=$year&amp;week=$week\"";
				if ($week == $curr_week)
					echo " class=\"active\"";
				echo ">Week $week</a></li>\n";
			}
			echo "			</ul>\n";
		}
		else
			echo "		<li><a href=\"$WEB_ROOT/games.php\">Schedule</a>";
?></li>
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/standings.php">Standings</a>
			<ul class="level2">
				<li><a href="<?php echo $WEB_ROOT; ?>/standings.php?view=standard">Standard</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/standings.php?view=breakdown">Breakdown</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/standings.php?view=power">Power Rankings</a></li>
			</ul>
		</li>
<?php if ($_SESSION["admin"] == 1)
	{
?>
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/admin.php">Admin</a>
			<ul class="level2">
				<li><a href="<?php echo $WEB_ROOT; ?>/users.php?mode=admin">Users</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/leagues.php?mode=admin">Leagues</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/news.php?mode=admin">News</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/trades.php?mode=admin">Trades</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/rosters.php?mode=admin">Rosters</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/players.php?mode=admin">Players</a></li>
				<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/controls.php?mode=admin">Setup</a>
					<ul class="level3">
						<li><a href="<?php echo $WEB_ROOT; ?>/controls.php?mode=admin&amp;view=config">League Config</a></li>
						<li><a href="<?php echo $WEB_ROOT; ?>/controls.php?mode=admin&amp;view=scoring">Scoring</a></li>
						<li><a href="<?php echo $WEB_ROOT; ?>/controls.php?mode=admin&amp;view=style">Site Style</a></li>
						<li><a href="<?php echo $WEB_ROOT; ?>/controls.php?mode=admin&amp;view=misc">Misc</a></li>
					</ul>
				</li>
				<li><a href="<?php echo $WEB_ROOT; ?>/teams.php?mode=admin">Teams</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/divisions.php?mode=admin">Divisions</a></li>
				<li><a href="<?php echo $WEB_ROOT; ?>/games.php?mode=admin">Schedules</a></li>

<?php
if ($control->getValue("CONFIG_USE_DRAFT") == "Yes")
{
?>
<li><a href="<?php echo $WEB_ROOT; ?>/drafts.php?mode=admin">Drafts</a></li>
<?php
}

if ($control->getValue("CONFIG_USE_AUCTION") == "Yes")
{
?>
<li><a href="<?php echo $WEB_ROOT; ?>/auction.php?mode=admin">Auction</a></li>
<?php
}

?>

			</ul>
		</li>
<?php } ?>

<?php } /* end if isset($myleague) */ 
else {
		$lg = new OFFL_League();
		$leagues = $lg->getAllLeagues();
		$otherLeagues = FALSE;
		if (sizeof($leagues))
		{
?>
		<li class="submenu"><a href="<?php echo $WEB_ROOT; ?>/leagues.php">Leagues</a>
			<ul class="level2">
<?php		foreach ($leagues as $lg)
			{
				if ($lg->inLeague($_SESSION["user_id"], "USER") || ($_SESSION["user_id"] == -1))
				{
					echo "					<li><a href=\"$WEB_ROOT/leagues.php?league_id=" . $lg->getLeagueID() . "\">" . $lg->getLeagueName() . "</a></li>\n";
				}
				else
				{	$otherLeagues = TRUE;	}
			}
			if ($otherLeagues)
			{
?>				<li class="submenu"><a href="javascript:void()" style="pointer:normal;">More</a>
					<ul class="level3">
<?php
				foreach ($leagues as $lg)
				{
					if (($_SESSION["user_id"] != -1) && !$lg->inLeague($_SESSION["user_id"], "USER"))
					{
						echo "						<li><a href=\"$WEB_ROOT/leagues.php?league_id=" . $lg->getLeagueID() . "\">" . $lg->getLeagueName() . "</a></li>\n";
					}
				}

?>
					</ul>
				</li>
<?php		}
?>
			</ul>
		</li>

<?php	}
		else
		{
?>
		<li><a href="<?php echo $WEB_ROOT; ?>/leagues.php">Leagues</a></li>
<?php	} /* end else sizeof($leagues) */ 
	} /* end else !isset($myleague) */ ?>
	<li><a href="<?php echo $WEB_ROOT; ?>/logout.php">Logout</a></li>

	</ul>
<?php } /* end if logged in */ else { echo "<ul class=\"level1\"><li style=\"z-index: -1;\"><a style=\"cursor:default;\" href=\"javascript:void()\">&nbsp;</a></li></ul>"; }// end if isset login ?>
</div><div style="clear:both;"></div>
<?php // main page body begins here.  Prepare to clean up this layout. ?>
	<h2 id="page-title"><?php echo $pageTitle ?></h2>
Return current item: Online Fantasy Football League