Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Problem prcoessing update PHP/MySQL

Hi there,

I have this fantasy football system i am trying to use called OFFL. There is no real support for it now days since 2007 so I am kind of stuck.

I am trying to process scores for week 1 basically. But when i run the processscores.php file it says processing Fantasy Scores - 2011 - week 2181. I don't understand how or why it says week 2181? There must be a game time or something somewhere that is well out of date or what?

I need for it to process Fantasy Scores - 2001 - week 1!

Code added. Please help. If you need more details just ask. Thanks.
<?php
/**
 * Scores Processor
 *
 * This file should be run via cron.  I recommend every 10 minutes, 2 minutes after stats run.  It updates the game methods.
 * I leave this out of the stats process itself because it's already busy enough.
 * 
 * that line would look like:
 * 
 * 2,12,22,32,42,52 * * * * /path/to/php /path/to/processscores.php
 * 
 * alternately, win32 servers can use pycron (http://www.kalab.com/freeware/pycron/pycron.htm)
 * and have a line like
 * 
 * 2,12,22,32,42,52 * * * * "c:\path\to\php" "c:\path\to\processscores.php"
 * 
 * Since you're not accessing this via the web, you should place it outside of your document root.
 * There are no permission checks; therefore, anyone could prematurely execute a waiver claim if the
 * file is public.  Security through obscurity is a poor substitute.
 * 
 * @author Stephen Rochelle <lomn@lomn.net>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-maint
 */


$pageTitle = "Fantasy Score Processing";
$public = TRUE;
$maintenance = TRUE;
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php");

if (!isset($_GET["year"]))
{	$_GET["year"] = getThisYear();	}
if (!isset($_GET["week"]))
{	$_GET["week"] = getCurrentWeek($_GET["year"]);	}

echo "<h2>" . $_GET["year"] . " Week " . $_GET["week"] . " Scores</h2>\n";

// check to see if this is the current week (and use players for roster)
// or a past week (and use pastrosters for roster)
$curr_year = getThisYear();
$curr_week = getCurrentWeek($curr_year);

$playerStat_lookup = new OFFL_PlayerStat();
$current = FALSE;
if (($curr_week == $_GET["week"]) && ($curr_year == $_GET["year"]))
{	$current = TRUE;	}

// find the final game of the week so I can setFinal() if needed
$x = new OFFL_NFLGame();
$weekGames = $x->getNFLGames($_GET["year"], $_GET["week"]);
$gametime = 0;
foreach ($weekGames as $nfl_game)
{	
	if ($nfl_game->getGametime() > $gametime)
	{	$gametime = $nfl_game->getGametime();	}
}
$final = 0;
if ( (time()-$gametime) > (5*3600) ) // 5 hours past start time of last weekly game
{	$final = 1;	}

// *********************************************
// start checking for new compatibility here!!!
// *********************************************
$x = new OFFL_Game();
$games = $x->getGames(NULL, $_GET["year"], $_GET["week"]);

foreach ($games as $game)
{
	$hTeam = new OFFL_FFLTeam($game->getHFFLTeamID());
	$vTeam = new OFFL_FFLTeam($game->getVFFLTeamID());
	if ($current)
	{
		$hRosterPlayers = $hTeam->getRoster(TRUE); // get starters
		$vRosterPlayers = $vTeam->getRoster(TRUE);
		$hRoster = array();
		$vRoster = array();
		foreach ($hRosterPlayers as $player)
		{	$hRoster[] = $player->getPlayerID();	}
		foreach ($vRosterPlayers as $player)
		{	$vRoster[] = $player->getPlayerID();	}
	}
	else
	{
		$hPastRoster = new OFFL_PastRoster($_GET["year"], $_GET["week"], $game->getHFFLTeamID());
		$hRoster = array();
		$hR = $hPastRoster->getPlayerIDArray();
		$hS = $hPastRoster->getStarterArray();
		foreach ($hR as $i=>$player_id)
		{
			if ($hS[$i])
			{	$hRoster[] = $player_id;	}
		}
		$vPastRoster = new OFFL_PastRoster($_GET["year"], $_GET["week"], $game->getVFFLTeamID());
		$vRoster = array();
		$vR = $vPastRoster->getPlayerIDArray();
		$vS = $vPastRoster->getStarterArray();
		foreach ($vR as $i=>$player_id)
		{
			if ($vS[$i])
			{	$vRoster[] = $player_id;	}
		}
	}

	$hScore = 0;
	$vScore = 0;
	foreach ($hRoster as $player_id)
	{
		$stat = $playerStat_lookup->getStatsByPlayerIDYearWeek($player_id, $_GET["year"], $_GET["week"]);
		if ($stat !== FALSE)
		{
			$stat->setLeagueID($game->getLeagueID());
			$hScore += $stat->calculatePoints();
		}
	}
	foreach ($vRoster as $player_id)
	{
		$stat = $playerStat_lookup->getStatsByPlayerIDYearWeek($player_id, $_GET["year"], $_GET["week"]);
		if ($stat !== FALSE)
		{
			$stat->setLeagueID($game->getLeagueID());
			$vScore += $stat->calculatePoints();
		}
	}

	$game->setHFFLTeamScore($hScore);
	$game->setVFFLTeamScore($vScore);

	echo "<p>" . $vTeam->getFFLTeamFullName() . " " . $vScore . " at " . $hTeam->getFFLTeamFullName() . " " . $hScore;
	if ($final)
	{	echo " (Final)";	}
	else
	{	echo " (In Progress)";	}
	echo "</p>\n";

	$game->setFinal($final);

	$game->save();
}

