diff --git a/index.php b/index.php index 3b70036..95cd844 100755 --- a/index.php +++ b/index.php @@ -30,6 +30,18 @@ $variables = array( 'baseURL' => $settings->baseURL ); +//Pull targets from CSV file +if (($handle = fopen('targets.csv', 'r')) === false) { + die('Error opening file'); + } +$headers = fgetcsv($handle, 1024, ','); +$targets = array(); +while ($row = fgetcsv($handle, 1024, ',')) { + $targets[$row[0]] = array_combine($headers, $row); + } +fclose($handle); + + $template = false; $mode = !empty($_GET['mode']) ? $_GET['mode'] : 'start'; $phase = !empty($_GET['phase']) && in_array($_GET['phase'], $settings->phases) ? $_GET['phase'] : false; @@ -97,18 +109,17 @@ switch ($mode) { } //Calculate the score. Compare results with targets in settings.json. - if (($phasevalue['xcoordinate'] >= $settings->elementLocations->{$phasename }->topleft->x) - && ($phasevalue['xcoordinate'] < $settings->elementLocations->{$phasename}->bottomright->x) - && ($phasevalue['ycoordinate'] >= $settings->elementLocations->{$phasename}->topleft->y) - && ($phasevalue['ycoordinate'] < $settings->elementLocations->{$phasename}->bottomright->y)) { + if (($phasevalue['xcoordinate'] >= $targets[$phasename][topleftx]) + && ($phasevalue['xcoordinate'] < $targets[$phasename][bottomrightx]) + && ($phasevalue['ycoordinate'] >= $targets[$phasename][toplefty]) + && ($phasevalue['ycoordinate'] < $targets[$phasename][bottomrighty])) { //Put the correct score in the ready array array_push($ready, '1'); } else { //Put the incorrect score in the ready array array_push($ready, '0'); - } - + } //Building an INSERT query: //Include userid (once collection form is added into the start page) // DB fields are listed here: diff --git a/targets.csv b/targets.csv new file mode 100644 index 0000000..9f2c9ff --- /dev/null +++ b/targets.csv @@ -0,0 +1,6 @@ +phase,topleftx,toplefty,bottomrightx,bottomrighty +1,0,0,10,10 +2,0,0,20,20 +3,0,0,30,30 +4,0,0,40,40 +5,0,0,50,50