Example #1
0
/**     updateData()
 *
 *     load summission data into database  
 *
 **/
function updateData($text)
{
    // get the group names and data identifiers
    include "groupstrings.php";
    // define a database result
    $result = false;
    // default success - thinK positive
    $success = true;
    // resultString to return;
    $resultString = null;
    // data structure descriptors
    $dsType = array('none', 'Hash Table', 'Trie', 'Other');
    // submission data file name
    $inFileName = "../minis/newsubdata.txt";
    // in no submission data then clean up the files
    // and alert the admin
    if (!file_exists($inFileName)) {
        dumpSubmissions(0, 0);
        moveSubmissions();
        return "&nbsp;...no submission data: file \" {$inFileName} \" not found<br />";
    }
    // connect to the data base get handle
    $dbhandle = PDOconnect();
    // define the MySQL statement
    $sql = "REPLACE INTO `leader_board` VALUES(:id, :grp2, :name, :total, :dload,";
    $sql = $sql . " :tcheck, :size, :unload, :mem, :typ)";
    // open submission data file
    $inFileHandle = fopen($inFileName, 'r') or die("can't open file");
    // begin adding data to database
    try {
        // prepare or create sql statement object
        $stmt = $dbhandle->prepare($sql);
        // begin parsing data from submission file one line at a time
        while (($data = fgetcsv($inFileHandle, 1000, ",")) !== FALSE) {
            // if no data exit loop
            if (!$data[0]) {
                break;
            }
            // default type value
            $type = null;
            // extract group and type from $data[0]
            if (!in_array($data[0], $validGrpNum_R, true)) {
                // assign last value in $data[0]
                $type = $data[0][strlen($data[0]) - 1];
                // get group substring
                $data[0] = substr($data[0], 0, strlen($data[0] - 2));
            }
            // get the next id number for this group
            $return = getPut("nextId", $data[0]);
            // if getput nextId result good bind data or throw error
            if (is_array($return)) {
                $stmt->bindParam(":id", $return['nextId']);
            } else {
                $error = 'unable to get id number';
                throw new Exception($error);
            }
            // bind data to object
            $stmt->bindParam(":grp2", $data[0]);
            $stmt->bindParam(":name", $data[1]);
            $stmt->bindParam(":total", $data[2]);
            $stmt->bindParam(":dload", $data[3]);
            $stmt->bindParam(":tcheck", $data[4]);
            $stmt->bindParam(":size", $data[5]);
            $stmt->bindParam(":unload", $data[6]);
            $stmt->bindParam(":mem", $data[7]);
            $stmt->bindParam(":typ", $dsType[$type]);
            // execute the MySQL data addition
            $result = $stmt->execute();
            // output admin data
            if (!$text) {
                $resultString = $resultString . sprintf("adding %04u for group %u name: \" %s \" total time: %04f <br>", $return['nextId'], $data[0], $data[1], $data[2]);
            } else {
                $resultString = $resultString . sprintf("adding %04u for group %u name: \" %s \" total time: %04f \n", $return['nextId'], $data[0], $data[1], $data[2]);
            }
            // build some source and destination strings for moving submission files
            // to a final resting place
            $oldFileName = $data[1] . $data[0] . '-' . $type . 'speller.x';
            $newFileName = $oldFileName . $return['nextId'];
            // move submitter's files to the dump if it exists
            // under certain automation testing methods the file may not exist
            // if submitter is not on the board or the latest submission fails the
            // file well move to the dump and replace any file already there.  The
            // dump contains files on the board or last failure.
            if (file_exists('../uploading/' . $oldFileName)) {
                dumpSubmissions($oldFileName, $newFileName);
            }
        }
    } catch (PDOException $error) {
        // success is not true / echo error message
        $success = false;
        echo 'Leader Board updateData ERROR: ' . $error->getMessage();
    }
    // clean up files and move to dump if no data was uploaded
    unlink($inFileName);
    dumpSubmissions(0, 0);
    moveSubmissions();
    // close database connection if open
    if ($dbhandle) {
        $dbhandle = null;
    }
    // return $resultString on success or false
    if ($success) {
        return $resultString;
    } else {
        return false;
    }
}
Example #2
0
<?php

header("location: /");
exit;
include "../include/helfun.php";
$mySQL_Handle = PDOconnect();
$grp = 6;
$rows = getPut("rows", $grp);
$outFileHandle = fopen('../include/archive2014/rows_0.txt', 'w');
foreach ($rows as $row) {
    $line = $row['name'] . "," . $row['total'] . "," . $row['dload'] . "," . $row['tcheck'] . "," . $row['size'] . "," . $row['unload'] . "," . $row['mem'] . "," . $row['typ'] . "\r\n";
    fwrite($outFileHandle, $line);
}
echo "done";