I have a script called buildtickerfilesXML.php. This script needs to be
accessed in two different ways.
I need to be able to call this script with 1 GET parameter
and call the function called buildall passing the parameter
I am setting a define called fromstoregame and, if it is
set, it does this. It will be called from an anchor on one
page like this:
{This script, called storegame, gets POST data and one of the POST
variables needs to be sent to the buildtickerfilesXML script}
<? define('fromstoregame', TRUE); ?>
<form name="ticker"
action="buildtickerfilesXML.php?week=<? date('W')?>&game=<?$_POST["gamenum"]?>"
method="post">
<input type="submit" name="Submit" value="Build Ticker Files">
</form>
I need to be able to call the buildall function directly
from another script called mgrstoregame, like this: buildall($game);
I am not setting the fromstoregame define in the mgrstoregame script.
Here is how it looks, irrelavent code is <snipped>. The problem lies
in the fact that sometimes the buildall function is not being called
from mgrstoregame, whereas the buildall is always being hit from the
storegame script. Any ideas as to how this can be accomplished easier?
<?php
$wk = 0;
$useSimpleXML = true;
if (!defined('fromstoregame')) {
buildall($_POST['game']);
define('fromstoregame', FALSE);
}
function buildall($game) {
global $wk;
global $useSimpleXML;
global $xml;
if ($useSimpleXML) {
$xmlstr = '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><data></data>';
$xml = new SimpleXMLElement( $xmlstr );
}
// this is to be able to create the results from the last week
if (isset($_POST["LW"])) {
$wk = $_POST["week"] - 1;
} else {
$wk = $_POST["week"];
}
define ("NL", "\n");
include("dbconnectionstuff.inc");
$db = new dbstuff;
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
$sql = $sql.'select WEEK(gamedate) from games WHERE gamenum = '.$game;
$result = $db->query($sql);
if ($db->num_rows($result) > 0) {
list($wk)=$db->fetch_row($result);
}
if (!$useSimpleXML) {
$fp = fopen("gamedata.xml", "w");
$hdr = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>\n\t<data>\n";
fwrite($fp, $hdr);
fclose($fp);
}
buildit($db, "AA", $wk);
buildit($db, "C", $wk);
buildit($db, "N", $wk);
buildit($db, "A", $wk);
buildit($db, "BR", $wk);
if (!$useSimpleXML) {
$fp = fopen("gamedata.xml", "a");
fwrite($fp, "\n\t</data>");
fclose($fp);
}
}
function buildit($db, $div, $wk) {
<code snipped>
}
?>