This repository has been archived by the owner on Mar 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ewatcher_controller.php
74 lines (69 loc) · 2.27 KB
/
ewatcher_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// No direct access
defined("EMONCMS_EXEC") or die("Restricted access");
// eWatcher controller
function ewatcher_controller()
{
// Global variables
global $session,$route,$mysqli,$path;
// Return if not logged in
if (!$session['write']) {
return array('content'=>false);
}
// Output for the call
$result = false;
// Configuration model
require_once("Modules/ewatcher/EWatcherConfig_model.php");
$ewatcherconfig = new EWatcherConfig($mysqli, $session["userid"]);
// View petition
if ($route->format == "html")
{
// Split into actions
$active = false;
for($i = 1; (($i <= $ewatcherconfig->numPanels) && ($active === false)); $i++) {
$panel = "P" . $i;
if((($route->action == $panel) && ($ewatcherconfig->panels[$panel])) || (($route->action == "") && ($ewatcherconfig->panels[$panel]))) {
$active = true;
require_once("Modules/ewatcher/panels/_EWatcherPanel.php");
require_once("Modules/ewatcher/panels/" . $panel . ".php");
$className = "EWatcher" . $panel;
$panelObject = new $className((int)$session['userid'], $mysqli, $path, $ewatcherconfig);
// Start capturing echo's
ob_start();
// Render panel
$panelObject->view();
// Get echo's
$result = ob_get_contents();
ob_end_clean();
}
}
if($active === false) {
// Start capturing echo's
ob_start();
// Render panel
require_once("Modules/ewatcher/panels/_default.php");
// Get echo's
$result = ob_get_contents();
ob_end_clean();
}
}
// Get/Set settings petition
else if ($route->format == "json")
{
// Cost out
if (($route->action == "setcout") && ($session["write"])) {
$result = $ewatcherconfig->setcout(get("cout"));
}
// Cost in
else if (($route->action == "setcin") && ($session["write"])) {
$result = $ewatcherconfig->setcin(get("cin"));
}
// Units
else if (($route->action == "setunits") && ($session["write"])) {
$result = $ewatcherconfig->setunits(get("units"));
}
}
// Return content
return array("content"=>$result, "fullwidth"=>true);
}
?>