From f3e532e591067eaa371632b5fc4d36081b5e31e9 Mon Sep 17 00:00:00 2001
From: Philip <mail@philjak.de>
Date: Fri, 15 Jul 2016 11:18:38 +0200
Subject: [PATCH] =?UTF-8?q?Config=20=C3=84nderungen=20SQL=20Klasse=20mit?=
 =?UTF-8?q?=20Parameter?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 web/admin.php          |  5 +++--
 web/api/lastUpdate.php |  5 ++---
 web/classes/SQL.php    | 10 +++-------
 web/details.php        |  5 +++--
 web/graph.php          |  5 +++--
 web/include/config.php | 20 ++++++++++++++------
 web/index.php          |  5 +++--
 7 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/web/admin.php b/web/admin.php
index f352ec1..1a7037d 100644
--- a/web/admin.php
+++ b/web/admin.php
@@ -1,8 +1,9 @@
 <?php
 session_start();
+include("include/config.php");
 require_once("classes/SQL.php");
 include("include/_head.php");
-include("include/config.php");
+
 
 $loggedIn = false;
 $loginFailed = true;
@@ -49,7 +50,7 @@ if (!$loggedIn){
 	</form>
 ';
 }else{
-	$sql = new SQL();
+	$sql = new SQL($DBHOST, $DBUSER, $DBPASS, $DBNAME);
 	$link = $sql->getLink();
 	$exist = false;
 
diff --git a/web/api/lastUpdate.php b/web/api/lastUpdate.php
index 5d9296a..8468caf 100644
--- a/web/api/lastUpdate.php
+++ b/web/api/lastUpdate.php
@@ -2,11 +2,10 @@
 
 
 if (isset($_POST["param"])){
-
-require_once("../classes/SQL.php");
 include("../include/config.php");
+require_once("../classes/SQL.php");
 
-	$sql = new SQL();
+	$sql = new SQL($DBHOST, $DBUSER, $DBPASS, $DBNAME);
 	$link = $sql->getLink();
 
 	$query = "SELECT ".$TBL_DATA.".id as id, ".$TBL_PARAMETER.".param as param, ".$TBL_DATA.".value as value, DATE_FORMAT(".$TBL_DATA.".timestamp, '%d.%m.%Y %H:%i:%s') as date FROM (".$TBL_REGISTER." INNER JOIN ".$TBL_PARAMETER." ON ".$TBL_REGISTER.".id = ".$TBL_PARAMETER.".fid_register) INNER JOIN ".$TBL_DATA." ON ".$TBL_PARAMETER.".id = ".$TBL_DATA.".fid_parameter WHERE ".$TBL_DATA.".fid_parameter = ".$_POST["param"]." ORDER BY ".$TBL_DATA.".id DESC LIMIT 1";
diff --git a/web/classes/SQL.php b/web/classes/SQL.php
index f34cc85..4affd4b 100644
--- a/web/classes/SQL.php
+++ b/web/classes/SQL.php
@@ -1,15 +1,11 @@
 <?php
-
+	
 class SQL{
 
 	private $link;
-	private $dbHost = "localhost";
-	private $dbUser = "root";
-	private $dbPass = "";
-	private $dbName = "iot";
 
-	function __construct(){
-		$this->link = new mysqli($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName);
+	function __construct($dbHost, $dbUser, $dbPass, $dbName){
+		$this->link = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
 		$this->link->set_charset("utf8");
 	}
 
diff --git a/web/details.php b/web/details.php
index d30f56a..f039d44 100644
--- a/web/details.php
+++ b/web/details.php
@@ -1,11 +1,12 @@
 <?php
+include("include/config.php");
 require_once("classes/SQL.php");
 include("include/_head.php");
-include("include/config.php");
+
 ?>
 
 <?php
-$sql = new SQL();
+$sql = new SQL($DBHOST, $DBUSER, $DBPASS, $DBNAME);
 $link = $sql->getLink();
 
 if (isset($_GET["param"])){
diff --git a/web/graph.php b/web/graph.php
index 384738f..afa18d5 100644
--- a/web/graph.php
+++ b/web/graph.php
@@ -1,8 +1,9 @@
 <?php // content="text/plain; charset=utf-8"
+require_once ('include/config.php');
 require_once ('classes/jpgraph/jpgraph.php');
 require_once ('classes/jpgraph/jpgraph_line.php');
 require_once ('classes/SQL.php');
-require_once ('include/config.php');
+
 
 if (isset($_GET["param"])){
 	if (isset($_GET["details"]) && $_GET["details"] == "yes"){
@@ -11,7 +12,7 @@ if (isset($_GET["param"])){
 		$showDetails = false;
 	}
 
-		$sql = new SQL();
+		$sql = new SQL($DBHOST, $DBUSER, $DBPASS, $DBNAME);
 		$link = $sql->getLink();
 
 		$dataY = array();
diff --git a/web/include/config.php b/web/include/config.php
index 858bd96..5a3c658 100644
--- a/web/include/config.php
+++ b/web/include/config.php
@@ -1,19 +1,26 @@
 <?php
 
+// Database
 $TBL_PARAMETER = "tbl_parameter";
 $TBL_REGISTER = "tbl_register";
 $TBL_DATA = "tbl_data";
 $TBL_ADDRESSES = "tbl_addresses";
 $TBL_UNREGISTERED = "tbl_unregistered";
+$DBHOST = "localhost";
+$DBUSER = "root";
+$DBPASS = "";
+$DBNAME = "iot";
 
-$GRAPHPOINTS = -50;
-$THUMBSIZE = 4; // 1 min, 12 max
-$TABLELINESPERPAGE = 50;
+// Dashboard
+$DEVICEOFFLINETIME =  24; // Nach X Stunden Inaktivität vom Dashboard entfernen
+$REFRESHINTERVAL = 25; // Alle X Sekunden Daten im Dashboard neu laden
+$THUMBSIZE = 4; // Größe der Vorschaubilder - 1 min, 12 max
 
-// Wenn letzte Nachricht älter als X Stunden, wird das Gerät aus dem Dashboard entfernt
-$DEVICEOFFLINETIME =  24;
+// Graphs
+$GRAPHPOINTS = 50; // Anzahl der X letzten Messungen im Graphen
 
-$REFRESHINTERVAL = 25;
+// Details
+$TABLELINESPERPAGE = 50; // Anzahl der Tabelleneinträge pro Seite
 
 
 
@@ -21,4 +28,5 @@ $REFRESHINTERVAL = 25;
 
 $DEVICEOFFLINETIME = $DEVICEOFFLINETIME * 60;
 $REFRESHINTERVAL = $REFRESHINTERVAL * 1000;
+$GRAPHPOINTS = $GRAPHPOINTS * (-1);
 ?>
\ No newline at end of file
diff --git a/web/index.php b/web/index.php
index 5242738..02f7fea 100755
--- a/web/index.php
+++ b/web/index.php
@@ -1,7 +1,8 @@
 <?php
+include("include/config.php");
 require_once("classes/SQL.php");
 include("include/_head.php");
-include("include/config.php");
+
 ?>
 
 <!-- Page Header -->
@@ -13,7 +14,7 @@ include("include/config.php");
         </div>
 
 <?php
-$sql = new SQL();
+$sql = new SQL($DBHOST, $DBUSER, $DBPASS, $DBNAME);
 $link = $sql->getLink();
 $graphs = array();
 
-- 
GitLab