forked from emoncms/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_controller.php
55 lines (42 loc) · 1.77 KB
/
app_controller.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
<?php
// no direct access
defined('EMONCMS_EXEC') or die('Restricted access');
function app_controller()
{
global $session,$route,$mysqli;
$result = false;
include "Modules/app/AppConfig_model.php";
$appconfig = new AppConfig($mysqli);
if ($route->action == "") {
$route->format = "html";
$result = view("Modules/app/client.php",array());
} else {
$route->format = "json";
if ($route->action == "setconfig" && $session['write'])
$result = $appconfig->set($session['userid'],get('data'));
if ($route->action == "getconfig" && $session['read'])
$result = $appconfig->get($session['userid']);
if ($route->action == "dataremote")
{
$id = (int) get("id");
$start = (float) get("start");
$end = (float) get("end");
$interval = (int) get("interval");
$result = json_decode(file_get_contents("http://emoncms.org/feed/data.json?id=$id&start=$start&end=$end&interval=$interval&skipmissing=0&limitinterval=0"));
}
if ($route->action == "valueremote")
{
$id = (int) get("id");
$result = (float) json_decode(file_get_contents("http://emoncms.org/feed/value.json?id=$id"));
$route->format = "text/plain";
}
if ($route->action == "ukgridremote")
{
$start = (float) get("start");
$end = (float) get("end");
$interval = (int) get("interval");
$result = json_decode(file_get_contents("https://openenergymonitor.org/ukgrid/api.php?q=data&id=1&start=$start&end=$end&interval=$interval"));
}
}
return array('content'=>$result, 'fullwidth'=>false);
}