Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/players.php
<?php
/**
 * Player viewing interface
 *
 * Displays {@link OFFL_Players players} and related interfaces such as stats.
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

$pageTitle = "Player Info";
$adminEditOnly = TRUE;
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php"); 

if(empty($_REQUEST["year"]))
{	$_REQUEST["year"] = getThisYear();	}
if(empty($_REQUEST["action"]))
{	$_REQUEST["action"] = NULL;	}
if(empty($_REQUEST["mode"]))
{	$_REQUEST["mode"] = NULL;	}

// Stub team object
$thisPlayer = new OFFL_Player();

// user is saving info (edit or add)
if($_REQUEST["action"] == "save")
{
	// If edit, get the existing record
	if($_REQUEST["mode"] == "edit")
	{	$thisPlayer = new OFFL_Player($_REQUEST["player_id"], $_SESSION["league_id"]);	}	

	// Populate fields with form data
	$thisPlayer->setLastName($_REQUEST["lname"]);
	$thisPlayer->setFirstName($_REQUEST["fname"]);
	$thisPlayer->setPictureLoc($_REQUEST["picture_loc"]);
	$thisPlayer->setNFLTeamID($_REQUEST["nflteam_id"]);
	$thisPlayer->setPositionID($_REQUEST["position_id"]);
	$thisPlayer->setActive($_REQUEST["active"]);
	$thisPlayer->setNFLProfile($_REQUEST["nfl_profile"]);

	$thisPlayer->save();
?><div class="success">Player <?php echo $thisPlayer->getName(); ?> successfully saved.</div><p>
<META http-equiv="refresh" content="1; URL=<?php echo "$WEB_ROOT/players.php?mode=admin" ?>"><?php
}
else
{

	if(($_REQUEST["mode"] == "display") || (!isset($_REQUEST["mode"])))
	{
		// Present display (read-only) information
		if(empty($_REQUEST["player_id"]))
		{
			// No player_id is selected, show list of active free-agent players
			// Note: Only showing active players for public view
			//			 Admin will get list of ALL players for editing
			$myPosition = new OFFL_Position;
			if(empty($_REQUEST["position_id"]))
			{	$_REQUEST["position_id"] = 0;	}
			else
			{	$myPosition = new OFFL_Position($_REQUEST["position_id"]);	}
			if(!isset($_REQUEST["fa"]))
			{	$_REQUEST["fa"] = 2;	}
			$waivers = 0;
			// NEW VALUES: 0 FOR ALL 1 FOR ROSTERS 2 FOR FAS + WAIVERS

			// NOTE: MUST REVAMP FA PARAMETERS
//			$players = $myleague->getAllActivePlayers($_REQUEST["position_id"], $_REQUEST["fa"]);
			if (!isset($_REQUEST["orderby"]))
			{	$_REQUEST["orderby"] = NULL;	}
			$players = $myleague->getPlayers($_REQUEST["fa"], $waivers, $_REQUEST["position_id"], FALSE, $_REQUEST["orderby"]);
			?>
			<table width="50%">
				<tr valign="bottom">
					<td class="bigger" rowspan="2"><?php if(!empty($_REQUEST["position_id"])) { echo $myPosition->getPositionName(); } 
					switch ($_REQUEST["fa"])
					{
						case "2":
							echo " Free Agents";
							break;
						case "0":
							if (!empty($_REQUEST["position_id"]))
								echo "s";
							else
								echo "All Players";
							break;
						case "1":
								echo " Roster Players";
							break;
					}
					?></td>
					<td class="small" style="text-align:right;"><a href="players.php?mode=display&position_id=<?php echo $_REQUEST["position_id"]; ?>&fa=2">Free Agents</a>
					| <a href="players.php?mode=display&position_id=<?php echo $_REQUEST["position_id"]; ?>&fa=0">All</a>
					| <a href="players.php?mode=display&position_id=<?php echo $_REQUEST["position_id"]; ?>&fa=1">On Rosters</a>
					</td>
				</tr>
				<tr>
					<td class="small" style="text-align:right;"><a href="players.php?mode=display&position_id=&fa=<?php echo $_REQUEST["fa"]; ?>">All</a> |
				<?php
					$first = 0;
					$positions = $myPosition->getAllPositions();
					for($i=0; $i<sizeof($positions); $i++)
					{
			if (!strstr($positions[$i]->getPositionAbbv(), "FLEX"))
					{
				if(!empty($first))
					echo " | ";
				?><a href="players.php?mode=display&position_id=<?php echo $positions[$i]->getPositionID(); ?>&fa=<?php echo $_REQUEST["fa"]; ?>"><?php echo $positions[$i]->getPositionAbbv(); ?></a><?php
				$first++;
			}
					}
				?>
				</td>
				</tr>
			</table>
			<table border="0" cellpadding="3" cellspacing="0" width="50%">
				<tr bgcolor="#cccccc">
					<th style="text-align:left; vertical-align:middle;"><a href="players.php?mode=display&position_id=<?php echo $_REQUEST["position_id"]; ?>&fa=<?php echo $_REQUEST["fa"]; ?>&orderby=name">Name</a></th>
					<th style="text-align:left; vertical-align:middle;"><a href="players.php?mode=display&position_id=<?php echo $_REQUEST["position_id"]; ?>&fa=<?php echo $_REQUEST["fa"]; ?>&orderby=position">Position</a></th>
					<th style="text-align:left; vertical-align:middle;"><a href="players.php?mode=display&position_id=<?php echo $_REQUEST["position_id"]; ?>&fa=<?php echo $_REQUEST["fa"]; ?>&orderby=team">NFL Team</a></th>
				</tr>
				<?php
				foreach($players as $i=>$player)
				{
					?>
					<tr<?php if($i%2){ ?> class="altline"<?php } ?>>
						<td><a href="players.php?player_id=<?php echo $player->getPlayerID(); ?>"><?php echo $player->getName(); ?></a></td>
						<td><?php echo $player->getPositionAbbv(); ?></td>
						<td><?php echo $player->getNFLTeamAbbv(); ?></td>
					</tr>
					<?php
				}
				?>
			</table>
			<?php
		}
		else // playerid is not empty
		{
			// Show information of given player
			$thisPlayer = new OFFL_Player($_REQUEST["player_id"], $_SESSION["league_id"]);
			?>
			<table border="0" width="75%">
				<tr>
					<td>
						<?php $pic = "http://images.nfl.com/images/players/60x80/" . $thisPlayer->getPictureLoc() . ".jpg";
						//if (is_file("$pic")) { ?>
						<img src="<?php echo $pic; ?>" alt="<?php echo $thisPlayer->getName("FL");; ?>" align="left">
						<?php //} ?>

						<div class="bigger"><?php echo $thisPlayer->getName("FL"); ?></div>

						<?php echo $thisPlayer->getPositionName() . ", " . $thisPlayer->getNFLTeamCity() . " " . $thisPlayer->getNFLTeamName(); ?><br>
<?php
	/* ******************* *\
		stats here
		list years
		w/in year, list weeks + all
		later, make sortable.
	\* ******************* */

