-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.php
49 lines (39 loc) · 1.03 KB
/
session.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
<?php
include('lib.php');
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
if($data) {
$evse = aget($data, 'location.id');
$row = db_get(aget($data, 'id'));
if(!$row) {
$insert = [
'start' => db_date(aget($data, 'start_datetime')),
'session' => aget($data, 'id'),
'evse' => intval($evse),
'status' => db_string(aget($data, 'status')),
];
$user = reservation($evse);
if($user) {
$insert['user'] = $user;
}
$row = ['id' => db_insert('sessions', $insert)];
}
$obj = [
'kwh' => floatval(aget($data, 'kwh')),
'status' => db_string(aget($data, 'status'))
];
$user = reservation($evse);
if($user) {
$obj['user'] = intval($user);
}
$cost = aget($data, 'total_cost');
if($cost) {
$obj['cost'] = floatval($cost);
}
$end = aget($data, 'end_datetime');
if($end) {
$obj['end'] = db_date($end);
}
db_update('sessions', $row['id'], $obj);
}
file_put_contents("/tmp/session-info.tmp", date('c') . "|$raw\n", FILE_APPEND);