91 lines
1.7 KiB
PHP
91 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
class Forward {
|
||
|
private $inDB = false;
|
||
|
public $id;
|
||
|
public $flags;
|
||
|
public $portlo = 0;
|
||
|
public $porthi = 0;
|
||
|
public $name;
|
||
|
|
||
|
private function fromRow($row) {
|
||
|
$retval = new Forward();
|
||
|
if ($row) {
|
||
|
$retval->inDB = true;
|
||
|
$retval->id = (int)$row['id'];
|
||
|
$retval->flags = (int)$row['flags'];
|
||
|
$retval->portlo = (int)$row['portlo'];
|
||
|
$retval->porthi = (int)$row['porthi'];
|
||
|
$retval->name = (string)$row['name'];
|
||
|
}
|
||
|
return $retval;
|
||
|
}
|
||
|
|
||
|
private function toSql() {
|
||
|
return "flags = '{$this->flags}',
|
||
|
portlo = '{$this->portlo}',
|
||
|
porthi = '{$this->porthi}',
|
||
|
name = '".mysql_real_escape_string($this->name)."'";
|
||
|
}
|
||
|
|
||
|
function load($id) {
|
||
|
$dbh = Database::getInstance();
|
||
|
$sql = "SELECT id, flags, portlo, porthi, name
|
||
|
FROM forward
|
||
|
WHERE id = '{$id}'";
|
||
|
|
||
|
$dbh->query($sql);
|
||
|
return self::fromRow($dbh->fetch_assoc());
|
||
|
}
|
||
|
|
||
|
function save() {
|
||
|
$dbh = Database::getInstance();
|
||
|
|
||
|
if ($this->inDB) {
|
||
|
$sql = "UPDATE forward SET ".$this->toSql()."
|
||
|
WHERE id = '{$this->id}'";
|
||
|
$dbh->query($sql);
|
||
|
|
||
|
} else {
|
||
|
$sql = "INSERT forward SET ".$this->toSql();
|
||
|
|
||
|
$dbh->query($sql);
|
||
|
$this->iNDB = true;
|
||
|
$this->id = $dbh->insert_id();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function delete($id) {
|
||
|
$dbh = Database::getInstance();
|
||
|
$sql = "DELETE FROM forward
|
||
|
WHERE id = '{$id}'";
|
||
|
|
||
|
$dbh->query($sql);
|
||
|
}
|
||
|
|
||
|
function getAll() {
|
||
|
$dbh = Database::getInstance();
|
||
|
|
||
|
$sql = "SELECT id, flags, portlo, porthi, name
|
||
|
FROM forward
|
||
|
ORDER BY portlo, porthi";
|
||
|
$dbh->query($sql);
|
||
|
|
||
|
$retval = array();
|
||
|
while ($row = $dbh->fetch_assoc())
|
||
|
$retval[$row['id']] = self::fromRow($row);
|
||
|
|
||
|
return $retval;
|
||
|
}
|
||
|
|
||
|
function toggle() {
|
||
|
$this->flags ^= 0x01;
|
||
|
}
|
||
|
|
||
|
function isActive() {
|
||
|
return ($this->flags & 0x01);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|