This repository was archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprocess.php
More file actions
55 lines (46 loc) · 1.46 KB
/
process.php
File metadata and controls
55 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
session_start();
require_once('config.php');
if (empty($_GET['id']) || !in_array($_GET['id'], $participants))
die(json_encode(array(
'status' => 'error',
'msg' => 'Invalid participant!'
)));
if (empty($_POST['token']) || $_POST['token']!==$_SESSION['token'])
die(json_encode(array(
'status' => 'error',
'msg' => 'Invalid token!'
)));
if (empty($_POST['data']))
die(json_encode(array(
'status' => 'error',
'msg' => 'Missing or incorrect data!'
)));
try
{
$json = json_decode($_POST['data']);
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'no ip';
$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'no user agent';
$csv = array();
$csv[] = array(date('c'), $_GET['id'], $ip, $useragent);
for ($i=0;$i<=5;$i++)
$csv[] = array($json->scale[$i], $json->results_rating[$i], $json->results_tally[$i], $json->results_weight[$i]);
$csv[] = array($json->results_overall);
$resultsfile = $results_folder_path . '/nasatlx_'.date('Y-m-d_H-i').'_'.$_GET['id'].'.csv';
$fp = fopen($resultsfile, 'w+');
if (!$fp)
throw new Exception('Could not create file!');
foreach ($csv as $line)
fputcsv($fp, $line, "\t");
fclose($fp);
die(json_encode(array(
'status' => 'success',
'msg' => 'Results saved!'
)));
}
catch (Exception $e) {
die(json_encode(array(
'status' => 'error',
'msg' => 'Something went wrong when saving the results: ' . $e->getMessage()
)));
}