forked from sdn4nigeria/monitoring-platform
-
Notifications
You must be signed in to change notification settings - Fork 3
/
coordinates.php
55 lines (50 loc) · 1.84 KB
/
coordinates.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
<?php
// Author: Alberto González Palomo <http://sentido-labs.com>
// ©2013 Alberto González Palomo <http://sentido-labs.com>
// The author grants Stakeholder Democracy Network Ltd.
// a sublicensable, assignable, royalty free, including the rights
// to create and distribute derivative works, non-exclusive license
// to this software.
$backend_root = '../_backend/';
require_once $backend_root.'spill-data.php';
$bin_root = $backend_root.'bin/';
$data_root = '/var/www/data/';
$backup_root = '/var/www/data/backup/';
function pquoted($name)
{
if (array_key_exists($name, $_GET)) {
return '\''.preg_replace('/([\'])/', '\'"\'"\'', $_GET[$name]).'\'';
}
else {
return '\'\'';
}
}
$ok = true;
$exit_code = 0;
file_put_contents('/tmp/coordebug', $bin_root.'coordinates.py 2>&1 --lga='.
$bin_root.'nigeria-lga-reduced.geojson'.
' --output= --google= --json='.
' --latitude='.pquoted("latitude").
' --longitude='.pquoted("longitude").
' --northings='.pquoted("northings").
' --eastings='.pquoted("eastings"));
$last_line = exec($bin_root.'coordinates.py 2>&1 --lga='.
$bin_root.'nigeria-lga-reduced.geojson'.
' --output= --google= --json='.
' --latitude='.pquoted("latitude").
' --longitude='.pquoted("longitude").
' --northings='.pquoted("northings").
' --eastings='.pquoted("eastings"),
$command_output,
$exit_code);
if ($exit_code != 0) $ok = false;
$output = join($command_output, " ");
if ($ok) {
header('Content-type: application/json; charset=UTF-8');
echo $output;
}
else {
header('Content-type: application/json; charset=UTF-8');
echo "{'error':'".htmlspecialchars($output)."'}";
}
?>