. For more information, visit http://sourceforge.net/projects/ipreg, or contact me at wietsew@users.sourceforge.net *****************************************************************************/ class Db { protected $dblink; public function __construct ($dblink) { $this->dblink = $dblink; } function db_delete($query) { // run query $sql = mysqli_query($this->dblink, $query) or die(mysqli_error($this->dblink)); } function db_insert($query) { // run query echo "
$query"; $sql = mysqli_query($this->dblink, $query) or die(mysqli_error($this->dblink)); // return result return mysqli_insert_id($this->dblink); } function db_select($query) { // run query $sql = mysqli_query($this->dblink, $query) or die(mysqli_error($this->dblink)); // loop results $result = array(); while($record = mysqli_fetch_assoc($sql)) { $result[] = $record; } // return array return $result; } function db_update($query) { // run query $sql = mysqli_query($this->dblink, $query) or die(mysqli_error($this->dblink)); } function options_asset($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT asset_id, asset_name FROM asset ORDER BY asset_name"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['asset_id']] = $rec['asset_name']; } return $options; } function options_assetclass($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT assetclass_id, assetclass_name FROM assetclass ORDER BY assetclass_name"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['assetclass_id']] = $rec['assetclass_name']; } return $options; } function options_assetclassgroup($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT assetclassgroup_id, assetclassgroup_name FROM assetclassgroup ORDER BY assetclassgroup_name"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['assetclassgroup_id']] = $rec['assetclassgroup_name']; } return $options; } function options_location($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT location_id, location_name FROM location ORDER BY location_name"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['location_id']] = $rec['location_name']; } return $options; } function options_subnet($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT subnet_id, CONCAT_WS('/', subnet_address, subnet_mask) AS subnet_name FROM subnet ORDER BY INET_ATON(subnet_address)"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['subnet_id']] = $rec['subnet_name']; } return $options; } function options_vlan($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT vlan_id, CONCAT_WS(' - ', vlan_number, vlan_name) AS vlan_option FROM vlan ORDER BY vlan_number"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['vlan_id']] = $rec['vlan_option']; } return $options; } function options_zone($null_value=NULL) { $options = array(); if (isset($null_value)) { $options[0] = $null_value; } $sql = "SELECT zone_id, zone_origin FROM zone ORDER BY zone_origin"; $records = $this->db_select($sql); foreach ($records as $rec) { $options[$rec['zone_id']] = $rec['zone_origin']; } return $options; } } ?>