if(empty($_REQUEST["week"]))
	$_REQUEST["week"] = "season";


$stat_lookup = new OFFL_PlayerStat();
$statYears = $stat_lookup->getStatYears($thisPlayer->getPlayerID());
if ($_REQUEST["year"] != "career")
	$statWeeks = $stat_lookup->getStatWeeks($_REQUEST["year"], $thisPlayer->getPlayerID());

foreach ($statYears as $i=>$year)
{
	if ($i)
		echo " | ";
	echo "<a ";
	if ($year == $_REQUEST["year"])
		echo "class=\"current\" ";
	echo "href=\"$WEB_ROOT/players.php?player_id=" . $thisPlayer->getPlayerID() . "&year=$year\">$year</a>";
}
//echo "Career";
echo "<br>\n";
if (isset($statWeeks))
{
	foreach ($statWeeks as $week)
	{
		echo "<a ";
			if ($week == $_REQUEST["week"])
				echo "class=\"current\" ";
		echo "href=\"$WEB_ROOT/players.php?player_id=" . $thisPlayer->getPlayerID() . "&year=" . $_REQUEST["year"] . "&week=$week\">$week</a> | ";
	}
	echo "<a ";
	if ($_REQUEST["week"] == "season")
		echo "class=\"current\" ";
	echo "href=\"$WEB_ROOT/players.php?player_id=" . $thisPlayer->getPlayerID() . "&year=" . $_REQUEST["year"] . "\">Season</a>";
}
echo "<br>\n";