require($DOC_ROOT . "/lib/footer.php"); ?>

Open in new window

0
james130c
Asked:
james130c
  • 6
1 Solution
 
james130cAuthor Commented:
I don't know if this helps. But In functions there is the code below.
/**
 * Returns the current week of the FFL season based on league-invariant control value "MISC_SEASON_START_YYYY"
 *
 * Formerly associated with Game class, but doesn't really need to be there.  Maybe relocate to {@link functions.php}.
 * @return integer Current week of the FFL season
 */
function getCurrentWeek($year)
{
	global $localtest;

	$ctrl = new OFFL_Control();
	$season_start = $ctrl->getValue("MISC_SEASON_START_" . $year);

	@list($date, $time) = explode(" ", $season_start);
	@list($Y, $M, $D) = explode("-", $date);
	@list($h, $i, $s) = explode(":", $time);
	$time = gmmktime($h, $i, $s, $M, $D, $Y);

	$curr_time = time() - $time - (3600*24*7);
	$week = 1;

	while ($curr_time > 0)
	{
		$curr_time -= 3600 * 24 * 7; // one week in seconds
		$week++;
	}
	return $week;
}

Open in new window

0
 
mattibuttCommented:
I think its doing week 21 however 81 could be the year can you select a different year
0
 
james130cAuthor Commented:
Hi there,

there is no way to change the year or date when running the process file...? see this link... http://lilkixx.co.uk/maintenance/processscores.php 

As youll see it processes the scores but for some reason the year is right 2011.  But the week says 2181? I am totally unsure why. I just installed and created this yesterday. If anything shouldn't it be on week 1?

Im totally lost as to why it's using week 2181?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
james130cAuthor Commented:
***UPDATE***

I have since found out that if i change the database (week) feilds from (1) to (2181) and run the processscores.php ... it actually works and processes the scores. So there is definitely something somewhere that thinks the week should be 2181. When I want it to be week 1.

Any ideas why this is trying to process week 2181? Thanks.
0
 
james130cAuthor Commented:
Full function.php file code.
<?php
/**
 * Miscellaneous Functions
 *
 * @author Stephen Rochelle <lomn@lomn.net>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl
 */

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

function GMTOffsetTime($timestamp)
/*
	Takes a Unix timestamp, returns the stamp plus offset from $_SESSION["offset"]
	such that gmdate("", return) gives data in client's timezone.
*/
{
	if (!isset($_SESSION["offset"]))
	{
		return $timestamp;
	}
	else
	{
		return $timestamp - $_SESSION["offset"];
	}
}

function getThisYear()
{
	$today = getdate();
	$year = $today["year"];
	if ( ($today["month"] == "January") || ($today["month"] == "February") )
		$year--;
	return $year;
}

/**
 * Returns the current week of the FFL season based on league-invariant control value "MISC_SEASON_START_YYYY"
 *
 * Formerly associated with Game class, but doesn't really need to be there.  Maybe relocate to {@link functions.php}.
 * @return integer Current week of the FFL season
 */
function getCurrentWeek($year)
{
	global $localtest;

	$ctrl = new OFFL_Control();
	$season_start = $ctrl->getValue("MISC_SEASON_START_" . $year);

	@list($date, $time) = explode(" ", $season_start);
	@list($Y, $M, $D) = explode("-", $date);
	@list($h, $i, $s) = explode(":", $time);
	$time = gmmktime($h, $i, $s, $M, $D, $Y);

	$curr_time = time() - $time - (3600*24*7);
	$week = 1;

	while ($curr_time > 0)
	{
		$curr_time -= 3600 * 24 * 7; // one week in seconds
		$week++;
	}
	return $week;
}

function debugPrint($string)
{
	global $localtest;

	if (!$localtest)
		return;

	if (is_array($string))
	{
		foreach($string as $i=>$stringline)
		{
			if (!is_object($stringline))
			{
				$string[$i] = str_replace("<", "&lt;", $string[$i]);
				$string[$i] = str_replace(">", "&gt;", $string[$i]);
			}
		}
		echo "\n\n<pre>";
		var_dump($string);
		echo "</pre>\n\n";
		return;
	}

	$string = str_replace("<", "&lt;", $string);
	$string = str_replace(">", "&gt;", $string);

	echo "\n\n<pre>$string</pre>\n\n";
}

?>

Open in new window

0
 
james130cAuthor Commented:
I must be getting closer.. reading this below suggests there is something telling it that it is in game week 2181.

/**
 * Returns the current week of the FFL season based on league-invariant control value "MISC_SEASON_START_YYYY"
 *
 * Formerly associated with Game class, but doesn't really need to be there.  Maybe relocate to {@link functions.php}.
 * @return integer Current week of the FFL season
 */
function getCurrentWeek($year)
{
      global $localtest;

      $ctrl = new OFFL_Control();
      $season_start = $ctrl->getValue("MISC_SEASON_START_" . $year);

      @list($date, $time) = explode(" ", $season_start);
      @list($Y, $M, $D) = explode("-", $date);
      @list($h, $i, $s) = explode(":", $time);
      $time = gmmktime($h, $i, $s, $M, $D, $Y);

      $curr_time = time() - $time - (3600*24*7);
      $week = 1;

      while ($curr_time > 0)
      {
            $curr_time -= 3600 * 24 * 7; // one week in seconds
            $week++;
      }
      return $week;
}


i have no idea what  league-invariant etc means..
0
 
james130cAuthor Commented:
Found own solution based on my comments information.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now