/**
  * WRITE_DBASE
  * std module method
  * stores a single sample of all dps to the database, ie one full db row
  * at presnet the datestamp is the time that read_device completes
  * code is 0 for successful sample, or pos int for error condition
  * only code 0 samples are ever read, the others kept to help with device fault finding.
  * 
  * @args  nil 
  * @return (bool) success
  *
  **/
 protected function write_dbase()
 {
     $db = $this->db;
     //prepare periodic query
     $query_insert = $query_insert_day = '';
     if (!$this->code) {
         foreach ($this->datapoints as $label => $datapoint) {
             if (!$datapoint->store) {
                 continue;
             }
             $field = $db->quote($label);
             $value = $db->quote($datapoint->current_value);
             if ($datapoint->interval == 'periodic') {
                 $query_insert .= "`{$field}`= '{$value}',\n";
             }
             if ($datapoint->interval == 'day') {
                 $query_insert_day .= "`{$field}`= '{$value}',\n";
             }
         }
     }
     //write periodic
     if ($this->code or $query_insert) {
         $request = "\n\t\t\t\tinsert into `:table` set\n\t\t\t\t{$query_insert}\n\t\t\t\tcode = ':code', \n\t\t\t\tdate_created= ':dtime'\n\t\t\t";
         $params = array('table' => $this->settings['store_db_table'], 'code' => $this->code, 'dtime' => $this->datetime);
         $db->query($request, $params) or codeerror('DB error', __FILE__, __LINE__);
     }
     //write day, keep overwriting current day til last one stands
     if ($query_insert_day) {
         $day = date("Y-m-d", strtotime($this->datetime));
         $request = "\n\t\t\t\tselect id from `:daytable` \n\t\t\t\twhere date_created= ':day'\n\t\t\t";
         $params = array('daytable' => $this->settings['store_db_table_day'], 'day' => $day);
         $result = $db->query($request, $params) or codeerror('DB error', __FILE__, __LINE__);
         if (!$db->num_rows($result)) {
             $request = "\n\t\t\t\t\tinsert into `:daytable` set\n\t\t\t\t\tdate_created= ':day'\n\t\t\t\t";
             $params = array('daytable' => $this->settings['store_db_table_day'], 'day' => $day);
             $db->query($request, $params) or codeerror('DB error', __FILE__, __LINE__);
         }
         $request = "\n\t\t\t\tupdate `:daytable` set\n\t\t\t\t{$query_insert_day}\n\t\t\t\t`code`= '0'\n\t\t\t\twhere date_created= ':day'\n\t\t\t";
         $params = array('daytable' => $this->settings['store_db_table_day'], 'day' => $day);
         $db->query($request, $params) or codeerror('DB error', __FILE__, __LINE__);
     }
     return true;
 }
示例#2
0
        $head .= "<th><h3>{$panetag}</h3></th>";
        $tbody .= "<td>{$lines}</td>";
    }
    //Display page
    $page->tags['PageTitle'] = 'Setup';
    $page->tags['LeftSidebar'] = "\r\n\t\t<p style='font-style:italic;'>\r\n\t\t\tPlace datapoint and/or graph elements into the View template panes. \r\n\t\t</p>\r\n\t";
    $page->tags['Body'] = "\r\n\t\t<table style='clear:right;margin-bottom:15px' class='wtab'>\r\n\t\t\t<tr>{$head}</tr>\r\n\t\t\t<tr>{$tbody}</tr>\r\n\t\t</table>\r\n\t\t<input type='button' value='Add datapt' onClick=\"document.location.href='setup.php?do=editdatapt&amp;id_view={$id_view}';\"  />\r\n\t\t<input type='button' value='Add graph' onClick=\"document.location.href='setup.php?do=editgraph&amp;id_view={$id_view}';\"  />\r\n\t";
    $page->render();
}
###  VIEWS
###
###############################################
//view listing
$panelines = array();
$query = "\r\n\tselect * from blackboxviews\r\n\torder by id_view\r\n";
$result = $db->query($query) or codeerror('DB error', __FILE__, __LINE__);
$views_insert = '';
while ($row = $db->fetch_row($result)) {
    $id_view = $row['id_view'];
    $views_insert .= "\r\n\t\t<div>\r\n\t\t\tView {$id_view} - \r\n\t\t\t<a href='setup.php?do=config&amp;id_view={$id_view}'>Config</a>\r\n\t\t\t<a href='setup.php?do=delview&amp;id_view={$id_view}'>Del</a>\r\n\t\t</div>\r\n\t";
}
//module listing
$mods_insert = '';
foreach ($modules as $mod => $module) {
    $ndps = count($module->datapoints);
    $mods_insert .= "<div>{$module->name} ({$ndps} dps)</div>";
}
//display page
$page->tags['PageTitle'] = 'Setup';
$page->tags['LeftSidebar'] = "\r\n\t<p style='font-style:italic;'>\r\n\t\tA view is a status visualisation of module data. Add a view, or configure views to edit the view elements.  \r\n\t</p>\r\n";
$page->tags['Body'] = "\r\n\t<table style='width:100%' class='wtab'>\r\n\t\t<tr>\r\n\t\t\t<td style='width:50%'>\r\n\t\t\t\t<h3>Views - <a href='setup.php?do=editview'>Add</a></h3>\r\n\t\t\t\t{$views_insert} \r\n\t\t\t</td>\r\n\t\t\t<td style='width:50%'>\r\n\t\t\t\t<h3>Modules - <a href='setup.php?do=checkdb'>Check db</a></h3>\r\n\t\t\t\t{$mods_insert} \r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t</table>\r\n";
示例#3
0
/** 
 *  INIT.PHP
 *
 *  Holds code common to UI pages. 
 * 
 *  The Blackbox Project
 *  --
 *  @author:   Peter 2013
 *  @license:  GPLv3. 
 *  @revision: $Rev$
 *
 **/
//php set
ini_set('display_errors', 'on');
error_reporting(E_ALL);
//includes
require 'config/config-main.php';
require 'lib/housekeeping.php';
require 'lib/lib-db.php';
require 'lib/lib-form.php';
require 'lib/lib-page.php';
require 'lib/lib-draw.php';
require 'lib/lib-graph.php';
require 'lib/lib-blackbox.php';
//connect to db
$db = new Database($SQL_TYPE);
$db->connect($SQL_HOST, $SQL_USER, $SQL_PASS, $SQL_DB) or codeerror("DB connect failed", __FILE__, __LINE__);
//sanity check sample interval
$SETTINGS['sample_interval'] = (int) $SETTINGS['sample_interval'] >= 1 ? (int) $SETTINGS['sample_interval'] : 1;
$profiler = new Profiler();