-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhs_table.php
50 lines (35 loc) · 1 KB
/
hs_table.php
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
<?php
require_once 'assets/config/config.php';
require_once "vendor/autoload.php";
use Miniature\Trivia;
$trivia = new Trivia();
$todays_data = new \DateTime("now", new \DateTimeZone("America/Detroit"));
/* Makes it so we don't have to decode the json coming from javascript */
header('Content-type: application/json');
/*
* The below must be used in order for the json to be decoded properly.
*/
$data = json_decode(file_get_contents('php://input'), true);
$data['day_of_year'] = $todays_data->format('z');
$result = $trivia->insertHighScores($data);
if ($result) {
output(true);
}
/*
* Throw error if something is wrong
*/
function errorOutput($output, $code = 500) {
http_response_code($code);
echo json_encode($output);
}
/*
* If everything validates OK then send success message to Ajax / JavaScript
*/
/*
* After converting data array to JSON send back to javascript using
* this function.
*/
function output($output) {
http_response_code(200);
echo json_encode($output);
}