-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveBPData.php
67 lines (53 loc) · 1.43 KB
/
saveBPData.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once 'assets/config/config.php';
require_once "vendor/autoload.php";
use PhotoTech\Measure;
if (!isset($_SESSION['last_login'])) {
header("Location: gallery.php");
exit();
}
if ($_SESSION['id'] != 2) {
header('Location: gallery.php');
exit();
}
/* Makes it, so we don't have to decode the json coming from javascript */
header('Content-type: application/json');
/*
* Grab per_page and offset
*/
$data = json_decode(file_get_contents('php://input'), true);
try {
$date_added = new DateTime($data['date_taken'], new DateTimeZone("America/Detroit"));
} catch (Exception $e) {
}
$send['date_taken'] = $date_added->format('Y-m-d H:i:s');
$send['systolic'] = (int) $data['systolic'];
$send['diastolic'] = (int) $data['diastolic'];
$send['pulse'] = (int) $data['pulse'];
$send['miles_walked'] = (float) $data['miles_walked'];
$send['weight'] = (int) $data['weight'];
$send['sodium'] = (int) $data['sodium'];
$save = new Measure($send);
$save->create();
output(true);
/*
* Throw error if something is wrong
*/
function errorOutput($output, $code = 500) {
http_response_code($code);
try {
echo json_encode($output, JSON_THROW_ON_ERROR);
} catch (JsonException) {
}
}
/*
* After converting data array to JSON send back to javascript using
* this function.
*/
function output($output) {
http_response_code(200);
try {
echo json_encode($output, JSON_THROW_ON_ERROR);
} catch (JsonException) {
}
}