if ($_REQUEST["year"] != "career")
{
	// single year stats
	if ($_REQUEST["week"] != "season")
	{	
		// single week stats
		$stats = $stat_lookup->getStatsByPlayerIDYearWeek($thisPlayer->getPlayerID(), $_REQUEST["year"], $_REQUEST["week"], $_SESSION["league_id"]);
		if ($stats === FALSE)
		{
			echo "<h2 class=\"error\">No stats found for " . $thisPlayer->getName() . " during " . $_REQUEST["year"] . " week " . $_REQUEST["week"] . ".</h2>\n";
			continue;
		}
		// stats found OK.

		$x = new OFFL_NFLGame();
		$game = $x->getNFLTeamGame($_REQUEST["year"], $_REQUEST["week"], $stats->getNFLTeamID());
		$opp = $game->getNFLTeamGameOpponent($_REQUEST["year"], $_REQUEST["week"], $stats->getNFLTeamID());

		if (!isset($_REQUEST["allstats"]) || $_REQUEST["allstats"] != "yes")
		{
			// show most relevant stats
			// QB: pass/rush
			// RB: rush/rec
			// WR: rec/rush
			// TE: rec/rush
			// K:  kicks
			switch ($thisPlayer->getPositionAbbv())
			{
				case "QB":
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Pass Att</th><th>Pass Cmp</th><th>Pass Yd</th><th>Pass TD</th><th>Int</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>Fmbl</th><th>2-Pt</th>
		</tr>
<?php

					$cats = array("Points", "PassAtt", "PassCmp", "PassYd", "PassTD", "Int", "RushAtt", "RushYd", "RushTD", "FmblLost", "TwoPt");
	
					break;
				case "RB":
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th>Fmbl</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th rowspan="300" class="vborder"></th>
			<th>2-Pt</th>
		</tr>
<?php

					$cats = array("Points", "RushAtt", "RushYd", "RushTD", "FmblLost", "RecAtt", "RecYd", "RecTD", "TwoPt");

					break;
				case "WR":
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th>Fmbl</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>2-Pt</th>
		</tr>
<?php

					$cats = array("Points", "RecAtt", "RecYd", "RecTD", "FmblLost", "RushAtt", "RushYd", "RushTD", "TwoPt");

					break;
				case "TE":
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th>Fmbl</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>2-Pt</th>
		</tr>
<?php

					$cats = array("Points", "RecAtt", "RecYd", "RecTD", "FmblLost", "RushAtt", "RushYd", "RushTD", "TwoPt");

					break;
				case "K":
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>FG 0-19</th><th>FG 20-29</th><th>FG 30-39</th><th>FG 40-49</th><th>FG 50+</th><th>FG Miss</th><th rowspan="300" class="vborder"></th>
			<th>XP</th><th>XP Miss</th>
		</tr>
<?php

						$cats = array("Points", "FG_0_19", "FG_20_29", "FG_30_39", "FG_40_49", "FG_50p", "FGMiss", "XP", "XPMiss");

					break;
				case "DEF":
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Pts<br />Allowed</th><th>Yds<br />Allowed</th><th>Pass Yds<br />Allowed</th><th>Rush Yds<br />Allowed</th><th rowspan="300" class="vborder"></th>
			<th>Sack</th><th>Fmbl Rec</th><th>Int</th><th rowspan="300" class="vborder"></th>
			<th>Fmbl TD</th><th>Int TD</th><th>Kick / Punt TD</th><th>Misc TD</th><th rowspan="300" class="vborder"></th>
			<th>Safety</th><th>Blk Kick</th>
		</tr>
<?php

						$cats = array("Points", "DEFPt", "DEFYd", "DEFPYd", "DEFRYd", "DEFSack", "DEFFmblRec", "DEFInt", "DEFFmblTD", "DEFIntTD", "DEFRetTD", "DEFMiscTD", "DEFSafety", "DEFBlkKick");

					break;
			} // end switch PositionAbbv

			$vals = array();
			foreach ($cats as $cat)
				$vals[$cat] = 0;

			echo "		<tr>\n";

			echo "<td>$opp</td>";
			echo "\n";
			foreach ($cats as $cat)
			{
				echo "<td>" . $stats->{"get" . $cat}() . "</td>\n";
				$vals[$cat] += $stats->{"get" . $cat}();
			}
			echo "\n";

			echo "		</tr>\n	</table>\n";
		
		} // end not all stats
		else // display all stats, only check is for def v. individ player.
		{
			// show all stats
			if ($thisPlayer->getPositionAbbv() != "DEF")
			{
?>	<table class="stattable">
		<tr>
			<th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Pass Att</th><th>Pass Cmp</th><th>Pass Yd</th><th>Pass TD</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th rowspan="300" class="vborder"></th>
			<th>Kick Return<br />Att</th><th>Kick Return<br />Yd</th><th>Kick Return<br />TD</th>
			<th>Punt Return<br />Att</th><th>Punt Return<br />Yd</th><th>Punt Return<br />TD</th><th rowspan="300" class="vborder"></th>
			<th>Int</th><th>Fmbl</th><th>2-Pt</th><th rowspan="300" class="vborder"></th>
			<th>FG 0-19</th><th>FG 20-29</th><th>FG 30-39</th><th>FG 40-49</th><th>FG 50+</th><th>FG Miss</th>
			<th>XP</th><th>XP Miss</th>
		</tr>
<?php
				$cats = array("Points", "PassAtt", "PassCmp", "PassYd", "PassTD", "RushAtt", "RushYd", "RushTD", "RecAtt", "RecYd", "RecTD", "KRetAtt", "KRetYd", "KRetTD", "PRetAtt", "PRetYd", "PRetTD", "Int", "FmblLost", "TwoPt", "FG_0_19", "FG_20_29", "FG_30_39", "FG_40_49", "FG_50p", "FGMiss", "XP", "XPMiss");

				$vals = array();
				foreach ($cats as $cat)
					$vals[$cat] = 0;

//				$opp = "Opp";

				echo "		<tr>\n";

				echo "<td>$opp</td>";
				echo "\n";
				foreach ($cats as $cat)
				{
					echo "<td>" . $stats->{"get" . $cat}() . "</td>\n";
					$vals[$cat] += $stats->{"get" . $cat}();
				}
				echo "\n";

				echo "		</tr>\n	</table>\n";
			}
			else // player is DEF
			{
				// should never display
			}
		} // end if show all
	}
	else // $_REQUEST["week"] == "season"
	{
		// get all stats for the player and season
		$statArray = array();
		foreach ($statWeeks as $week)
		{
			$statArray[] = $stat_lookup->getStatsByPlayerIDYearWeek($thisPlayer->getPlayerID(), $_REQUEST["year"], $week, $_SESSION["league_id"]);
		}

		// full season stats
		if (!isset($_REQUEST["allstats"]) || ($_REQUEST["allstats"] != "yes"))
		{ // show primarily relevant stats by position
			switch ($thisPlayer->getPositionAbbv())
			{
				case "QB":
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Pass Att</th><th>Pass Cmp</th><th>Pass Yd</th><th>Pass TD</th><th>Int</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>Fmbl</th><th>2-Pt</th>
		</tr>
<?php
					$cats = array("Points", "PassAtt", "PassCmp", "PassYd", "PassTD", "Int", "RushAtt", "RushYd", "RushTD", "FmblLost", "TwoPt");
					break;
				case "RB":
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th>Fmbl</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th rowspan="300" class="vborder"></th>
			<th>2-Pt</th>
		</tr>
<?php
					$cats = array("Points", "RushAtt", "RushYd", "RushTD", "FmblLost", "RecAtt", "RecYd", "RecTD", "TwoPt");
					break;
				case "WR":
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th>Fmbl</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>2-Pt</th>
		</tr>
<?php
					$cats = array("Points", "RecAtt", "RecYd", "RecTD", "FmblLost", "RushAtt", "RushYd", "RushTD", "TwoPt");
					break;
				case "TE":
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th>Fmbl</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>2-Pt</th>
		</tr>
<?php
					$cats = array("Points", "RecAtt", "RecYd", "RecTD", "FmblLost", "RushAtt", "RushYd", "RushTD", "TwoPt");
					break;
				case "K":
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>FG 0-19</th><th>FG 20-29</th><th>FG 30-39</th><th>FG 40-49</th><th>FG 50+</th><th>FG Miss</th><th rowspan="300" class="vborder"></th>
			<th>XP</th><th>XP Miss</th>
		</tr>
<?php
					$cats = array("Points", "FG_0_19", "FG_20_29", "FG_30_39", "FG_40_49", "FG_50p", "FGMiss", "XP", "XPMiss");
					break;
				case "DEF":
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Pts<br />Allowed</th><th>Yds<br />Allowed</th><th>Pass Yds<br />Allowed</th><th>Rush Yds<br />Allowed</th><th rowspan="300" class="vborder"></th>
			<th>Sacks</th><th>Fmbl Rec</th><th>Int</th><th rowspan="300" class="vborder"></th>
			<th>Fmbl TD</th><th>Int TD</th><th>Kick / Punt TD</th><th>Misc TD</th><th rowspan="300" class="vborder"></th>
			<th>Safety</th><th>Blk Kick</th>
		</tr>
<?php
					$cats = array("Points", "DEFPt", "DEFYd", "DEFPYd", "DEFRYd", "DEFSack", "DEFFmblRec", "DEFInt", "DEFFmblTD", "DEFIntTD", "DEFRetTD", "DEFMiscTD", "DEFSafety", "DEFBlkKick");
					break;
			}

			$vals = array();
			foreach ($cats as $cat)
				$vals[$cat] = 0;

			foreach ($statArray as $i=>$statRec)
			{
				$x = new OFFL_NFLGame();
				$game = $x->getNFLTeamGame($_REQUEST["year"], $statRec->getWeek(), $statRec->getNFLTeamID());
				$opp = $game->getNFLTeamGameOpponent($_REQUEST["year"], $statRec->getWeek(), $statRec->getNFLTeamID());
				
				if ($i % 2)
					echo "		<tr class=\"evenrow\">\n";
				else
					echo "		<tr class=\"oddrow\">\n";

				echo "<td>" . $statRec->getWeek() . "</td>";
				echo "<td>$opp</td>";
				echo "\n";
				foreach ($cats as $cat)
				{
					echo "<td>" . $statRec->{"get" . $cat}() . "</td>\n";
					$vals[$cat] += $statRec->{"get" . $cat}();
				}
				echo "\n";

				echo "		</tr>\n";
			}

			echo "		<tr><td style=\"background-color:#CCC; height:2px;\" colspan=\"300\"></td></tr>\n";
			echo "		<tr><td>" . sizeof($statArray) . " Games</td><td></td>\n"; // week and opponent
			foreach ($cats as $cat)
				echo "<td>" . $vals[$cat] . "</td>";

			echo "		</tr>\n";

			echo "	</table>\n";
		
		}
		else // show all stats, not just relevant
		{
			if ($thisPlayer->getPositionAbbv() != "DEF")
			{
?>	<table class="stattable">
		<tr>
			<th>Week</th><th>Opp</th><th rowspan="300" class="vborder"></th>
			<th>Fantasy<br />Points</th><th rowspan="300" class="vborder"></th>
			<th>Pass Att</th><th>Pass Cmp</th><th>Pass Yd</th><th>Pass TD</th><th rowspan="300" class="vborder"></th>
			<th>Rush Att</th><th>Rush Yd</th><th>Rush TD</th><th rowspan="300" class="vborder"></th>
			<th>Rec Att</th><th>Rec Yd</th><th>Rec TD</th><th rowspan="300" class="vborder"></th>
			<th>Kick Return<br />Att</th><th>Kick Return<br />Yd</th><th>Kick Return<br />TD</th>
			<th>Punt Return<br />Att</th><th>Punt Return<br />Yd</th><th>Punt Return<br />TD</th><th rowspan="300" class="vborder"></th>
			<th>Int</th><th>Fmbl</th><th>2-Pt</th><th rowspan="300" class="vborder"></th>
			<th>FG 0-19</th><th>FG 20-29</th><th>FG 30-39</th><th>FG 40-49</th><th>FG 50+</th><th>FG Miss</th>
			<th>XP</th><th>XP Miss</th>
		</tr>
<?php
				$cats = array("Points", "PassAtt", "PassCmp", "PassYd", "PassTD", "RushAtt", "RushYd", "RushTD", "RecAtt", "RecYd", "RecTD", "KRetAtt", "KRetYd", "KRetTD", "PRetAtt", "PRetYd", "PRetTD", "Int", "FmblLost", "TwoPt", "FG_0_19", "FG_20_29", "FG_30_39", "FG_40_49", "FG_50p", "FGMiss", "XP", "XPMiss");

				$vals = array();
				foreach ($cats as $cat)
					$vals[$cat] = 0;
				foreach ($statArray as $i=>$statRec)
				{
					$x = new OFFL_NFLGame();
					$game = $x->getNFLTeamGame($_REQUEST["year"], $statRec->getWeek(), $statRec->getNFLTeamID());
					$opp = $game->getNFLTeamGameOpponent($_REQUEST["year"], $statRec->getWeek(), $statRec->getNFLTeamID());
					
					if ($i % 2)
						echo "		<tr class=\"evenrow\">\n";
					else
						echo "		<tr class=\"oddrow\">\n";

					echo "<td>" . $statRec->getWeek() . "</td>";
					echo "<td>$opp</td>";
					echo "\n";
					foreach ($cats as $cat)
					{
						echo "<td>" . $statRec->{"get" . $cat}() . "</td>\n";
						$vals[$cat] += $statRec->{"get" . $cat}();
					}
					echo "\n";

					echo "		</tr>\n";
				}

				echo "		<tr><td style=\"background-color:#CCC; height:2px;\" colspan=\"300\"></td></tr>\n";
				echo "		<tr><td>" . sizeof($statArray) . " Games</td><td></td>\n"; // week and opponent
				foreach ($cats as $cat)
					echo "<td>" . $vals[$cat] . "</td>";

				echo "		</tr>\n";

				echo "	</table>\n";
			}
		}
	}
}
else // $_REQUEST["year"] == "career"
{
	// career stats, ignore $_REQUEST["week"]
}
if (!isset($_REQUEST["allstats"]))
	echo "<a style=\"font-variant:small-caps;\" href=\"$WEB_ROOT/players.php?player_id=" . $thisPlayer->getPlayerID() . "&year=" . $_REQUEST["year"] . "&week=" . $_REQUEST["week"] . "&allstats=yes\">[Show All Stats]</a>";

