<?
/*
HandicappingOS, Open Source Handicapping Solutions
http://www.handicappingOS
Copyright (c) 2005 Richard Rosa
Released under the GNU General Public License
*/
// replace this with the name of the file you want to parse.
$fileToGrab = get_var_from_getpost("fileToGrab");
//echo "file = " . $fileToGrab;
switch ($subaction) {
case 'getFile':
getFile ($fileToGrab);
break;
case 'terms':
default:
listNewFiles ();
break;
}
function listNewFiles () {
echo "<table>";
$uploadDir = _UPLOAD_DIR;
if ($handle = opendir($uploadDir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$fullpath = $uploadDir.$file;
if (!(checkFile($file))) {
echo "<tr><td><b><a href='$fullpath'>$file</a></b></td>";
echo "<td> <a href='#' onClick=\"if(confirm('Are you sure you wish to delete this file?')) {
window.open('filedelete.php?path=<? echo $fullpath; ?>','UploadFile','top=30,left=30,width=350,height=150');return
true; } else { return false; }\">Delete</a>";
echo "
</td>
<td> <a href=\"" . _URL_PATH . "index.php?action=getFiles&fileToGrab=" . $file . "&subaction=getFile\">Process File</a>
</td>
</tr>";
}
}
}
closedir($handle);
}
echo "</table>";
}
function getFile ($fileToGrab) {
if (!($fileToGrab)) {
echo "<br>Error!! I don't have a file to Grab";
}
elseif (!(checkFile($fileToGrab))) {
$datafile = getURL(_UPLOAD_DIR . $fileToGrab);
$pparray = explode("\n",$datafile);
//echo "<br>Size = " . sizeof($pparray);
for ($i=0; $i<sizeof($pparray); $i++) {
//echo "<br>Line #$i<br>";
if ($pparray[$i]) { // is it an empty line?
$ppline = explode(",", $pparray[$i]);
$parsed_lines[] = parse_line($ppline, $raceToParse);
}
}
//show_array($parsed_lines);
$i = 0;
// get the parsed_lines array and seperate it by race
/*while ($parsed_lines[$i]['raceNum'] == 1) {
$raceData[0][] = $parsed_lines[$i];
$i++;
}
display_top($raceData[0][0]);
horse_summary($raceData[0]);
*/
//$debug = 1;
$j = 1;
for ($i=0; $i<sizeof($parsed_lines); $i++) {
//echo "<br>race = " . $parsed_lines[$i]['raceNum'];
if ($parsed_lines[$i]['raceNum'] == $j) {
echo "<br>Addding Race = $j";
$myrace = new race();
$myrace->init_race($parsed_lines[$i]);
$raceID = $myrace->save_race();
$doneRaces[] = $raceID;
echo " " . $myrace->track . " " . $myrace->raceDate . " " . $myrace->raceNum . " " . ($myrace->distanceYards/220)
. " " . $myrace->surface;
$j++;
}
// stuff to save each entry in stages
$myEntry = new entry(); // get a pointer to the entry class
$myEntry->init_entry($parsed_lines[$i], $raceID); // init the entry with the parsed line of data
$myEntry->save_entry(); // save to the entry table
$myEntry->save_workouts(); // save workouts
$myEntry->save_pps(); // save all the pp data
$myEntry->save_trainerStats();
$myEntry->save_jockeyStats();
//$calcs = doPPCalcs($rsPPs->fields, $rsEntry->fields['entryID']);
//$pctEarly = ($calcs['pctEarly']*1000) - 520;
$rsPP = $myEntry->get_pps();
while (!$rsPP->EOF) {
$ppID = $rsPP->fields['ppID'];
$myEntry->save_calcs($calcs['med'], $calcs['te'], $ppID);
$rsPP->MoveNext();
}
//$myEntry->load_entry();
}
insertUploadedFile($fileToGrab, '2005'); // un-hardcode this.....
}
else {
echo "<br>Error: We processed that file already.";
}
}
function insertUploadedFile($fileToGrab, $year) {
// replace this with a check on the file in the database
global $conn, $debug;
$sql = " insert into files
(filename, year)
values (" . $conn->qstr($fileToGrab) . ", " . $conn->qstr($year) . ")";
//echo $sql;
$recordSet = execute_sql($sql);
//show_array($recordSet->fields);
//show_array($recordSet);
if ($recordSet->RowCount() > 0) {
return $recordSet->RowCount();
}
else {
return;
}
}
function checkFile($fileToGrab) {
// replace this with a check on the file in the database
global $conn, $debug;
$sql = "SELECT fileID
FROM files
WHERE filename = " . $conn->qstr($fileToGrab);
//echo $sql;
$recordSet = execute_sql($sql);
//show_array($recordSet->fields);
//show_array($recordSet);
if ($recordSet->RowCount() > 0) {
return $recordSet->RowCount();
}
else {
return;
}
}
function displayFiles($recordSet) {
global $conn, $debug;
while (!$recordSet->EOF) {
list($fileID, $fileName, $fileYear) = $recordSet->fields;
echo "<br>" . $fileID . " - " . $fileName;
$recordSet->MoveNext();
}
}
function listFiles() {
// replace this with a check on the file in the database
global $conn, $debug;
$sql = "SELECT fileID, name, year
FROM files";
//echo $sql;
$recordSet = execute_sql($sql);
//show_array($recordSet->fields);
//show_array($recordSet);
return $recordSet;
}