diff --git a/AppConfig_model.php b/AppConfig_model.php
index 2233d1cf..c4dc2910 100644
--- a/AppConfig_model.php
+++ b/AppConfig_model.php
@@ -22,33 +22,42 @@ public function __construct($mysqli)
{
$this->mysqli = $mysqli;
}
-
+
+ public function checktable(){
+ $sql = 'SHOW TABLES LIKE "app_config"';
+ $result = $this->mysqli->query($sql);
+ if ($result->num_rows>0) return true;
+ return false;
+ }
+
public function set($userid,$json)
{
$userid = (int) $userid;
-
+ //var_dump ($json);
+
$data = json_decode($json);
if (!$data) return array('success'=>false);
-
+
// Input sanitisation
$outdata = array();
+ $filter = "/[^A-Za-z0-9&£€$.,]/";
foreach ($data as $appname=>$properties)
{
- $appname = preg_replace("/[^A-Za-z0-9]/",'',$appname);
-
+ $appname = preg_replace($filter,'',$appname);
+
if (gettype($properties)=="object") {
$outdata[$appname] = array();
foreach ($properties as $property=>$value)
{
- $property = preg_replace("/[^A-Za-z0-9]/",'',$property);
+ $property = preg_replace($filter,'',$property);
if (gettype($value)=="array") {
$tmp = array();
foreach ($value as $val) $tmp[] = (int) $val;
$value = $tmp;
} else {
- $value = preg_replace("/[^A-Za-z0-9,;£$.]/",'',$value);
+ $value = preg_replace($filter,'',$value);
}
-
+
$outdata[$appname][$property] = $value;
}
}
@@ -56,20 +65,20 @@ public function set($userid,$json)
// Re-encode for storage in db text field
$json = json_encode($outdata);
-
+
$result = $this->mysqli->query("SELECT `userid` FROM app_config WHERE `userid`='$userid'");
if ($result->num_rows) {
$this->mysqli->query("UPDATE app_config SET `data`='$json' WHERE `userid`='$userid'");
return true;
-
+
} else {
$this->mysqli->query("INSERT INTO app_config (`userid`,`data`) VALUES ('$userid','$json')");
return true;
}
-
+
return array('success'=>false);
}
-
+
public function get($userid)
{
$userid = (int) $userid;
@@ -79,7 +88,7 @@ public function get($userid)
} else {
return false;
}
-
+
}
}
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..101bdc34
--- /dev/null
+++ b/README.md
@@ -0,0 +1,12 @@
+#App module
+App, is an EMONCMS complementary module made to display technical information on theoretically any type of device. The screen is preformated to show predefined type of feeds.
+
+Example: My electric is able to show the house electrical need, consumption of the day, month, year, with values and graphs.
+
+how to use it:
+copy or clone this repository into the module directory of your EMONCMS installation.
+Visit admin page and update database. This module uses a specific table, not present in previous releases.
+Go to the config page (wrench positionned top right of screen) to configure to your needs
+NB:
+
+rem : A conversion to bootstrap3 and font awesome icons will probably make the presentation more responsive.
diff --git a/app.js b/app.js
index d227df3c..2b06c86f 100644
--- a/app.js
+++ b/app.js
@@ -1,85 +1,131 @@
var app = {
-
- basepath: path+"Modules/app/",
-
+ basepath: path + "Modules/app/",
include: {},
-
loaded: {},
- load: function(appname)
- {
+ load: function (appname) {
app.loaded[appname] = true;
// We load here the html of the app into an dedicated element for that app
// when an app is loaded its html remains in the dom even when viewing another app
// an app is just hidden and shown depending on the visibility settings.
-
+
// we check here if the app has been loaded to the dom, if not we load it
-
- var appdom = $("#app_"+appname);
-
- if (appdom.length) return true;
-
-
- var html = "";
- $.ajax({url: app.basepath+appname+"/"+appname+".html", async: false, cache: false, success: function(data) {html = data;} });
-
- $("#content").append('
');
- $("#app_"+appname).html(html);
+ var dash = "app_" + appname,
+ appdom = $("#" + dash),
+ html = '',
+ include='',
+ file,
+ i;
+
+ if (appdom.length) {return true; }
+ $.ajax({
+ url: app.basepath + appname + "/" + appname + ".html",
+ async: false,
+ cache: false,
+ success: function (data) {html = data; }
+ });
+
+ $("#content").append('');
+ $("#" + dash).html(html);
$.ajax({
- url: app.basepath+appname+"/"+appname+".js",
+ url: app.basepath + appname + "/" + appname + ".js",
dataType: 'script',
async: false
});
-
+ // include the translation file required by asked language
+ // check if answer is 200 or create a blank i18ntext variable
+ $.ajax({
+ url: app.basepath + "locale_js/app_" + 'en' + '.js',
+ dataType: 'script',
+ async: false,
+ error: function () {
+ }
+ });
+ $.ajax({
+ url: app.basepath + "locale_js/app_" + lang + '.js',
+ dataType: 'script',
+ async: false,
+ error: function () {
+ }
+ });
// ----------------------------------------------------------
// Included javascript loader
// ----------------------------------------------------------
- var include = window["app_"+appname].include;
- for (i in include) {
- var file = include[i];
- if (app.include[file]==undefined)
- {
+ include = window[dash].include;
+ for (i = 0; i < include.length; i++) {
+ file = include[i];
+ if (app.include[file] === undefined) {
+ //file = file.replace('%lang%', lang);
app.include[file] = true;
$.ajax({
- url: path+file,
+ url: path + file,
dataType: 'script',
async: false
});
}
}
-
- window["app_"+appname].init();
-
+ window[dash].init();
+ var result= {
+ "ref":{
+ "test":"test"
+ }
+ };
+ // the DOM will be available here
+
+ var flds = document.getElementsByClassName("i18n");
+ var out = '';
+ for(var i=0; i");
+ flds[i].innerHTML= key
+ } else {
+ flds[i].innerHTML= i18ntext[key]
+ }
+ }
+ out = '