bcast-bridge/web/include/db_Hlsw.class.php

93 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2006-12-11 21:36:44 +01:00
<?php
class Hlsw {
private $inDB = false;
public $id;
public $vlanid;
public $flags;
public $ip = "0.0.0.0";
public $name;
2006-12-22 00:06:05 +01:00
public $rrdpath;
2006-12-11 21:36:44 +01:00
private function fromRow($row) {
$retval = new Hlsw();
if ($row) {
$retval->inDB = true;
$retval->id = (int)$row['id'];
$retval->vlanid = (int)$row['vlanid'];
$retval->flags = (int)$row['flags'];
$retval->ip = (string)$row['ip'];
$retval->name = (string)$row['name'];
2006-12-22 00:06:05 +01:00
$retval->rrdpath = (string)$row['rrdpath'];
2006-12-11 21:36:44 +01:00
}
return $retval;
}
private function toSql() {
return "vlanid = '{$this->vlanid}',
flags = '{$this->flags}',
ip = INET_ATON('".mysql_real_escape_string($this->ip)."'),
name = '".mysql_real_escape_string($this->name)."'";
}
function load($id) {
$dbh = Database::getInstance();
2006-12-22 00:06:05 +01:00
$sql = "SELECT h.id, h.vlanid, h.flags, INET_NTOA(h.ip) AS ip, h.name,
CONCAT('bridge-', b.id, '/hlsw-', h.id, '.rrd') AS rrdpath
FROM hlsw h, vlan v, trunk t, bridge b
WHERE h.id = '{$id}'
AND v.id = h.vlanid
AND t.id = v.trunkid
AND b.id = t.bridgeid";
2006-12-11 21:36:44 +01:00
$dbh->query($sql);
return self::fromRow($dbh->fetch_assoc());
}
function save() {
$dbh = Database::getInstance();
if ($this->inDB) {
$sql = "UPDATE hlsw SET ".$this->toSql()."
WHERE id = '{$this->id}'";
$dbh->query($sql);
} else {
$sql = "INSERT hlsw SET ".$this->toSql();
$dbh->query($sql);
$this->iNDB = true;
$this->id = $dbh->insert_id();
}
}
function delete($id) {
$dbh = Database::getInstance();
$sql = "DELETE FROM hlsw
WHERE id = '{$id}'";
$dbh->query($sql);
}
function getAll() {
$dbh = Database::getInstance();
2006-12-22 00:06:05 +01:00
$sql = "SELECT h.id, h.vlanid, h.flags, INET_NTOA(h.ip) AS ip, h.name,
CONCAT('bridge-', b.id, '/hlsw-', h.id, '.rrd') AS rrdpath
FROM hlsw h, vlan v, trunk t, bridge b
WHERE v.id = h.vlanid
AND t.id = v.trunkid
AND b.id = t.bridgeid
ORDER BY h.ip";
2006-12-11 21:36:44 +01:00
$dbh->query($sql);
$retval = array();
while ($row = $dbh->fetch_assoc())
$retval[$row['id']] = self::fromRow($row);
return $retval;
}
}
?>