diff --git a/webstuff/frontend/content/module_sets/set_test.html b/webstuff/frontend/content/module_sets/set_test.html index 19edef1..3ce2893 100644 --- a/webstuff/frontend/content/module_sets/set_test.html +++ b/webstuff/frontend/content/module_sets/set_test.html @@ -1 +1 @@ -{content:addModule:temp_1}{content:addModule:temp_2} +{content:addModule:temp_1}{content:addModule:temp_4} diff --git a/webstuff/frontend/content/modules/mod_temp.html b/webstuff/frontend/content/modules/mod_temp.html index 9afb5ac..0361b6c 100644 --- a/webstuff/frontend/content/modules/mod_temp.html +++ b/webstuff/frontend/content/modules/mod_temp.html @@ -2,22 +2,22 @@

{content:fill:sens_description}

Momentane Werte

- - + + - - + + - - + +
Momentan:{content:fill:temp_now_val}{content:fill:temp_now_date}
Momentan:{content:fill:temp_now_val}°C{content:fill:temp_now_date}
Durchschnitt (halbe std.):{content:fill:temp_av_value} 
Durchschnitt ({content:fill:temp_av_interval} min.):{content:fill:temp_av_value}°C 
Tendenz (2 std.):{content:fill:temp_changing} 
Tendenz (2 std.):{content:fill:temp_changing} 
-

Extrema

+

Extrema

