|
1 |
| -<?php |
2 |
| -session_start(); |
3 |
| -require_once('common/settings.php'); |
4 |
| -require_once('common/utils.php'); |
5 |
| -require_once('common/database.php'); |
6 |
| - |
7 |
| -//Connect to the database |
8 |
| -$dbh = databaseConnect($dbHost, $dbPort, $dbUser, $dbPass, $dbName); |
9 |
| - |
10 |
| -//Create the output array |
11 |
| -$output = array('result' => 0); |
12 |
| -if(!$dbh) { |
13 |
| - //Couldn't connect to the database |
14 |
| - $output['result'] = -100; |
15 |
| -} else { |
16 |
| - //Connected successfully |
17 |
| - if($_REQUEST['action'] == 'forecast' || $_REQUEST['action'] == 'autosave') { |
18 |
| - $output['action'] = $_REQUEST['action']; |
19 |
| - $hash = mysql_real_escape_string($_REQUEST['hash']); |
20 |
| - $temp = array(); |
21 |
| - if(getUserByHash($temp, $hash) == 1) { |
22 |
| - $forecast = array(); |
23 |
| - foreach($_REQUEST['f'] as $f) { |
24 |
| - array_push($forecast, floatval(mysql_real_escape_string($f))); |
25 |
| - } |
26 |
| - if(getEpiweekInfo($temp) == 1) { |
27 |
| - if(count($forecast) >= 1 && count($forecast) <= 53) { |
28 |
| - //Save the forecast |
29 |
| - $regionID = intval(mysql_real_escape_string($_REQUEST['region_id'])); |
30 |
| - $commit = ($_REQUEST['action'] == 'forecast'); |
31 |
| - if(saveForecast($temp, $temp['user_id'], $regionID, $forecast, $commit) == 1) { |
32 |
| - //Success |
33 |
| - $output['result'] = 1; |
34 |
| - } else { |
35 |
| - //Failed to save forecast |
36 |
| - $output['result'] = -5; |
37 |
| - } |
38 |
| - } else { |
39 |
| - //Size of forecast array is wrong |
40 |
| - $output['result'] = -4; |
41 |
| - } |
42 |
| - } else { |
43 |
| - //Failed to get round info |
44 |
| - $output['result'] = -3; |
45 |
| - } |
46 |
| - } else { |
47 |
| - //Invalid user |
48 |
| - $output['result'] = -2; |
49 |
| - } |
50 |
| - } else { |
51 |
| - //Unknown action |
52 |
| - $output['result'] = -1; |
53 |
| - } |
54 |
| -} |
55 |
| -echo json_encode($output); |
56 |
| -?> |
| 1 | +<?php |
| 2 | +session_start(); |
| 3 | +require_once('common/settings.php'); |
| 4 | +require_once('common/utils.php'); |
| 5 | +require_once('common/database.php'); |
| 6 | + |
| 7 | +//Connect to the database |
| 8 | +$dbh = databaseConnect($dbHost, $dbPort, $dbUser, $dbPass, $dbName); |
| 9 | + |
| 10 | +//Create the output array |
| 11 | +$output = array('result' => 0); |
| 12 | +if(!$dbh) { |
| 13 | + //Couldn't connect to the database |
| 14 | + $output['result'] = -100; |
| 15 | +} else { |
| 16 | + //Connected successfully |
| 17 | + if($_REQUEST['action'] == 'forecast' || $_REQUEST['action'] == 'autosave') { |
| 18 | + $output['action'] = $_REQUEST['action']; |
| 19 | + $hash = mysqli_real_escape_string($dbh, $_REQUEST['hash']); |
| 20 | + $temp = array(); |
| 21 | + if(getUserByHash($dbh, $temp, $hash) == 1) { |
| 22 | + $forecast = array(); |
| 23 | + foreach($_REQUEST['f'] as $f) { |
| 24 | + array_push($forecast, floatval(mysqli_real_escape_string($dbh, $f))); |
| 25 | + } |
| 26 | + if(getEpiweekInfo($dbh, $temp) == 1) { |
| 27 | + if(count($forecast) >= 1 && count($forecast) <= 53) { |
| 28 | + //Save the forecast |
| 29 | + $regionID = intval(mysqli_real_escape_string($dbh, $_REQUEST['region_id'])); |
| 30 | + $commit = ($_REQUEST['action'] == 'forecast'); |
| 31 | + if(saveForecast($dbh, $temp, $temp['user_id'], $regionID, $forecast, $commit) == 1) { |
| 32 | + //Success |
| 33 | + $output['result'] = 1; |
| 34 | + } else { |
| 35 | + //Failed to save forecast |
| 36 | + $output['result'] = -5; |
| 37 | + } |
| 38 | + } else { |
| 39 | + //Size of forecast array is wrong |
| 40 | + $output['result'] = -4; |
| 41 | + } |
| 42 | + } else { |
| 43 | + //Failed to get round info |
| 44 | + $output['result'] = -3; |
| 45 | + } |
| 46 | + } else { |
| 47 | + //Invalid user |
| 48 | + $output['result'] = -2; |
| 49 | + } |
| 50 | + } else { |
| 51 | + //Unknown action |
| 52 | + $output['result'] = -1; |
| 53 | + } |
| 54 | +} |
| 55 | +echo json_encode($output); |
| 56 | +?> |
0 commit comments