Use functions
All checks were successful
Web/tracks/pipeline/head This commit looks good

This commit is contained in:
Julien Cabillot 2020-04-17 16:48:33 -04:00
parent 0685a316e8
commit 707741aa4c

View File

@ -1,22 +1,13 @@
<?php
# Obtain the JSON payload from an OwnTracks app POSTed via HTTP
# and insert into database table.
header("Content-type: application/json");
header('Content-type: application/json');
$payload = file_get_contents("php://input");
$data = @json_decode($payload, true);
define('DB_DIR', getenv('DB_DIR'));
if ($data['_type'] == 'location') {
file_put_contents('toto', serialize($data));
$db_dir = getenv('DB_DIR');
# TODO: pour plus tard afin de dynamiser le nom
$db_path = $db_dir.'/db.db';
function store_sqlite3($data) {
$db_path = DB_DIR.'/location-'.date('Y-m').'.db';
$db = new SQLite3($db_path);
# TODO: à commenter quand ready
# TODO: fixer type (https://owntracks.org/booklet/tech/json/)
$db->exec('
CREATE TABLE IF NOT EXISTS history(
tst INTEGER PRIMARY KEY,
@ -47,8 +38,18 @@ if ($data['_type'] == 'location') {
$res = $stm->execute();
}
$response = array();
# optionally add objects to return to the app (e.g.
# friends or cards)
print json_encode($response);
function store_raw($data) {
$db_path = DB_DIR.'/location-'.date('Y-m').'.raw';
file_put_contents('toto', serialize($data));
}
$payload = file_get_contents("php://input");
$data = @json_decode($payload, true);
if ('location' == $data['_type']) {
store_raw($data);
store_sqlite3($data);
}
print json_encode([]);
?>