105 lines
2.5 KiB
PHP
105 lines
2.5 KiB
PHP
<?php
|
|
|
|
class Vlan {
|
|
private $inDB = false;
|
|
public $id;
|
|
public $trunkid;
|
|
public $flags;
|
|
public $vlannum;
|
|
public $bandwidth;
|
|
public $mac = "00:00:00:00:00:00";
|
|
public $rrdpath;
|
|
public $fullname;
|
|
|
|
private function fromRow($row) {
|
|
$retval = new Vlan();
|
|
if ($row) {
|
|
$retval->inDB = true;
|
|
$retval->id = (int)$row['id'];
|
|
$retval->trunkid = (int)$row['trunkid'];
|
|
$retval->flags = (int)$row['flags'];
|
|
$retval->vlannum = (int)$row['vlannum'];
|
|
$retval->bandwidth = (int)$row['bandwidth'];
|
|
$retval->mac = (string)$row['mac'];
|
|
$retval->rrdpath = (string)$row['rrdpath'];
|
|
$retval->fullname = (string)$row['fullname'];
|
|
}
|
|
return $retval;
|
|
}
|
|
|
|
private function toSql() {
|
|
return "trunkid = '{$this->trunkid}',
|
|
flags = '{$this->flags}',
|
|
vlannum = '{$this->vlannum}',
|
|
bandwidth = '{$this->bandwidth}',
|
|
mac = '".mysql_real_escape_string($this->mac)."'";
|
|
}
|
|
|
|
function load($id) {
|
|
$dbh = Database::getInstance();
|
|
$sql = "SELECT v.id, v.trunkid, v.flags, v.vlannum, v.bandwidth, v.mac,
|
|
IF (v.vlannum = 1,
|
|
CONCAT('bridge-', b.id, '/vlan-', t.name, '.rrd'),
|
|
CONCAT('bridge-', b.id, '/vlan-', t.name, '.', v.vlannum, '.rrd')
|
|
) AS rrdpath,
|
|
IF (v.vlannum = 1,
|
|
CONCAT(b.name, ': ', t.name),
|
|
CONCAT(b.name, ': ', t.name, '.', v.vlannum)
|
|
) AS fullname
|
|
FROM vlan v, trunk t, bridge b
|
|
WHERE v.id = '{$id}'
|
|
AND t.id = v.trunkid
|
|
AND b.id = t.bridgeid";
|
|
|
|
$dbh->query($sql);
|
|
return self::fromRow($dbh->fetch_assoc());
|
|
}
|
|
|
|
function save() {
|
|
$dbh = Database::getInstance();
|
|
|
|
if ($this->inDB) {
|
|
$sql = "UPDATE vlan SET ".$this->toSql()."
|
|
WHERE id = '{$this->id}'";
|
|
$dbh->query($sql);
|
|
|
|
} else {
|
|
$sql = "INSERT vlan SET ".$this->toSql();
|
|
|
|
$dbh->query($sql);
|
|
$this->iNDB = true;
|
|
$this->id = $dbh->insert_id();
|
|
}
|
|
}
|
|
|
|
function delete($id) {
|
|
$dbh = Database::getInstance();
|
|
$sql = "DELETE FROM vlan
|
|
WHERE id = '{$id}'";
|
|
|
|
$dbh->query($sql);
|
|
}
|
|
|
|
function getAll($trunkid = false) {
|
|
$dbh = Database::getInstance();
|
|
|
|
$sql = "SELECT v.id, v.trunkid, v.flags, v.vlannum, v.bandwidth, v.mac,
|
|
CONCAT('bridge-', b.id, '/vlan-', t.name, '.', v.vlannum, '.rrd') as rrdpath,
|
|
CONCAT(t.name, '.', v.vlannum) as fullname
|
|
FROM vlan v, trunk t, bridge b
|
|
WHERE ".($trunkid ? "trunkid = '{$trunkid}'" : "1")."
|
|
AND t.id = v.trunkid
|
|
AND b.id = t.bridgeid
|
|
ORDER BY b.name, t.name, v.vlannum";
|
|
$dbh->query($sql);
|
|
|
|
$retval = array();
|
|
while ($row = $dbh->fetch_assoc())
|
|
$retval[$row['id']] = self::fromRow($row);
|
|
|
|
return $retval;
|
|
}
|
|
}
|
|
|
|
?>
|