if (($_SESSION["admin"] == 1) && ($_REQUEST["week"] != "season"))
	// provide link to editstats.php
{
	echo " | <a style=\"font-variant:small-caps;\" href=\"$WEB_ROOT/editstats.php?player_id=" . $thisPlayer->getPlayerID() . "&amp;year=" . $_REQUEST["year"] . "&amp;week=" . $_REQUEST["week"] . "\">[Edit Stats]</a>";
}

echo "<br />\n";
?>


						FFL Team: <?php if($thisPlayer->getFFLTeamID() != 0) { ?><a href="<?php echo $WEB_ROOT; ?>/teams.php?fflteam_id=<?php echo $thisPlayer->getFFLTeamID(); ?>"><?php echo $thisPlayer->getFFLTeamCity() . " " . $thisPlayer->getFFLTeamName(); ?></a><?php } else { echo "Free Agent"; } ?><br>

						<?php if (trim($thisPlayer->getNFLProfile()) != "") { ?>
						<a href="<?php echo $thisPlayer->getNFLProfile(); ?>" target="_blank">NFL.com Profile</a> (Opens new window)
						<?php } ?>

					</td>
				</tr>
			</table>
			<?php
		}
	} // end if playerid
	elseif($_REQUEST["mode"] == "admin")
	{
		// Present page of add/edit option
		//	Edit has drop-down of options
			?>
			<table border="0" cellpadding="3" cellspacing="0" width="50%">
				<tr valign="top">
					<td>
						<form name="addplayer" action="<?php echo $WEB_ROOT; ?>/players.php">
							<input type="hidden" name="mode" value="add">
							<input type="submit" value="Add Player">
						</form>
					</td>
					<td>
						<form name="editplayer" action="<?php echo $WEB_ROOT; ?>/players.php">
							<input type="hidden" name="mode" value="editselect">
							<input type="submit" value="Edit Player">
						</form>
					</td>
					<td>
						<form name="getnfltrades" action="<?php echo $WEB_ROOT; ?>/players.php">
							<input type="hidden" name="mode" value="getall" />
							<input type="hidden" name="tradetrack" value="on" />
							<input type="hidden" name="step" value="1" />
							<input type="submit" value="Update NFL Trades" />
						</form>
					</td>
				</tr>
				<tr valign="top">
					<td>&nbsp;</td>
				</tr>
			</table>
			<?php

	}
	elseif ($_REQUEST["mode"] == "editselect")
	{
		if ($_SESSION["admin"] == 1)
		{
			$players = $myleague->getPlayers();
?>
				<form name="editplayer" action="<?php echo $WEB_ROOT; ?>/players.php">
					<input type="hidden" name="mode" value="edit">
					<select name="player_id">
<?php
			foreach ($players as $player)
			{
				echo "\t\t\t\t\t\t<option value=\"" . $player->getPlayerID() . "\">" . $player->getName() . "</option>\n";
			}

?>
					</select>
					<input type="submit" value="Edit Player">
				</form>
<?php
		}
	}
	elseif ($_REQUEST["mode"] != "getall")
	{
		if ($_SESSION["admin"] == 1)
		{

		if($_REQUEST["mode"] == "edit")
		{
			if(isset($_REQUEST["player_id"]))
			{
				$thisPlayer = new OFFL_Player($_REQUEST["player_id"]);
				if(!empty($thisPlayer->_emsg))
				{
					?><div class="alert"><?php echo $thisPlayer->_emsg; ?></div><?php
				}
			}
		}

// $thisPlayer variable contains what we need
?>
<form name="playerinfo" action="<?php echo $WEB_ROOT; ?>/players.php">
<?php if ($_REQUEST["mode"] == "edit") { ?>
	<input type="hidden" name="player_id" value="<?php echo $thisPlayer->getPlayerID() ?>">
<?php } ?>
	<input type="hidden" name="mode" value="<?php echo $_REQUEST["mode"] ?>">
	<input type="hidden" name="type" value="<?php echo $_REQUEST["type"] ?>">
	<input type="hidden" name="action" value="save">

	<table border="0">
		<tr>
			<th align="right">Name:</th>
			<td><input type="text" name="fname" size="20" maxlength="50"<?php if($_REQUEST["mode"] == "edit") { ?> value="<?php echo $thisPlayer->getFirstName() ?>"<?php } ?>></td>
			<td><input type="text" name="lname" size="20" maxlength="50"<?php if($_REQUEST["mode"] == "edit") { ?> value="<?php echo $thisPlayer->getLastName() ?>"<?php } ?>></td>
		</tr>
		<tr valign="top">
			<th align="right">&nbsp;</th>
			<td class="small">First</td>
			<td class="small">Last</td>
		</tr>
		<tr>
			<th align="right">Position:</th>
			<td colspan="2">
				<select name="position_id" size="1">
					<option value="0"> -- Select One -- </option>
					<?php
						$a = new OFFL_Position();
						$positions = $a->getAllPositions();
						foreach($positions as $pos)
						{
							?>
								<option value="<?php echo $pos->getPositionID(); ?>"<?php
									if(($_REQUEST["mode"] == "edit") && ($pos->getPositionID() == $thisPlayer->getPositionID())) { ?> selected<?php } ?>><?php echo $pos->getPositionName(); ?></option>
							<?php
						}

					?>
				</select>
			</td>
		</tr>
		<tr>
			<th align="right">Picture Filename:</th>
			<td colspan="2"><input type="text" name="picture_loc" size="40" maxlength="80"<?php if($_REQUEST["mode"] == "edit") { ?> value="<?php echo $thisPlayer->getPictureLoc() ?>"<?php } ?>></td>
		</tr>
		<tr>
			<th align="right">NFL Team:</th>
			<td colspan="2">
				<select name="nflteam_id" size="1">
					<option value="0"> -- Select One -- </option>
					<?php
						$a = new OFFL_NFLTeam();
						$nflteams = $a->getAllNFLTeams();
						foreach($nflteams as $nflteam)
						{
							?>
								<option value="<?php echo $nflteam->getNFLTeamID(); ?>"<?php
									if(($_REQUEST["mode"] == "edit") && ($nflteam->getNFLTeamID() == $thisPlayer->getNFLTeamID())) { ?> selected<?php } ?>><?php echo $nflteam->getNFLTeamCity() . " " . $nflteam->getNFLTeamName(); ?></option>
							<?php
						}

					?>
				</select>
			</td>
		</tr>
		<tr>
			<th align="right">NFL.com Profile:</th>
			<td colspan="2"><input type="text" name="nfl_profile" size="50" maxlength="100"<?php if($_REQUEST["mode"] == "edit") { ?> value="<?php echo $thisPlayer->getNFLProfile() ?>"<?php } ?>></td>
		</tr>
<?php if($mode == "edit") { ?>
		<tr>
			<th align="right"><?php echo $control->getValue("MISC_LEAGUE_ABBV"); ?> Team:</th>
			<td colspan="2">
				<select name="fflteam_id" size="1">
					<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>
			</td>
		</tr>
<?php } ?>
		<tr valign="top">
			<th align="right">Active:</th>
			<td><input type="checkbox" name="active" value="1"<?php 
			if (($_REQUEST["mode"] == "edit")&&($thisPlayer->getActive())){ 
				?> checked<?php 
			} elseif($_REQUEST["mode"] == "add") { 
				// New additions default to active
				?> checked<?php 
			} ?>></td>
		</tr>
		<tr>
			<th align="right">&nbsp;</th>
			<td colspan="2"><input type="submit" value="Save Player"></td>
		</tr>
	</table>

</form>

<?php } // end is admin
	}
	else // $_REQUEST["mode"] == "getall"
	{
		if ($_SESSION["admin"] == 1)
		{
		if (!isset($_REQUEST["tradetrack"]))
		{
			if ($_REQUEST["step"] != "2") // confirm action
			{
	?>			<h2>Download NFL Roster</h2>
				<p>Warning!	This will completely replace the current players list, necessitating the drop of all
				players from team rosters and draft records!	Hopefully I'll get a non-destructive update done later,
				but for now, this is all you get!
				<form name="getnflroster" action="<?php echo $WEB_ROOT; ?>/players.php">
					<input type="hidden" name="mode" value="getall" />
					<input type="hidden" name="step" value="2" />
					I'm sure!	Update me!	<input type="checkbox" name="confirm" />
					<input type="submit" value="Download NFL Roster" />
				</form>

	<?php	}
			else // proceed with SQL stuff here
			{
				if ($_REQUEST["confirm"] != "on")
					echo "<META http-equiv=\"refresh\" content=\"0; URL=$WEB_ROOT/players.php?mode=admin\">";
				else
				{
					/* ok, steps to pull this off:

					1) get the list of NFL teams.	Use their abbreviations
					2) run through that list and
						a) parse for players
						b) create SQL calls
						c) include an SQL call for the defense
						d) replace team and position abbreviations with indexes
					3) assemble other SQL calls (empty table, etc)
					4) run the SQL calls
					*/

					$x = new OFFL_NFLTeam();
					$teams = $x->getAllNFLTeams();
					$x = new OFFL_Position();
					$positions = $x->getAllPositions();
					$pos_id = Array();
					$pos_name = Array();

					foreach ($positions as $position)
					{
						$pos_id[$position->getPositionAbbv()] = $position->getPositionID();
						$pos_name[$position->getPositionID()] = $position->getPositionAbbv();
					}

					$sqllist = Array();
					$sqllist[0] = "TRUNCATE TABLE `players`";
					
					// here's the main team iterative loop
					foreach($teams as $team)
					{
	//					echo $team->getNFLTeamAbbv() . " (" . $team->getNFLTeamID() . ")<br>";

						$nflteam = $team->getNFLTeamAbbv();
						$nflteam_id = $team->getNFLTeamID();

						$teamroster = file("http://www.nfl.com/teams/rosters/$nflteam");
						$teamstring = "";

						foreach ($teamroster as $teamline)
						{
							$teamstring .= $teamline;
						}

						//echo $teamstring;

						list($beforetable, $tableandafter) = explode("<div class=SLTables1>", $teamstring, 2);
						unset($beforetable);
						unset($teamstring);
						list($table, $aftertable) = explode("</table>", $tableandafter, 2);
						unset($aftertable);
						unset($tableandafter);

						// echo $table;

						$players_raw = explode("<tr", $table);

						for ($i = 3; $i < sizeof($players_raw); $i++)
						{
							$player_temp = explode("<td", $players_raw[$i], 5);
							if (strpos($player_temp[2], "/players"))
								// this finds players who don't have NFL.com profiles
								// the condition might should be changed to check for "href=", though
							{
								list($temp1, $player[$i][3], $player[$i][0], $temp2) = explode(">", $player_temp[2]);
							}
							else
							{
								list($temp1, $player[$i][0], $temp2) = explode(">", $player_temp[2]);
							}
							list($temp1, $player[$i][2], $temp2) = explode(">", $player_temp[3]);

							list($player[$i][0], $player[$i][1]) = explode(",", $player[$i][0], 2);
							list($player[$i][1], $temp1) = explode("<", $player[$i][1], 2);
							list($player[$i][2], $temp1) = explode("<", $player[$i][2], 2);
							@list($temp1, $player[$i][3], $temp2) = explode("\"", $player[$i][3], 3);
							$player[$i][3] = trim($player[$i][3]);
							if ($player[$i][3] != "")
								$player[$i][3] = "http://www.nfl.com" . $player[$i][3];

							// get rid of the leading space on player first names
							$player[$i][1] = ltrim($player[$i][1]);

							$player[$i][0] = mysql_escape_string($player[$i][0]); // last name
							$player[$i][1] = mysql_escape_string($player[$i][1]); // first name

							if (strcmp($player[$i][2], "FB") == 0)
								$player[$i][2] = "RB";

							foreach ($pos_name as $pos)
							{
								if (strcmp($player[$i][2], $pos) == 0)
								{
									$player[$i][2] = $pos_id[$pos];
									break;
								}
							}

						}
						$teaminfo = $players_raw[1];
						list($temp1, $teaminfo, $temp2) = explode("font>", $teaminfo);
						list($teaminfo, $temp1) = explode("<", $teaminfo);
						$teaminfo = explode(" ", $teaminfo);
						$teamname = $teaminfo[sizeof($teaminfo) - 1];

	//					echo ($teamname) . "<br>";

						unset($players_raw);
						unset($player_temp);

						foreach($player as $plyr)
						{
	//						if (($plyr[2] == "QB") || ($plyr[2] == "RB") || ($plyr[2] == "WR") || ($plyr[2] == "TE") || ($plyr[2] == "K"))
							if (($plyr[2] > 0) && ($plyr[2] < 50))
								$sqllist[] = "INSERT INTO `players` (lname,fname,nflteam_id,position_id,nfl_profile) VALUES ('$plyr[0]','$plyr[1]',$nflteam_id,$plyr[2],'$plyr[3]')";
						}
						unset ($player);
						$sqllist[] = "INSERT INTO `players` (lname,nflteam_id,position_id) VALUES ('$teamname', $nflteam_id, " . $pos_id["DEF"] . ")";
					}

	/*
		The SQL statements are prepared.	Now open the database and run them.
	*/
					$db = new OFFL_DBObject();
					$dbconn = $db->getConn();

					foreach ($sqllist as $sql)
						$result = mysql_query($sql, $dbconn);

	//					echo "$sql<br>\n";
			
					$db->closeDB();

					echo "<h2>Download complete!</h2>";
				}
			}
		} // end regular download
		else
		{
			if ($_REQUEST["step"] != "2") // confirm action
			{
	?>			<h2>Update NFL Roster</h2>
				<p>This will update the current NFL roster to reflect trades.	It may substitute for the download option already in place.</p>
				<form name="getnflroster" action="<?php echo $WEB_ROOT; ?>/players.php">
					<input type="hidden" name="mode" value="getall" />
					<input type="hidden" name="tradetrack" value="on" />
					<input type="hidden" name="step" value="2" />
					I'm sure!	Update me!	<input type="checkbox" name="confirm" />
					<input type="submit" value="Download NFL Roster" />
				</form>

	<?php	}
			else // proceed with SQL stuff here
			{
// *** BEGIN PROCESSING OF TRADES
				
				if ($_REQUEST["confirm"] != "on")
					echo "<META http-equiv=\"refresh\" content=\"0; URL=$WEB_ROOT/players.php?mode=admin\">";
				else
				{
					/* ok, steps to pull this off:

					1) set all non-defense players to inactive

					2) get the list of NFL teams.	Use their abbreviations
					3) run through that list and
						a) parse for players
						b) compare player profiles
							if same: create UPDATE SQL call
							else: create INSERT SQL call
						c) replace team and position abbreviations with indexes
					4) assemble other SQL calls (empty table, etc) -- might not be needed?
					5) run the SQL calls
					*/

//					$x = new OFFL_NFLTeam();
//					$teams = $x->getAllNFLTeams();
//					$x = new OFFL_Position();
//					$positions = $x->getAllPositions();
//					$pos_id = Array();
//					$pos_name = Array();
//
//					foreach ($positions as $position)
//					{
//						$pos_id[$position->getPositionAbbv()] = $position->getPositionID();
//						$pos_name[$position->getPositionID()] = $position->getPositionAbbv();
//					}
//
//					$sqllist = Array();
//					$sqllist[0] = "UPDATE players SET active=0 WHERE position_id<>8"; // not defense (I can ignore that)
//					
//					// here's the main team iterative loop
//					foreach($teams as $i=>$team)
//					{
//	//					echo $team->getNFLTeamAbbv() . " (" . $team->getNFLTeamID() . ")<br>";
//
//						$nflteam = $team->getNFLTeamAbbv();
//						$nflteam_id = $team->getNFLTeamID();
//
//						$teamroster = file("http://www.nfl.com/teams/rosters/$nflteam");
//						$teamstring = "";
//
//						foreach ($teamroster as $teamline)
//						{
//							$teamstring .= $teamline;
//						}
//
//						//echo $teamstring;
//
//					//	debugprint($teamstring);
//						$teamstring = str_replace("</tr>", "</tr>\n", $teamstring);
//
//						list($beforetable, $tableandafter) = explode("<div class=SLTables1>", $teamstring, 2);
//
//					//	debugprint($tableandafter);
//						unset($beforetable);
//						unset($teamstring);
//						list($table, $aftertable) = explode("</table>", $tableandafter, 2);
//						unset($aftertable);
//						unset($tableandafter);
//						list($empty, $table) = explode("College</td></tr>", $table, 2);
//
//					//	debugprint($table);
//
//						// echo $table;
//
//						$players_raw = explode("<tr", $table);
//
//						// for ($i = 3; $i < sizeof($players_raw); $i++)
//						foreach($players_raw as $i=>$player_row)
//						{
//							if ($i == 0)
//								continue; //skip the empty first entry
//
//							$player_temp = explode("<td", $player_row, 5);
//
//							if (strpos($player_temp[2], "/players"))
//								// this finds players who don't have NFL.com profiles
//								// the condition might should be changed to check for "href=", though
//							{
//								@list($temp1, $player[$i][3], $player[$i][0], $temp2) = explode(">", $player_temp[2]);
//							}
//							else
//							{
//								@list($temp1, $player[$i][0], $temp2) = explode(">", $player_temp[2]);
//							}
//							@list($temp1, $player[$i][2], $temp2) = explode(">", $player_temp[3]);
//
//							@list($player[$i][0], $player[$i][1]) = explode(",", $player[$i][0], 2);
//							@list($player[$i][1], $temp1) = explode("<", $player[$i][1], 2);
//							@list($player[$i][2], $temp1) = explode("<", $player[$i][2], 2);
//							@list($temp1, $player[$i][3], $temp2) = explode("\"", $player[$i][3], 3);
//							$player[$i][3] = trim($player[$i][3]);
//							if ($player[$i][3] != "") // should fix finding players w/o profiles.
//								$player[$i][3] = "http://www.nfl.com" . $player[$i][3];
//	
//							// get rid of the leading space on player first names
//							$player[$i][1] = ltrim($player[$i][1]);
//
//							$player[$i][0] = mysql_escape_string($player[$i][0]); // last name
//							$player[$i][1] = mysql_escape_string($player[$i][1]); // first name
//
//							if (strcmp($player[$i][2], "FB") == 0)
//								$player[$i][2] = "RB";
//
//							foreach ($pos_name as $pos)
//							{
//								if (strcmp($player[$i][2], $pos) == 0)
//								{
//									$player[$i][2] = $pos_id[$pos];
//									break;
//								}
//							}
//
//							debugprint($player[$i]);
//
//						}
//						$teaminfo = $players_raw[1];
//						list($temp1, $teaminfo, $temp2) = explode("font>", $teaminfo);
//						list($teaminfo, $temp1) = explode("<", $teaminfo);
//						$teaminfo = explode(" ", $teaminfo);
//						$teamname = $teaminfo[sizeof($teaminfo) - 1];
//
//	//					echo ($teamname) . "<br>";
//
//						unset($players_raw);
//						unset($player_temp);
//
//						$player_lookup = new OFFL_Player();
//
//						foreach($player as $plyr)
//						{
//	//						if (($plyr[2] == "QB") || ($plyr[2] == "RB") || ($plyr[2] == "WR") || ($plyr[2] == "TE") || ($plyr[2] == "K"))
//							if (($plyr[2] > 0) && ($plyr[2] < 50))
//							{	
//								$new_player = $player_lookup->getPlayerByNFLProfile($plyr[3]);
//								
//								if ($new_player === FALSE)
//									$sqllist[] = "INSERT INTO `players` (lname,fname,nflteam_id,position_id,nfl_profile) VALUES ('$plyr[0]','$plyr[1]',$nflteam_id,$plyr[2],'$plyr[3]')";
//								else
//									$sqllist[] = "UPDATE players SET active=1, nflteam_id=$nflteam_id WHERE player_id=" . $new_player->getPlayerID();
//							}
//						}
//						unset ($player);
//					}
//
//					$sqllist[] = "UPDATE players SET nflteam_id=0 WHERE active=0";
//	/*
//		The SQL statements are prepared.	Now open the database and run them.
//	*/
//					$db = new OFFL_DBObject();
//					$dbconn = $db->getConn();
//
//					foreach ($sqllist as $sql)
//						$result = mysql_query($sql, $dbconn);
//
//	//					echo "$sql<br>\n";
//			
//					$db->closeDB();
//

				    include ("./lib/inc/htmlparser.inc");

					$x = new OFFL_NFLTeam(); 
					$teams = $x->getAllNFLTeams(); 
					
					foreach($teams as $team) {
						$nflteamcity = $team->getNFLTeamCity(); 
						$nflteamname = $team->getNFLTeamName(); 
						$nflteamabbv = $team->getNFLTeamAbbv(); 
						$nflteamfullname = str_replace(" ", "", strtolower($nflteamcity . $nflteamname)); 
					
						echo $nflteamfullname . "<br/>";
					}
					
					$x = new OFFL_Position(); 
					$positions = $x->getAllPositions(); 
					$pos_id = Array(); 
					$pos_name = Array(); 
					 
					foreach ($positions as $position) { 
						$pos_id[$position->getPositionAbbv()] = $position->getPositionID(); 
						$pos_name[$position->getPositionID()] = $position->getPositionAbbv(); 
					} 
					
					$warnings = array(); 
					$playersmoved = array(); 
					$sqllist = Array();
					 
					//do not reset defense
					$sqllist[0] = "UPDATE players SET active=0 WHERE position_id<>8"; 
					
					$num = 0;  
					 
					// here's the main team iterative loop 
					foreach($teams as $team) {
						$player = array(); 
						// structure of the old player object: 
						// $player[$i][0] last name 
						// $player[$i][1] first name 
						// $player[$i][2] position abbv 
						// $player[$i][3] profile relative url 
						// $player[$i][4] trash, but I'll use this to store nflteam_id 
					
						$nflteamcity = $team->getNFLTeamCity(); 
						$nflteamname = $team->getNFLTeamName(); 
						$nflteamabbv = $team->getNFLTeamAbbv(); 
						$nflteamfullname = str_replace(" ", "", strtolower($nflteamcity . $nflteamname)); 
						 
						//$teamurl = "http://www.nfl.com/teams/" . $nflteamfullname . "/roster?team=" . $nflteamabbv; 
						$teamurl = "http://www.sportsline.com/nfl/teams/roster/" . $nflteamabbv;
						 
						$nflteam_id = $team->getNFLTeamID(); 
						 
						$teamroster = file("$teamurl"); 
						$teamstring = ""; 
					 
						foreach ($teamroster as $teamline) { 
							$teamstring .= $teamline; 
						} 
						
						list($beforetable, $tableandafter) = explode("COLLEGE</a></td></tr>", $teamstring, 2); 
						unset($beforetable); 
						unset($teamstring); 
						list($table, $aftertable) = explode("<tr  id=special align=middle  class=bg1>", $tableandafter, 2); 
						unset($aftertable); 
						unset($tableandafter); 
						
						//echo $table;
						 
						$parser = new HtmlParser ($table);
					
					    $currentPlayerNbr = '';
					    $currentPlayerName = '';
					    $currentPlayerPosition = '';
						$currentPlayerProfile = '';
					    
					    while ($parser->parse()) {
							//echo $players_raw[$i] . "<br/>";
							
							//echo $parser->iNodeType . " - " . $parser->iNodeName . " - " . $parser->iNodeValue . "<br/>";
					
							if (($parser->iNodeType == 1) && ($parser->iNodeName == 'tr')) {
								//echo "new player<br/>";
								$i++;
							    $currentPlayerNbr = '';
							    $currentPlayerName = '';
							    $player_lname = '';
							    $player_fname = '';
							    $currentPlayerPosition = '';
							    $currentPlayerProfile = '';
							} elseif (($parser->iNodeType == 1) && ($parser->iNodeName == 'a') && ($currentPlayerProfile == '')) {
					            $attrValues = $parser->iNodeAttributes;
								$currentPlayerProfile = "http://www.sportsline.com" . $attrValues['href'];
								//$currentPlayerProfile = $attrValues['href'];
							} elseif (($parser->iNodeType == 3) && ($parser->iNodeName == 'Text') && ($currentPlayerNbr == '')) {
								$currentPlayerNbr = $parser->iNodeValue;
							} elseif (($parser->iNodeType == 3) && ($parser->iNodeName == 'Text') && ($currentPlayerName == '')) {
								$currentPlayerName = $parser->iNodeValue;
					
								list ($player_lname, $player_fname) = explode(", ", $currentPlayerName, 2); 
							} elseif (($parser->iNodeType == 3) && ($parser->iNodeName == 'Text') && (trim($parser->iNodeValue) != '') && ($currentPlayerPosition == '')) {
								$currentPlayerPosition = $parser->iNodeValue;
					
								$player[$i][0] = $player_lname;
								$player[$i][1] = $player_fname;
								$player[$i][2] = $currentPlayerPosition;
								$player[$i][3] = $currentPlayerProfile;
					//			$player[$i][4] = ''; // blank this out to use later for nflteam_id 
					
								$player[$i][0] = mysql_escape_string($player[$i][0]); // last name 
								$player[$i][1] = mysql_escape_string($player[$i][1]); // first name 
									 
								if (strcmp($player[$i][2], "FB") == 0) 
									$player[$i][2] = "RB"; 
						
								foreach ($pos_name as $pos) { 
									if (strcmp($player[$i][2], $pos) == 0) { 
										$player[$i][2] = $pos_id[$pos]; 
										break; 
									} 
								} 
					
								//echo $i . ":" . $currentPlayerNbr . " - " . $player_lname . " - " . $player_fname . " - " . $currentPlayerPosition . " - " . $currentPlayerProfile . "<br/>";
							}
						} 
					 
						foreach ($player AS $i=>$plr) { 
							//only handle players that are in a valid FFL position
							if(is_numeric($player[$i][2])) { 
								//$sql = "SELECT player_id, nflteam_id, fname, lname, position_id, nfl_profile FROM players WHERE lname = '" . $player[$i][0] . "' AND fname = '" . $player[$i][1] . "'"; //nflteam_id = " . $team->getNFLTeamID() . " AND 
								$sql = "SELECT player_id, nflteam_id, fname, lname, position_id, nfl_profile FROM players WHERE nfl_profile = '" . $player[$i][3] . "'"; //nflteam_id = " . $team->getNFLTeamID() . " AND 
								$result = mysql_query($sql) or die (mysql_error() . ": $sql");//,$this->_conn 
								$multi = mysql_num_rows($result); 
								if($multi > 1) { 
									$warnings[]= "<tr><td colspan=\"8\">Warning, multiple players by this name: " . $player[$i][1] . " " . $player[$i][0] . "</td></tr>"; 
								} else {  
									if(mysql_result($result,0,"player_id") != "") { 
										$sqllist[] = "UPDATE players SET active=1, lname='" . $player[$i][0] . "', fname='" . $player[$i][1] . "', nflteam_id=" . $team->getNFLTeamID() . ", nfl_profile='" . $player[$i][3] . "' WHERE player_id=" . mysql_result($result,0,"player_id"); } 
									else { 
										$sqllist[] = "INSERT INTO players (lname,fname,nflteam_id,position_id,nfl_profile) VALUES ('" . $player[$i][0] . "','" . $player[$i][1] . "'," . $team->getNFLTeamID() . "," . $player[$i][2] . ",'" . $player[$i][3] . "')"; } 
									} 
									$num++; 
							} else { 
								unset($player[$i]); 
							} 
						}
					} 
					
					if(sizeof($warnings)) { 
						echo "<table>"; 
						echo "<tr><td>Following players not updated; handle these players manually:</td></tr>"; 
					
						foreach($warnings AS $warning) { 
							echo $warning; 
						} 
					
						echo "</table>"; 
					} 
					
					$db = new OFFL_DBObject(); 
					$dbconn = $db->getConn(); 
					 
					foreach ($sqllist as $sql) { 
						$result = mysql_query($sql, $dbconn); 
						echo "$result - $sql<br>\n"; 
					} 
					 
					$db->closeDB(); 

					echo "<h2>Trade update complete!</h2>";
				}
			}
// *** END PROCESSING OF TRADES

		} // end trade track
		} // end is admin
	} // end mode check
}

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