<?php
/**
* Games interface
*
* @author Stephen Rochelle <hide@address.com>
* @version OFFL v0.2
* @copyright Copyright (c) 2004 Stephen Rochelle. Some rights reserved.
* @package offl-ui
*/
if(empty($_POST["action"]))
$_POST["action"] = NULL;
if(empty($_GET["mode"]))
$_GET["mode"] = NULL;
if(empty($_GET["action"]))
$_GET["action"] = NULL;
require_once("offlconfig.php");
if(empty($_GET["year"]))
{
$_GET["year"] = getThisYear();
}
$pageTitle = $_GET["year"] . " Schedule";
if(!empty($_GET["week"]))
{$pageTitle .= " - Week " . $_GET["week"]; }
$adminEditOnly = 1 ;
require_once($DOC_ROOT . "/lib/header.php");
$thisGame = new OFFL_Game();
$thisGame->setYear($_GET["year"]);
$thisGame->setLeagueID($_SESSION["league_id"]);
// user is saving info (edit or add)
if($_GET["mode"] == "loadnflschedule")
{
if ($_GET["step"] == "1")
{
?>
<h2>Import current NFL schedule?</h2>
<table><tr><td>
<form name="addnflgame" action="<?php echo $WEB_ROOT; ?>/games.php">
<input type="hidden" name="mode" value="loadnflschedule">
<input type="hidden" name="step" value="2">
<input type="submit" value="Yes">
</form>
</td><td>
<form name="abort" action="<?php echo $WEB_ROOT; ?>/games.php">
<input type="submit" value="No">
</form>
</td></tr></table>
<?php }
else
{
$schedulearray = file("http://www.nfl.com/schedules");
$schedule = "";
$x = new OFFL_NFLTeam();
$nfl_teams = $x->getAllNFLTeams();
$dbconn = $x->getConn();
$sql = "DELETE FROM nflgames WHERE year=" . $_GET["year"];
$result = mysql_query($sql,$dbconn) or die (mysql_error() . ": $sql");
include ("./lib/inc/htmlparser.inc");
// require_once("offlconfig.php");
// require_once($DOC_ROOT . "/lib/header.php");
//this retrieves the game page
$filename = "http://www.sportsline.com/nfl/schedules/regular";
$sched = file($filename);
$schedstring = "";
//appends
foreach ($sched as $schedline) {
$schedstring .= $schedline . "\n\n";
}
list($junk, $schedstring) = explode("<font class=\"lead\"><b>All times are US/Eastern</b></font><p>", $schedstring, 2);
list($schedstring, $junk) = explode("<div class=\"spacer10\"> </div>", $schedstring, 2);
//echo $schedstring;
$parser = new HtmlParser ($schedstring);
while ($parser->parse()) {
//echo "iNodeName: " . $parser->iNodeName . ", iNodeValue: " . $parser->iNodeValue . ", iNodeType: " . $parser->iNodeType . "<br/>";
$attrValues = $parser->iNodeAttributes;
if (strpos(trim($parser->iNodeValue), "WEEK") !== false) {
list($junk, $gameweek) = explode("WEEK ", $parser->iNodeValue, 2);
echo "Week Nbr: " . $gameweek . "<br/>";
}
if (strpos(trim($parser->iNodeValue), "y,") !== false) {
echo "<br/>--" . $parser->iNodeValue;
}
if (strpos(trim($parser->iNodeValue), " at ") !== false) {
list($vteam, $hteam) = explode(" at ", $parser->iNodeValue, 2);
echo "<br/>----" . $parser->iNodeValue;
$x = new OFFL_NFLTeam();
$vabbv = $x->getNFLTeamBySchedName($vteam);
$habbv = $x->getNFLTeamBySchedName($hteam);
}
if (strpos(trim($parser->iNodeValue), "document.write(formatTime") !== false) {
list($junk, $gametime) = explode("document.write(formatTime('%I:%M %p', ", $parser->iNodeValue, 2);
list($gametime, $junk) = explode("))", $gametime, 2);
echo " -- " . date("g:i A, D M j, Y", $gametime);
$gamedate = date('Ymd', $gametime);
//http://www.sportsline.com/nfl/gamecenter/live//hide@address.com
echo " -- " . "http://www.sportsline.com/nfl/gamecenter/live/NFL_" . $gamedate . "_" . $vabbv->getNFLTeamAbbv() . "@" . $habbv->getNFLTeamAbbv();
$thisGame = new OFFL_NFLGame();
$thisGame->setYear($_GET["year"]);
$thisGame->setWeek($gameweek);
$thisGame->setGametime($gametime);
$thisGame->setHNFLTeamID($habbv->getNFLTeamID());
$thisGame->setVNFLTeamID($vabbv->getNFLTeamID());
//echo "Save game: " . $thisGame->getYear() . ", " . $thisGame->getWeek() . ", " . $thisGame->getGametime() . ", " . $thisGame->getHNFLTeamID() . ", " . $thisGame->getVNFLTeamID() . "<br/>";
$thisGame->save();
}
}
} // end step 2
}
else {
if($_GET["action"] == "save")
{
$thisGame = new OFFL_Game();
// If edit, get the existing record
if($_GET["mode"] == "edit")
{ $thisGame = new OFFL_Game($_GET["game_id"]); }
// Populate fields with form data
$thisGame->setYear($_GET["year"]);
$thisGame->setWeek($_GET["week"]);
$thisGame->setHFFLTeamID($_GET["h_fflteam_id"]);
$thisGame->setVFFLTeamID($_GET["v_fflteam_id"]);
if (is_numeric($_GET["h_fflteam_score"]))
{ $thisGame->setHFFLTeamScore($_GET["h_fflteam_score"]); }
if (is_numeric($_GET["v_fflteam_score"]))
{ $thisGame->setVFFLTeamScore($_GET["v_fflteam_score"]); }
if (is_numeric($_GET["h_fflteam_score"]) && is_numeric($_GET["v_fflteam_score"])) // if a score has been posted
{ $thisGame->setFinal(TRUE); } // assume any score edit is a final score for now.
else
{ $thisGame->setFinal(FALSE); }
$thisGame->save();
?><div class="success">Game <?php echo $thisGame->getGameID(); ?> successfully saved.</div><p>
<a href="<?php echo $WEB_ROOT; ?>/games.php?mode=<?php echo $_GET["mode"] ?>&year=<?php echo $_GET["year"] ?>&week=<?php echo $_GET["week"] ?>">Back to <?php echo $year ?> Schedule Administration</a>
<META http-equiv="refresh" content="1; URL=<?php echo $WEB_ROOT; ?>/games.php?mode=<?php echo $_GET["mode"] ?>&year=<?php echo $_GET["year"] ?>&week=<?php echo $_GET["week"] ?>">
<?php
}
else
{
if(($_GET["mode"] == "display") || (!isset($_GET["mode"])))
{
// Present display (read-only) information
$thisGame->setYear($_GET["year"]);
$thisGame->setLeagueID($_SESSION["league_id"]);
// $thisGame = new Game($year,$week);
if(empty($_GET["week"]))
$_GET["week"] = getCurrentWeek($_GET["year"]);
$years = $thisGame->getGameYears();
$weeks = $thisGame->getGameWeeks($_GET["year"]);
$games = $thisGame->getGames($_SESSION["league_id"], $_GET["year"],$_GET["week"]);
?>
View Schedule Season: <?php
// for($i=0; $i<sizeof($years); $i++)
foreach ($years as $i=>$year)
{
if($i>0)
echo " | ";
?><a href="<?php echo $WEB_ROOT; ?>/games.php?year=<?php echo $year ?>"><?php echo $year ?></a><?php
}
?><br>
View Week: <?php
// for($i=0; $i<sizeof($weeks); $i++)
foreach($weeks as $i=>$week)
{
if($i>0)
echo " | ";
if($week == $_GET["week"])
{
echo "<b>$week</b>";
} else {
?><a href="<?php echo $WEB_ROOT; ?>/games.php?year=<?php echo $_GET["year"] ?>&week=<?php echo $week ?>"><?php echo $week . "</a>\n";
}
}
?>
<table id="gametable" width="80%">
<tr><td width="50%" valign="top">
<table id="ffl-games">
<tr bgcolor="#cccccc">
<th>Team</th>
<th width="10">Score</th>
<th></th>
</tr>
<?php
// for($i=0; $i<sizeof($games); $i++)
foreach($games as $game)
{
$hTeam = new OFFL_FFLTeam($game->getHFFLTeamID());
$vTeam = new OFFL_FFLTeam($game->getVFFLTeamID());
?>
<tr valign="top" class="oddrow">
<td><?php
echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $game->getVFFLTeamID();
if (isset($_GET["year"]))
{
echo "&year=$_GET[year]";
}
echo "\">" . $vTeam->getFFLTeamFullName() . "</a>"; ?> at
</td>
<td style="text-align:right; padding-right: 5px;">
<?php echo $game->getVFFLTeamScore(); ?>
</td>
<td rowspan="2" style="text-align:center; vertical-align:middle">
<?php
if (!is_null($vTeam->getFFLTeamID()) && !is_null($hTeam->getFFLTeamID()))
{
?><span style="font-size:smaller; text-transform:uppercase; font-weight:bold;"><a href="<?php echo $WEB_ROOT; ?>/matchups.php?game_id=<?php echo $game->getGameID(); ?>" title="Compare the Starting Rosters">[Matchup]</a></span>
<?php } ?>
</td>
</tr>
<tr valign="top" class="evenrow">
<td><?php
echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $game->getHFFLTeamID();
if (isset($_GET["year"]))
{
echo "&year=$_GET[year]";
}
echo "\">" . $hTeam->getFFLTeamFullName() . "</a>"; ?>
</td>
<td style="text-align:right; padding-right: 5px;">
<?php echo $game->getHFFLTeamScore(); ?>
</td>
</tr>
<?php
}
?>
</table>
</td><td valign="top" >
<table id="nfl-games">
<tr>
<th>NFL Game</th>
<th>Game Time</th>
</tr>
<?php
// NFL Schedule for the week goes here
$x = new OFFL_NFLGame();
$NFLGames = $x->getNFLGames($_GET["year"], $_GET["week"]);
foreach ($NFLGames as $i=>$game)
{
$url = NULL;
$timeDiff = time() - $game->getGametime();
if ($timeDiff > 0)
{ $url="http://www.nfl.com/gamecenter/live/NFL_" . date("Ymd", $game->getGametime()) . "_" . $game->getVNFLTeamAbbv() . "@" . $game->getHNFLTeamAbbv(); }
echo "<tr class=\"";
if ($i % 2)
echo "evenrow";
else
echo "oddrow";
echo "\"><td>";
if (isset($url))
{ echo "<a href=\"" . $url . "\" title=\"Game Stats\">"; }
echo "<span style=\"text-transform:none;\"><abbr title=\"" . $game->getVNFLTeamCity() . " " . $game->getVNFLTeamName() . "\">" . strtolower($game->getVNFLTeamAbbv()) . "</abbr></span> @ <abbr title=\"" . $game->getHNFLTeamCity() . " " . $game->getHNFLTeamName() . "\">" . $game->getHNFLTeamAbbv();
$time = $game->getGametime();
$time_str = gmdate("g:i A, D M j", GMTOffsetTime($time));
// $time_str = date("g:i A, j M, Y", $time);
echo "</abbr>";
if (isset($url))
{ echo "</a>"; }
echo "</td><td>$time_str</td></tr>\n";
}
$byeTeams = $x->getByeTeams($_GET["year"], $_GET["week"]);
if (sizeof ($byeTeams))
{
echo "<tr><th colspan=\"2\">Bye Teams</th></tr>\n<tr><td style=\"text-align:center;\" colspan=\"2\">";
foreach($byeTeams as $i=>$team)
{
if ($i)
echo " | ";
echo "<abbr title=\"" . $team->getNFLTeamCity() . " " . $team->getNFLTeamName() . "\">" . $team->getNFLTeamAbbv() . "</abbr>";
}
echo "</td></tr>\n";
}
?>
</table></td></tr></table>
<?php
}
elseif($_GET["mode"] == "admin")
{
// Present page of add/edit option
// Edit has drop-down of options
$years = $thisGame->getGameYears();
?>
<table border="0" cellpadding="3" cellspacing="0" width="50%">
<tr valign="top">
<td>
<form name="addgame" action="<?php echo $WEB_ROOT; ?>/games.php">
<input type="hidden" name="mode" value="add">
<input type="hidden" name="step" value="1">
<input type="submit" value="Create Schedule">
</form>
</td>
<td>
<form name="addnflgame" action="<?php echo $WEB_ROOT; ?>/games.php">
<input type="hidden" name="mode" value="loadnflschedule">
<input type="hidden" name="step" value="1">
<input type="submit" value="Download NFL schedule">
</form>
</td>
</tr>
<tr valign="top">
<td> </td>
</tr>
<tr valign="top">
<form name="editgame" action="<?php echo $WEB_ROOT; ?>/games.php">
<td align="right">
<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++)
foreach ($years as $year)
{
?>
<option value="<?php echo $year; ?>"><?php echo $year; ?></option>
<?php
}
?>
</select>
</td><td>
<input type="submit" value="Edit Schedule">
</td>
</form>
</tr>
</table>
<?php
}
elseif($_GET["mode"] == "edit")
{
$teams = $myleague->getAllFFLTeams();
usort($teams, "fflteam_name_rank");
if(!empty($_GET["year"]))
{
if(empty($_GET["week"]))
{ $_GET["week"]=0; }
// $thisGame = new Game($year,$week);
if(isset($_GET["game_id"]))
{
$thisGame= new OFFL_Game($_GET["game_id"]);
if(!empty($thisGame->_emsg))
{
?><div class="alert"><?php echo $thisGame->_emsg; ?></div><?php
}
// Here we want to edit an individual pick
// $thisGame variable contains what we need
?>
<form name="game" action="<?php echo $WEB_ROOT; ?>/games.php">
<input type="hidden" name="mode" value="<?php echo $_GET["mode"] ?>">
<input type="hidden" name="game_id" value="<?php echo $thisGame->getGameID(); ?>">
<input type="hidden" name="year" value="<?php echo $thisGame->getYear() ?>">
<input type="hidden" name="week" value="<?php echo $thisGame->getWeek() ?>">
<input type="hidden" name="action" value="save">
<table border="0">
<tr valign="top">
<td align="right">Year:</td>
<td align="left"><?php echo $thisGame->getYear() ?></td>
</tr>
<tr valign="top">
<td align="right">Week:</td>
<td align="left"><?php echo $thisGame->getWeek() ?></td>
</tr>
<tr valign="top" class="altline">
<th align="left" colspan="2">Team</th>
<th align="left">Score</th>
</tr>
<tr valign="top">
<td align="right">Visiting Team:</td>
<td align="left">
<select name="v_fflteam_id" size="1">
<option value="0"> -- Select One -- </option>
<?php
// for($i=0; $i<sizeof($teams); $i++)
foreach ($teams as $team)
{
?>
<option value="<?php echo $team->getFFLTeamID(); ?>"<?php if($team->getFFLTeamID() == $thisGame->getVFFLTeamID()) { ?> selected<?php } ?>><?php echo $team->getFFLTeamCity() . " " . $team->getFFLTeamName(); ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="text" name="v_fflteam_score" value="<?php echo $thisGame->getVFFLTeamScore(); ?>" size="5">
</td>
</tr>
<tr valign="top">
<td align="right">Home Team:</td>
<td align="left">
<select name="h_fflteam_id" size="1">
<option value="0"> -- Select One -- </option>
<?php
// for($i=0; $i<sizeof($teams); $i++)
foreach ($teams as $team)
{
?>
<option value="<?php echo $team->getFFLTeamID(); ?>"<?php if($team->getFFLTeamID() == $thisGame->getHFFLTeamID()) { ?> selected<?php } ?>><?php echo $team->getFFLTeamCity() . " " . $team->getFFLTeamName(); ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="text" name="h_fflteam_score" value="<?php echo $thisGame->getHFFLTeamScore(); ?>" size="5">
</td>
</tr>
<tr valign="top">
<td colspan="2"><input type="submit" value="Save Pick"></td>
</tr>
</table>
</form>
<?php
}
else
{
// Here we present a table similar to the display table
// $thisGame = new Game($year,$week);
if(empty($_GET["week"]))
{
if (isset($_GET["year"]))
{ $_GET["week"] = getCurrentWeek($_GET["year"]); }
else
{ $_GET["week"] = getCurrentWeek(getThisYear()); }
}
$years = $thisGame->getGameYears();
$weeks = $thisGame->getGameWeeks($_GET["year"]);
$games = $thisGame->getGames($_SESSION["league_id"], $_GET["year"],$_GET["week"]);
?>
Edit Schedule Season: <?php
foreach ($years as $i=>$year)
{
if($i>0)
echo " | ";
?><a href="<?php echo $WEB_ROOT; ?>/games.php?mode=edit&year=<?php echo $year ?>"><?php echo $year ?></a><?php
}
?><br>
Edit Week: <?php
foreach ($weeks as $i=>$week)
{
if($i>0)
echo " | ";
if($week == $_GET["week"])
{
echo "<b>$week</b>";
} else {
?><a href="<?php echo $WEB_ROOT; ?>/games.php?mode=edit&year=<?php echo $_GET["year"] ?>&week=<?php echo $week ?>"><?php echo $week ?></a><?php
}
}
?>
<table border="0" cellpadding="3" cellspacing="3" width="25%">
<tr bgcolor="#cccccc">
<th></th>
<th>Team</th>
<th width="10">Score</th>
</tr>
<?php
// for($i=0; $i<sizeof($games); $i++)
foreach ($games as $i=>$game)
{
$vTeam = new OFFL_FFLTeam($game->getVFFLTeamID());
$hTeam = new OFFL_FFLTeam($game->getHFFLTeamID());
if($i>0)
{
?><tr bgcolor="#cccccc"><td colspan="3"></td></tr><?php
}
?>
<tr valign="top" bgcolor="#eeeeee">
<td rowspan="2" valign="middle">
<a href="<?php echo $WEB_ROOT; ?>/games.php?mode=edit&game_id=<?php echo $game->getGameID(); ?>" class="red"><strong>[EDIT]</strong></a>
</td>
<td><?php
echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $game->getVFFLTeamID();
if (isset($_GET["year"]))
{
echo "&year=$_GET[year]";
}
echo "\">" . $vTeam->getFFLTeamFullName() . "</a>"; ?> at
</td>
<td>
<?php echo $game->getVFFLTeamScore(); ?>
</td>
</tr>
<tr valign="top" bgcolor="#eeeeee">
<td><?php
echo "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $game->getHFFLTeamID();
if (isset($_GET["year"]))
{
echo "&year=$_GET[year]";
}
echo "\">" . $hTeam->getFFLTeamFullName() . "</a>"; ?>
</td>
<td>
<?php echo $game->getHFFLTeamScore(); ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
}
else
{
// Print error
?><div class="alert">No year specified.</div><?php
}
}
elseif($_GET["mode"] == "add")
{
if($_GET["step"] == "1")
{
// Get number of teams from teams table
$numteams = $myleague->getNumberOfFFLTeams();
$numgames = floor($numteams / 2);
?><h3>Step 1: Game Format</h3>
There are <?php echo $numteams; ?> teams in this league. Therefore, we will create a schedule with <?php echo $numgames; ?> games per week.
<p>
Please fill out the form for the remaining needed information.
<form name="addgame" action="<?php echo $WEB_ROOT; ?>/games.php">
<input type="hidden" name="mode" value="add">
<input type="hidden" name="step" value="2">
<input type="hidden" name="numgames" value="<?php echo $numgames; ?>">
<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 $thisGame->getMaxGameYear($_SESSION["league_id"])+1; ?>"></td>
</tr>
<tr valign="top">
<th align="right">No. of Weeks:</th>
<td align="left"><input type="text" name="numweeks" size="4" maxlength="4"></td>
</tr>
<tr valign="top">
<th align="right">No. of Playoff Rounds:</th>
<td align="left"><input type="text" name="numrounds" size="4" maxlength="4"></td>
</tr>
<!--
<tr valign="top">
<th align="right">Schedule Type:</th>
<td align="left">
<input type="radio" name="type" value="straight" checked>Straight
</td>
</tr>
-->
<tr valign="top">
<td colspan="2">
<input type="submit" value="Proceed to Step 2">
</td>
</tr>
</table>
</form>
<?php
}
elseif($_GET["step"] == "2")
{
?><h3>Step 2: Creating Schedule</h3><?php
$thisGame->createSchedule($_SESSION["league_id"], $_GET["year"], $_GET["numgames"], $_GET["numweeks"], $_GET["numrounds"]);
?><div class="success"><?php echo $thisGame->getYear(); ?> Game successfully created and saved.</div><p>
<a href="<?php echo $WEB_ROOT; ?>/games.php?mode=edit&year=<?php echo $_GET["year"] ?>">Back to <?php echo $_GET["year"] ?> Game Administration</a><?php
}
}
}
}
require($DOC_ROOT . "/lib/footer.php"); ?>