Properly handles users asking for non-existent UUIDs

pull/73/head
jonsowman 2010-06-06 10:21:44 +01:00
rodzic 7c80b0aa05
commit b05394e628
4 zmienionych plików z 29 dodań i 12 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
<?php
require_once("includes/functions.inc.php");
require_once("includes/config.inc.php");
$action = $_GET['action'];
@ -8,7 +9,9 @@ $software_available = array("gfs", "gfs_hd");
switch($action) {
case "getCSV":
$uuid = $_GET['uuid'];
$fh = fopen("preds/".$uuid."/flight_path.csv", "r") or die("No CSV for UUID");
$tryfile = $c_preds_path.$uuid."/".$c_flight_csv;
if(!file_exists($tryfile)) return false;
$fh = fopen($tryfile, "r");
$data = array();
while (!feof($fh)) {
$line = trim(fgets($fh));
@ -20,7 +23,7 @@ case "getCSV":
case "JSONexists":
$uuid = $_GET['uuid'];
if(file_exists("preds/$uuid/progress.json")) {
if(file_exists($c_preds_path.$uuid."/".$c_progress_json)) {
echo true;
} else {
echo false;
@ -32,11 +35,11 @@ case "getModelByUUID":
if( !uuid ) die ("No uuid given to getModelByUUID");
// make a new model
$pred_model = array();
if ( !file_exists("preds/".$uuid."/scenario.ini") ) {
if ( !file_exists($c_preds_path.$uuid."/".$c_scenario_file) ) {
$pred_model['valid'] = false;
} else {
// populate the array, JSON encode it and return
$pred_model = parse_ini_file("preds/".$uuid."/scenario.ini");
$pred_model = parse_ini_file($c_preds_path.$uuid."/".$c_scenario_file);
if ( verifyModel($pred_model, $software_available) ){
$pred_model['valid'] == true;
} else {

Wyświetl plik

@ -34,7 +34,6 @@ a { text-decoration: underline; color: #333; cursor: pointer; }
left: 50%;
top: 50%;
width: 400px;
height: 50px;
margin-left: -200px;
margin-top: -50px;
padding: 1em;

Wyświetl plik

@ -0,0 +1,9 @@
<?php
$c_preds_path = "preds/";
$c_scenario_file = "scenario.ini";
$c_flight_csv = "flight_path.csv";
$c_progress_json = "progress.json";
?>

Wyświetl plik

@ -73,13 +73,19 @@ function handlePred(pred_uuid) {
function getCSV(pred_uuid) {
$.get("ajax.php", { "action":"getCSV", "uuid":pred_uuid }, function(data) {
appendDebug("Got JSON response from server for flight path, parsing...");
if (parseCSV(data) ) {
appendDebug("Parsing function returned successfully.");
appendDebug("Done, AJAX functions quitting.");
} else {
appendDebug("The parsing function failed.");
}
if(data != null) {
appendDebug("Got JSON response from server for flight path, parsing...");
if (parseCSV(data) ) {
appendDebug("Parsing function returned successfully.");
appendDebug("Done, AJAX functions quitting.");
} else {
appendDebug("The parsing function failed.");
}
} else {
appendDebug("Server couldn't find a CSV for that UUID");
throwError("Sorry, we couldn't find the data for that UUID. "+
"Please run another prediction.");
}
}, 'json');
}