- - + + - - + +
Max:{content:fill:temp_max_val}{content:fill:temp_max_date}
Max:{content:fill:temp_max_val}°C{content:fill:temp_max_date}
Min:{content:fill:temp_min_val}{content:fill:temp_min_date}
Min:{content:fill:temp_min_val}°C{content:fill:temp_min_date}
diff --git a/webstuff/frontend/php_inc/connection.inc.php b/webstuff/frontend/php_inc/connection.inc.php index e69de29..6fab5c7 100644 --- a/webstuff/frontend/php_inc/connection.inc.php +++ b/webstuff/frontend/php_inc/connection.inc.php @@ -0,0 +1,44 @@ +conn = NULL; + } + + function _createConn(){ + if($this->conn == NULL){ + $this->conn = pg_connect("host=141.30.228.39 dbname=wetter user=losinshi") + or die('Verbindungsaufbau fehlgeschlagen: ' . pg_last_error()); + } + } + + function closeConn(){ + if($this->conn != NULL){ + pg_close($this->conn); + $this->conn = NULL; + } + } + + function fetchQueryResultLine($query){ + $this->_createConn(); + $result = pg_query($this->conn, $query) + or die('Abfrage fehlgeschlagen: ' . pg_last_error()); + $array = pg_fetch_assoc($result); + //print_r($array); + return $array; + } + + function fetchQueryResultSet($query){ + $returnArray = array(); + $this->_createConn(); + $result = pg_query($this->conn, $query) + or die('Abfrage fehlgeschlagen: ' . pg_last_error()); + while($array = pg_fetch_assoc($result)) + array_push($returnArray, $array); + return $returnArray; + } + +} +?> diff --git a/webstuff/frontend/php_inc/module.inc.php b/webstuff/frontend/php_inc/module.inc.php index 1bdb566..610d2e1 100644 --- a/webstuff/frontend/php_inc/module.inc.php +++ b/webstuff/frontend/php_inc/module.inc.php @@ -13,37 +13,40 @@ class Module{ var $tempInstance = NULL; /* Temp-Instanz */ - function Module($modName, $sensId, $parser, $connection){ - $this->$sensId = $sensId; - $this->$connection = $connection; + function Module($modName, $sensId, &$parser, &$connection){ + $this->sensId = $sensId; + $this->connection = &$connection; + $this->parserInstance = &$parser; - $parser->parseContent($this->_getModuleFilename("frame"), $this, "top"); - $parser->parseContent($this->_getModuleFilename($modName), $this, NULL); - $parser->parseContent($this->_getModuleFilename("frame"), $this, "bottom"); + + $parser->parseContent($this->_getModuleFilename("frame"), & $this, "top"); + $parser->parseContent($this->_getModuleFilename($modName), & $this, NULL); + $parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom"); } function _getModuleFilename($modName){ return "content/modules/mod_".$modName.".html"; } - function _get_sens(){ - if($sensInstance == NULL) - $this->$sensInstance = new Sensor($this->$sensId, $this->$connection); - return $this->$sensInstance; + function &_get_sens(){ + if($this->sensInstance == NULL) + $this->sensInstance = new Sensor($this->sensId, $this->connection); + return $this->sensInstance; } - function _get_temp(){ - if($tempInstance == NULL) - $this->$tempInstance = new Temp($this->$sensId, $this->$connection); - return $this->$tempInstance; + function &_get_temp(){ + if($this->tempInstance == NULL) + $this->tempInstance = new Temp($this->sensId, $this->connection); + return $this->tempInstance; } function fill($contentId){ $content_split = explode("_", $contentId); - $callObject = call_user_method("_get_".$content_split[0], $this); + $callObject = & call_user_method("_get_".$content_split[0], $this); $funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0])); - echo "\n\naufruf: ".$funcName."()\n\n"; + + return $callObject->$funcName($content_split[1]); } diff --git a/webstuff/frontend/php_inc/module_set.inc.php b/webstuff/frontend/php_inc/module_set.inc.php index 1d07acd..a5ff8b8 100644 --- a/webstuff/frontend/php_inc/module_set.inc.php +++ b/webstuff/frontend/php_inc/module_set.inc.php @@ -1,6 +1,7 @@ _getParserInstance(); /* Parserinstanz holen */ - $parser->parseContent($this->_getSetFilename($setName), $this, NULL); /* Set Parsen */ + $parser = & $this->_getParserInstance(); /* Parserinstanz holen */ + $parser->parseContent($this->_getSetFilename($setName), &$this, NULL); /* Set Parsen */ - echo "\n\n"; $parser->printContent(); } @@ -23,20 +23,22 @@ class ModuleSet{ } /* Parser Instanzieren (wenn noch nicht ist) und zurückgeben */ - function _getParserInstance(){ - if($this->$parserInstance==NULL) - $this->$parserInstance = new Parser(); - return $this->$parserInstance; + function &_getParserInstance(){ + if($this->parserInstance==NULL) + $this->parserInstance = new Parser(); + return $this->parserInstance; } - function _getConnInstance(){ - // TODO: Muss noch Implementiert werden!! - return $connInstance; + function &_getConnInstance(){ + if($connInstance == NULL){ + $this->connInstance = new Connection(); + } + return $this->connInstance; } /* Ein Modul hinzufügen */ function addModule($modName){ - $params = explode("_",$modName); /* Modulname und Sensorid trennen */ + $params = explode("_",$modName); /* Modulname und Sensorid trennen */ new Module($params[0], $params[1], $this->_getParserInstance(), $this->_getConnInstance()); } } diff --git a/webstuff/frontend/php_inc/parser.inc.php b/webstuff/frontend/php_inc/parser.inc.php index e22f932..2822e6d 100644 --- a/webstuff/frontend/php_inc/parser.inc.php +++ b/webstuff/frontend/php_inc/parser.inc.php @@ -1,6 +1,7 @@ contentArray = array(); @@ -14,9 +15,7 @@ class Parser{ function appendContent($newContent){ if(is_array($newContent)){ for($i = 0; $i < count($newContent); $i++){ - echo "adding: ".$newContent[$i]."\n"; array_push($this->contentArray, $newContent[$i]); - echo "added: ".$this->contentArray[count($this->contentArray)-1]."\n"; } } else { array_push($this->contentArray, $newContent); @@ -25,28 +24,24 @@ class Parser{ /* Zeigt den Geparsten Inhalt an */ function printContent(){ - echo "\n ---- Printing ----\n"; - echo ""; - $array = &$this->getContentArray(); + $array = $this->getContentArray(); for ($i = 0; $i < count($array); $i++){ echo $array[$i]; } } - function parseContent($fileName, $callingObject, $filePart=null){ - echo "\n\nparse: ".$fileName."\n\n"; + function parseContent($fileName, & $callingObject, $filePart=null){ $fileArray = file($fileName); /* File als Array einlesen */ if($filePart != null){ $fileArray = $this->_fetchFilePart(&$fileArray, $filePart); /* Wenn File aus mehreren Template-Teilen besteht, dann wird hir der relevante Zeil geholt */ } for($i = 0; $i < count($fileArray); $i++){ /* Das Array durchlaufen ... */ - echo "Zeile: ".$i." = ".$fileArray[$i]."\n"; if(0 != preg_match_all("/\{content:([a-z]+):([a-z0-9_]+)\}/i", $fileArray[$i], $results)){ //print_r($results); for($j = 0; $j < count($results[1]); $j++){ - $callingObject->$results[1][$j]($results[2][$j]); - //$fileArray[$i] = preg_replace("/\{content:fill:".$results[1][$j]."\}/i", $fileContents[$results[1][$j]], $fileArray[$i]); + $insert = $callingObject->$results[1][$j]($results[2][$j]); + $fileArray[$i] = preg_replace("/\{content:".$results[1][$j].":".$results[2][$j]."\}/i", $insert, $fileArray[$i]); } } }