<?php
// Toowoomba City Council Water Monitoring System
// Developed by Sam Moffatt (hide@address.com)
// Pump Data Class
// Defines
define("PUMP_ERROR_IMG", "images/Pump_alarm_s.gif"); // Pump error image
define("PUMP_RUNNING_IMG", "images/pump_run_S.gif"); // Pump run image
define("PUMP_STOPPED_IMG", "images/pump_stop_s.gif"); // Pump stop image
define("PUMP_ERROR", "a4"); // Pump error
define("PUMP_RUNNING", "a1"); // Pump running
define("PUMP_STOPPED", "a0"); // Pump stopped
// Requirements
require_once("functions.php");
class pump {
// Variables
var $pumpid; // The pump id for this class
var $datasource; // Location of the CSV file
var $dbinfo; // Details about the database (array)
var $name; // Pump name (human friendly)
var $shortname; // Pump name (short)
var $data; // Data from CSV
var $top,$left; // Pump HTML position
var $errorurl; // Location to pop up in a new window with fault status information
var $graphurl; // Location to pop up in a new window with a graph
var $error = false; // Error status, boolean
var $errormsg = ""; // Error message, string
// Constructor
function pump($newpumpid, $shortname, $left,$top,$graphurl="", $errorurl="", $newdatasource="http://www.toowoomba.qld.gov.au/eBiz/artis/SCADA2000.CSV", $newdbinfo="") {
$this->dbinfo = Array();
if(is_array($newdbinfo)) {
// New database information
} else {
// Default database
}
if(($newdatasource != "") && (is_string($newdatasource))) {
$this->datasource = $newdatasource;
} else if(is_array($newdatasource)) {
$this->data = $newdatasource;
} else {
// Isn't a string and isn't an array, fall back
$this->datasource = "http://www.toowoomba.qld.gov.au/eBiz/artis/SCADA2000.CSV";
}
if(!isset($this->data)) { $this->data = loadCSV($this->datasource); }
$this->top = $top;
$this->left = $left;
$this->pumpid = $newpumpid;
$this->shortname = $shortname;
$this->graphurl = $graphurl;
$this->errorurl = $errorurl;
}
function getID() {
return $this->pumpid;
}
function getName() {
return "{$this->data[$this->pumpid]['title']} ($this->pumpid)";
}
function getShortName() {
return $this->shortname;
}
function getTimeStamp() {
return $this->data[$this->pumpid]['stamp'];
}
function getStatus() {
switch($this->data[$this->pumpid]['state']) {
case 0:
return "Stopped";
break;
case 1:
return "Running";
break;
default:
return "Alarm";
break;
}
}
function setTop($top) {
$this->top = $top;
}
function setLeft($left) {
$this->left = $left;
}
function getImageSrc() {
switch($this->data[$this->pumpid]['state']) {
case PUMP_RUNNING:
return PUMP_RUNNING_IMG;
break;
case PUMP_STOPPED:
return PUMP_STOPPED_IMG;
break;
default:
return PUMP_ERROR_IMG;
break;
}
}
function setError() {
switch($this->data[$this->pumpid]['state']) {
case PUMP_RUNNING:
$this->error = false;
break;
case PUMP_STOPPED:
$this->error = false;
break;
case PUMP_ERROR:
$this->errormsg = "Pump error detected";
$this->error = true;
default:
$this->errormsg = "Unknown state detected!";
$this->error = true;
break;
}
}
// Return the pump with div
// - Allows position override
function getHTML($left=0,$top=0) {
if($top == 0) {
$top = $this->top;
}
if($left == 0) {
$left = $this->left;
}
?>
<div style="z-index: 2; position: absolute; left: <?php echo $left;?>; top: <?php echo $top;?>;">
<div align="center"><?php echo $this->getShortName(); ?><br><?php echo $this->getTimeStamp(); ?><br>
<?php if($this->graphurl) { ?><a href="<?php echo $this->graphurl ?>" target="_blank">View Graph</a><br><?php } ?>
<?php if($this->error) { ?><a href="<?php echo $this->errorurl ?>" target="_blank">Error Report<br><?php } ?>
<IMG SRC="<?php echo $this->getImageSrc(); ?>" BORDER=0 width="68" height="57" alt="<?php echo $this->errormsg ?>">
<?php if($this->error) { ?></a><?php } ?>
</div>
</div>
<?php
}
}
?>