Refactored asset and location
This commit is contained in:
parent
32bd592098
commit
7cfcaeb9d7
176
asset.php
176
asset.php
|
@ -8,9 +8,78 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
*****************************************************************************/
|
||||
|
||||
include("includes.php");
|
||||
|
||||
|
||||
if (isset($_REQUEST['id'])) {
|
||||
$id = (int) $_REQUEST['id'] or $id = 0;
|
||||
}
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
switch ($submit = form_get_action()) {
|
||||
|
||||
case NULL: break;
|
||||
|
||||
case 'add': $action = ACT_ADD; break;
|
||||
case 'view': $action = ACT_VIEW; break;
|
||||
case 'edit': $action = ACT_EDIT; break;
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'insert':
|
||||
$name = sanitize($_POST['asset_name']);
|
||||
$hostname = sanitize($_POST['asset_hostname']);
|
||||
$assetclass_id = sanitize($_POST['assetclass_id']);
|
||||
$info = sanitize($_POST['asset_info']);
|
||||
$intf = sanitize($_POST['asset_intf']);
|
||||
$asset_type = sanitize($_POST['asset_type']);
|
||||
|
||||
$sql = "INSERT INTO asset
|
||||
(asset_name, asset_hostname, assetclass_id, asset_info,
|
||||
asset_intf, asset_type)
|
||||
VALUE
|
||||
(?, ?, ?, ?, ?, ?)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$name, $hostname, $assetclass_id, $info, $intf, $asset_type]);
|
||||
$id = $dbh->lastInsertId();
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$asset_name = sanitize($_POST['asset_name']);
|
||||
$asset_info = sanitize($_POST['asset_info']);
|
||||
$asset_intf = sanitize($_POST['asset_intf']);
|
||||
$asset_hostname = sanitize($_POST['asset_hostname']);
|
||||
$assetclass_id = sanitize($_POST['assetclass_id']);
|
||||
$asset_type = sanitize($_POST['asset_type']);
|
||||
|
||||
$sql = "UPDATE asset SET
|
||||
asset_name=?, asset_info=?, asset_hostname=?,
|
||||
assetclass_id=?, asset_intf=?, asset_type=?
|
||||
WHERE asset_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$asset_name, $asset_info, $asset_hostname,
|
||||
$assetclass_id, $asset_intf, $asset_type,
|
||||
$id]);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$sth = $dbh->prepare("DELETE FROM asset WHERE asset_id=?");
|
||||
$sth->execute([$id]);
|
||||
$sth = $dbh->prepare("DELETE FROM node WHERE asset_id=?");
|
||||
$sth->execute([$id]);
|
||||
$action = ACT_DEFAULT;
|
||||
break;
|
||||
|
||||
default:
|
||||
$g_error->Add(submit_error($submit));
|
||||
$valid = FALSE;
|
||||
}
|
||||
|
||||
// ========== ACTIONS END =====================================================
|
||||
|
||||
include("header.php");
|
||||
|
||||
|
||||
if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
// create letter links
|
||||
$sql = "SELECT DISTINCT SUBSTRING(UPPER(asset_name),1,1) AS asset_letter
|
||||
|
@ -43,5 +112,106 @@ $smarty->assign("assets", $sth->fetchAll());
|
|||
|
||||
$smarty->display("asset.tpl");
|
||||
|
||||
include("footer.php");
|
||||
elseif ($action == ACT_ADD):
|
||||
// ========== VARIANT: add record =============================================
|
||||
|
||||
if((isset($_GET['assetclass_id'])) ? $assetclass_id = sanitize($_GET['assetclass_id']) : $assetclass_id = "");
|
||||
$smarty->assign("assetclass_id", $assetclass_id);
|
||||
|
||||
$sql = "SELECT assetclass_id, assetclass_name
|
||||
FROM assetclass
|
||||
ORDER BY assetclass_name";
|
||||
$sth = $dbh->query($sql);
|
||||
|
||||
$types = db_load_enum('asset','asset_type');
|
||||
|
||||
$smarty->assign("type_ids", $types);
|
||||
$smarty->assign("type_names", $types);
|
||||
$smarty->assign("type_selected", $types[0]);
|
||||
|
||||
$assetclass_options = array();
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
$assetclass_options[$rec[0]] = $rec[1];
|
||||
}
|
||||
$smarty->assign("assetclass_options", $assetclass_options);
|
||||
|
||||
$smarty->display("assetadd.tpl");
|
||||
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
$sql = "SELECT a.asset_id, a.asset_name, a.asset_hostname, a.asset_info,
|
||||
a.asset_intf, a.asset_type, c.assetclass_id, c.assetclass_name
|
||||
FROM asset AS a LEFT OUTER JOIN assetclass AS c USING (assetclass_id)
|
||||
WHERE a.asset_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$asset = $sth->fetch(PDO::FETCH_OBJ);
|
||||
$smarty->assign("asset", $asset);
|
||||
|
||||
$sql = "SELECT node_id, node_ip,
|
||||
CONCAT(LEFT(node_info, 40), IF(CHAR_LENGTH(node_info)>40,'...','')) AS node_info
|
||||
FROM node
|
||||
WHERE asset_id=?
|
||||
ORDER BY INET_ATON(node_ip)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("nodes", $sth->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
// external systems
|
||||
// extlink_id
|
||||
// asset_id
|
||||
// Type: enum('cdb','zabbix','topdesk', osticket
|
||||
// ID: extlink_refid int
|
||||
// extlink_uid string
|
||||
|
||||
// $sql = "SELECT extlink_id, extlink_type, extlink_refid, extlink_uid FROM extline WHERE extlink_asset_id=?";
|
||||
|
||||
$smarty->display("assetview.tpl");
|
||||
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
$sql = "SELECT asset_id, asset_name, asset_hostname, asset_info, asset_intf,
|
||||
assetclass_id, asset_type
|
||||
FROM asset
|
||||
WHERE asset_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("asset", $sth->fetch(PDO::FETCH_OBJ));
|
||||
|
||||
// Type selection
|
||||
$smarty->assign("type_ids", ['active', 'passive']);
|
||||
$smarty->assign("type_names", ['Active', 'Passive']);
|
||||
|
||||
$smarty->assign("assetclass_options", db_get_options_assetclass());
|
||||
|
||||
$smarty->display("assetedit.tpl");
|
||||
|
||||
elseif ($action == ACT_DELETE):
|
||||
// ========== VARIANT: delete record ==========================================
|
||||
|
||||
// asset to delete
|
||||
$sth = $dbh->prepare("SELECT asset_name FROM asset WHERE asset_id=?");
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("asset_id", $id);
|
||||
$smarty->assign("asset_name", $sth->fetchColumn());
|
||||
|
||||
// nodes to delete
|
||||
$sql = "SELECT node_id, node_ip FROM node WHERE asset_id=? ORDER BY INET_ATON(node_ip)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$asset_id]);
|
||||
$smarty->assign("nodes", $sth->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$smarty->display("assetdel.tpl");
|
||||
|
||||
else:
|
||||
// ========== ERROR UNKNOWN VARIANT ===========================================
|
||||
|
||||
echo "<p>Unknown function call: Please report to system development!</p>\n";
|
||||
|
||||
endif; // $action == ...
|
||||
// ========== END OF VARIANTS =================================================
|
||||
|
||||
$smarty->display('footer.tpl');
|
||||
?>
|
||||
|
|
36
assetadd.php
36
assetadd.php
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
|
||||
Copyright (C) 2011-2023 Thomas Hooge
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*****************************************************************************/
|
||||
|
||||
include("includes.php");
|
||||
|
||||
if((isset($_GET['assetclass_id'])) ? $assetclass_id = sanitize($_GET['assetclass_id']) : $assetclass_id = "");
|
||||
|
||||
include("header.php");
|
||||
|
||||
$sql = "SELECT assetclass_id, assetclass_name
|
||||
FROM assetclass
|
||||
ORDER BY assetclass_name";
|
||||
$sth = $dbh->query($sql);
|
||||
|
||||
$types = db_load_enum('asset','asset_type');
|
||||
|
||||
$smarty->assign("type_ids", $types);
|
||||
$smarty->assign("type_names", $types);
|
||||
$smarty->assign("type_selected", $types[0]);
|
||||
|
||||
$assetclass_options = array();
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
$assetclass_options[$rec[0]] = $rec[1];
|
||||
}
|
||||
|
||||
$smarty->assign("assetclass_options", $assetclass_options);
|
||||
$smarty->display("assetadd.tpl");
|
||||
|
||||
include("footer.php");
|
||||
?>
|
|
@ -114,7 +114,7 @@ $sql = "SELECT asset_id, asset_name,
|
|||
WHERE assetclass_id=?
|
||||
ORDER BY asset_name";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$assetclass_id]);
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("assets", $sth->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$smarty->display("assetclassview.tpl");
|
||||
|
|
31
assetdel.php
31
assetdel.php
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
|
||||
Copyright (C) 2011-2023 Thomas Hooge
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*****************************************************************************/
|
||||
|
||||
include("includes.php");
|
||||
|
||||
$asset_id = sanitize($_GET['asset_id']);
|
||||
|
||||
include("header.php");
|
||||
|
||||
// asset to delete
|
||||
$sth = $dbh->prepare("SELECT asset_name FROM asset WHERE asset_id=?");
|
||||
$sth->execute([$asset_id]);
|
||||
$smarty->assign("asset_id", $asset_id);
|
||||
$smarty->assign("asset_name", $sth->fetchColumn());
|
||||
|
||||
// nodes to delete
|
||||
$sql = "SELECT node_id, node_ip FROM node WHERE asset_id=? ORDER BY INET_ATON(node_ip)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$asset_id]);
|
||||
$smarty->assign("nodes", $sth->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$smarty->display("assetdel.tpl");
|
||||
|
||||
include("footer.php");
|
||||
?>
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
|
||||
Copyright (C) 2011-2023 Thomas Hooge
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*****************************************************************************/
|
||||
|
||||
include("includes.php");
|
||||
|
||||
$asset_id = sanitize($_GET['asset_id']);
|
||||
|
||||
include("header.php");
|
||||
|
||||
$sql = "SELECT asset_id, asset_name, asset_hostname, asset_info, asset_intf,
|
||||
assetclass_id, asset_type
|
||||
FROM asset
|
||||
WHERE asset_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$asset_id]);
|
||||
$smarty->assign("asset", $sth->fetch(PDO::FETCH_OBJ));
|
||||
|
||||
// Type selection
|
||||
$smarty->assign("type_ids", ['active', 'passive']);
|
||||
$smarty->assign("type_names", ['Active', 'Passive']);
|
||||
|
||||
$smarty->assign("assetclass_options", db_get_options_assetclass());
|
||||
|
||||
$smarty->display("assetedit.tpl");
|
||||
|
||||
include("footer.php");
|
||||
?>
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
|
||||
Copyright (C) 2011-2023 Thomas Hooge
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*****************************************************************************/
|
||||
|
||||
include("includes.php");
|
||||
|
||||
if (isset($_GET['asset_id']) && (!empty($_GET['asset_id']))) {
|
||||
$asset_id = sanitize($_GET['asset_id']);
|
||||
} else {
|
||||
header_location("comments.php?comments=error");
|
||||
}
|
||||
|
||||
include("header.php");
|
||||
|
||||
$sql = "SELECT a.asset_id, a.asset_name, a.asset_hostname, a.asset_info,
|
||||
a.asset_intf, a.asset_type, c.assetclass_id, c.assetclass_name
|
||||
FROM asset AS a LEFT OUTER JOIN assetclass AS c USING (assetclass_id)
|
||||
WHERE a.asset_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$asset_id]);
|
||||
$asset = $sth->fetch(PDO::FETCH_OBJ);
|
||||
$smarty->assign("asset", $asset);
|
||||
|
||||
$sql = "SELECT node_id, node_ip,
|
||||
CONCAT(LEFT(node_info, 40), IF(CHAR_LENGTH(node_info)>40,'...','')) AS node_info
|
||||
FROM node
|
||||
WHERE asset_id=?
|
||||
ORDER BY INET_ATON(node_ip)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$asset_id]);
|
||||
$smarty->assign("nodes", $sth->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$smarty->display("assetview.tpl");
|
||||
|
||||
include("footer.php");
|
||||
?>
|
|
@ -33,4 +33,13 @@ $config_ldap_login_attr = 'uid';
|
|||
$config_ldap_bind_dn = 'cn=dummy,ou=organizationalunit,dc=example,dc=com';
|
||||
$config_ldap_bind_pass = 'secret';
|
||||
|
||||
// external systems
|
||||
$config_ext[] = [
|
||||
'zabbix' => ['enabled' => false,
|
||||
'host' => 'localhost',
|
||||
'db' => 'zabbix',
|
||||
'user' => 'ipreg',
|
||||
'pass' => 'topsecret']
|
||||
];
|
||||
|
||||
?>
|
||||
|
|
|
@ -16,7 +16,11 @@ if (empty($_SESSION['suser_id'])) {
|
|||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// required config vars, may be overwritten later
|
||||
$config_auth_ldap = false;
|
||||
$config_ext = array();
|
||||
|
||||
include("config.php");
|
||||
|
||||
// connect to database
|
||||
|
|
|
@ -53,10 +53,12 @@ CREATE TABLE cablevlan (
|
|||
|
||||
-- WIP
|
||||
-- Reference to external systems
|
||||
-- class 1=asset; per ext type different class-ids possible
|
||||
CREATE TABLE extlink (
|
||||
extlink_id int(10) NOT NULL AUTO_INCREMENT,
|
||||
asset_id int(10) NOT NULL,
|
||||
extlink_type enum('cdb','zabbix', 'topdesk') NOT NULL DEFAULT 'cdb',
|
||||
extlink_class tinyint(4) NOT NULL DEFAULT 1,
|
||||
extlink_refid int(10) DEFAULT NULL,
|
||||
extlink_uid varchar(65) DEFAULT NULL,
|
||||
PRIMARY KEY (extlink_id),
|
||||
|
|
244
location.php
244
location.php
|
@ -8,9 +8,100 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
*****************************************************************************/
|
||||
|
||||
include("includes.php");
|
||||
|
||||
|
||||
if (isset($_REQUEST['id'])) {
|
||||
$id = (int) $_REQUEST['id'] or $id = 0;
|
||||
}
|
||||
|
||||
// look for parents
|
||||
// function to look for parents and create a new array for every child
|
||||
function location($parents, $parent = 0) {
|
||||
// loop array to check
|
||||
foreach($parents[$parent] as $child) {
|
||||
if(isset($parents[$child])) {
|
||||
// element has children
|
||||
$children[$child] = location($parents, $child);
|
||||
} else {
|
||||
// no children, set NULL
|
||||
$children[$child] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// and again...
|
||||
return $children;
|
||||
}
|
||||
|
||||
// recursive children check to template
|
||||
function checkchildren($locations, $level) {
|
||||
global $location_options;
|
||||
global $location_names;
|
||||
global $location_parent;
|
||||
|
||||
foreach ($locations as $parent=>$child) {
|
||||
$row = str_repeat("- ", $level) . $location_names[$parent];
|
||||
$location_options[$parent] = $row;
|
||||
if (isset($child)) {
|
||||
checkchildren($child, $level+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
switch ($submit = form_get_action()) {
|
||||
|
||||
case NULL: break;
|
||||
|
||||
case 'add': $action = ACT_ADD; break;
|
||||
case 'view': $action = ACT_VIEW; break;
|
||||
case 'edit': $action = ACT_EDIT; break;
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'insert':
|
||||
$name = sanitize($_POST['location_name']);
|
||||
$parent = sanitize($_POST['location_parent']);
|
||||
$info = sanitize($_POST['location_info']);
|
||||
|
||||
$sql = "INSERT INTO location (
|
||||
location_name, location_parent, location_info
|
||||
)
|
||||
VALUE (?, ?, ?)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$name, $parent, $info]);
|
||||
|
||||
$id = $dbh->lastInsertId();
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$location_name = sanitize($_POST['location_name']);
|
||||
$location_info = sanitize($_POST['location_info']);
|
||||
$parentlocation_id = sanitize($_POST['parentlocation_id']);
|
||||
$sql = "UPDATE location SET
|
||||
location_name=?, location_parent=?, location_info=?
|
||||
WHERE location_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$location_name, $parentlocation_id, $location_info, $id]);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$sth = $dbh->prepare("DELETE FROM location WHERE location_id=?");
|
||||
$sth->execute([$id]);
|
||||
$action = ACT_DEFAULT;
|
||||
break;
|
||||
|
||||
default:
|
||||
$g_error->Add(submit_error($submit));
|
||||
$valid = FALSE;
|
||||
}
|
||||
|
||||
// ========== ACTIONS END =====================================================
|
||||
|
||||
include("header.php");
|
||||
|
||||
|
||||
if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
$sql = "SELECT location_id AS id, location_name AS value, location_parent AS parent_id
|
||||
FROM location
|
||||
ORDER BY location_parent, location_sort, location_name";
|
||||
|
@ -39,5 +130,152 @@ $smarty->assign("locations", $tree);
|
|||
|
||||
$smarty->display("location.tpl");
|
||||
|
||||
include("footer.php");
|
||||
elseif ($action == ACT_ADD):
|
||||
// ========== VARIANT: add record =============================================
|
||||
|
||||
$sql = "SELECT location_id AS id, location_name AS name,
|
||||
location_parent AS parent, location_sort AS sort
|
||||
FROM location
|
||||
ORDER BY location_parent, location_sort, location_name";
|
||||
$sth = $dbh->query($sql);
|
||||
$locations = $sth->fetchAll();
|
||||
|
||||
if (count($locations) > 0) {
|
||||
foreach ($locations AS $location) {
|
||||
$location_names[$location['id']] = $location['name'];
|
||||
$parents[$location['parent']][] = $location['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$tree = location($parents);
|
||||
|
||||
// create tree option list
|
||||
$location_options = array(0 => '-');
|
||||
checkchildren($tree, 0);
|
||||
|
||||
$smarty->assign("location_options", $location_options);
|
||||
|
||||
$location_parent = sanitize($_GET['parent']);
|
||||
$smarty->assign("location_parent", $location_parent);
|
||||
|
||||
$smarty->display("locationadd.tpl");
|
||||
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
// base location
|
||||
$sql = "SELECT location_id AS id, location_name AS name,
|
||||
location_parent AS parent_id, location_info AS info,
|
||||
CONCAT('locationview.php?location_id=', location_id) AS url
|
||||
FROM location
|
||||
WHERE location_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$location = $sth->fetch(PDO::FETCH_OBJ);
|
||||
$smarty->assign("location", $location);
|
||||
|
||||
// crumbs
|
||||
$crumbs[] = $location;
|
||||
$sql = "SELECT location_id AS id, location_name AS name,
|
||||
location_parent AS parent_id,
|
||||
CONCAT('locationview.php?location_id=', location_id) AS url
|
||||
FROM location
|
||||
WHERE location_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
while ($crumbs[0]->parent_id != 0) {
|
||||
$sth->execute([$crumbs[0]->parent_id]);
|
||||
$result = $sth->fetch(PDO::FETCH_OBJ);
|
||||
array_unshift($crumbs, $result);
|
||||
}
|
||||
$smarty->assign("crumbs", $crumbs);
|
||||
|
||||
// sublocations
|
||||
$sql = "SELECT location_id AS sublocation_id, location_name AS sublocation_name,
|
||||
LEFT(location_info, 40) AS info_short,
|
||||
CHAR_LENGTH(location_info) AS info_length
|
||||
FROM location
|
||||
WHERE location_parent=?
|
||||
ORDER BY location_name";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("sublocations", $sth->fetchAll());
|
||||
|
||||
// subnets
|
||||
$sql = "SELECT s.subnet_id, s.subnet_address, s.subnet_mask
|
||||
FROM subnet AS s LEFT JOIN subnetlocation AS l USING (subnet_id)
|
||||
WHERE l.location_id=?
|
||||
ORDER BY INET_ATON(s.subnet_address)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("subnets", $sth->fetchAll());
|
||||
|
||||
$smarty->display("locationview.tpl");
|
||||
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
// TODO implement sorting with location_sort
|
||||
|
||||
// location
|
||||
$sql = "SELECT location_id AS id, location_name AS name, location_parent AS parent,
|
||||
location_info AS info, location_sort AS sort
|
||||
FROM location
|
||||
WHERE location_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$location = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
$location_parent = $location->parent;
|
||||
|
||||
$smarty->assign("location", $location);
|
||||
|
||||
// parent location
|
||||
$sql = "SELECT location_id, location_name, location_parent
|
||||
FROM location
|
||||
WHERE location_id != ?
|
||||
ORDER BY location_name";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
|
||||
$locations = $sth->fetchAll();
|
||||
|
||||
$location_counter = count($locations);
|
||||
|
||||
$smarty->assign("location_counter", $location_counter);
|
||||
|
||||
// any loactions?
|
||||
if ($location_counter>0) {
|
||||
foreach($locations AS $location) {
|
||||
$location_names[$location['location_id']] = $location['location_name'];
|
||||
$parents[$location['location_parent']][] = $location['location_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$tree = location($parents);
|
||||
$location_options = array(0 => '-');
|
||||
checkchildren($tree, 0);
|
||||
$smarty->assign("location_options", $location_options);
|
||||
$smarty->assign("location_parent", $location_parent);
|
||||
|
||||
$smarty->display("locationedit.tpl");
|
||||
|
||||
elseif ($action == ACT_DELETE):
|
||||
// ========== VARIANT: delete record ==========================================
|
||||
|
||||
$sql = "SELECT location_id AS id, location_name AS name FROM location WHERE location_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ));
|
||||
|
||||
$smarty->display("locationdel.tpl");
|
||||
|
||||
else:
|
||||
// ========== ERROR UNKNOWN VARIANT ===========================================
|
||||
|
||||
echo "<p>Unknown function call: Please report to system development!</p>\n";
|
||||
|
||||
endif; // $action == ...
|
||||
// ========== END OF VARIANTS =================================================
|
||||
|
||||
$smarty->display('footer.tpl');
|
||||
?>
|
||||
|
|
24
submit.php
24
submit.php
|
@ -101,7 +101,7 @@ if (isset($_POST['redirect'])) {
|
|||
if (isset($_POST['add'])) {
|
||||
switch ($_POST['add']) {
|
||||
|
||||
case ("asset") :
|
||||
/* case ("asset") :
|
||||
$name = sanitize($_POST['asset_name']);
|
||||
$hostname = sanitize($_POST['asset_hostname']);
|
||||
$assetclass_id = sanitize($_POST['assetclass_id']);
|
||||
|
@ -119,7 +119,7 @@ if (isset($_POST['add'])) {
|
|||
|
||||
header_location("assetview.php?asset_id=" . $dbh->lastInsertId());
|
||||
break;
|
||||
/*
|
||||
|
||||
case ("assetclass") :
|
||||
$name = sanitize($_POST['assetclass_name']);
|
||||
$description = sanitize($_POST['assetclass_description']);
|
||||
|
@ -199,7 +199,7 @@ if (isset($_POST['add'])) {
|
|||
header_location("subnetview.php?subnet_id=" . $subnet_id);
|
||||
break;
|
||||
|
||||
case ("location") :
|
||||
/* case ("location") :
|
||||
$name = sanitize($_POST['location_name']);
|
||||
$parent = sanitize($_POST['location_parent']);
|
||||
$info = sanitize($_POST['location_info']);
|
||||
|
@ -212,7 +212,7 @@ if (isset($_POST['add'])) {
|
|||
$sth->execute([$name, $parent, $info]);
|
||||
|
||||
header_location("locationview.php?location_id=" . $dbh->lastInsertId());
|
||||
break;
|
||||
break; */
|
||||
|
||||
case ("locationsubnet") :
|
||||
$location_id = sanitize($_POST['location_id']);
|
||||
|
@ -386,7 +386,7 @@ if (isset($_POST['add'])) {
|
|||
|
||||
if (isset($_POST['del'])) {
|
||||
switch ($_POST['del']) {
|
||||
|
||||
/*
|
||||
case ("asset") :
|
||||
$asset_id = sanitize($_POST['asset_id']);
|
||||
|
||||
|
@ -398,7 +398,7 @@ if (isset($_POST['del'])) {
|
|||
|
||||
header_location("asset.php");
|
||||
break;
|
||||
/*
|
||||
|
||||
case ("assetclass") :
|
||||
$assetclass_id = sanitize($_POST['assetclass_id']);
|
||||
|
||||
|
@ -415,7 +415,7 @@ if (isset($_POST['del'])) {
|
|||
$sth->execute([$assetclassgroup_id]);
|
||||
|
||||
header_location("assetclassgroup.php");
|
||||
break; */
|
||||
break;
|
||||
|
||||
case ("location") :
|
||||
$location_id = sanitize($_POST['location_id']);
|
||||
|
@ -424,7 +424,7 @@ if (isset($_POST['del'])) {
|
|||
$sth->execute([$location_id]);
|
||||
|
||||
header_location("location.php");
|
||||
break;
|
||||
break; */
|
||||
|
||||
case ("locationsubnet") :
|
||||
$location_id = sanitize($_POST['location_id']);
|
||||
|
@ -528,7 +528,7 @@ if (isset($_POST['del'])) {
|
|||
|
||||
if (isset($_POST['edit'])) {
|
||||
switch ($_POST['edit']) {
|
||||
|
||||
/*
|
||||
case ("asset") :
|
||||
$asset_id = sanitize($_POST['asset_id']);
|
||||
$asset_name = sanitize($_POST['asset_name']);
|
||||
|
@ -548,7 +548,7 @@ if (isset($_POST['edit'])) {
|
|||
$asset_id]);
|
||||
|
||||
header_location("assetview.php?asset_id=" . $asset_id);
|
||||
/*
|
||||
|
||||
case ("assetclass") :
|
||||
$id = sanitize($_POST['assetclass_id']);
|
||||
$name = sanitize($_POST['assetclass_name']);
|
||||
|
@ -563,7 +563,7 @@ if (isset($_POST['edit'])) {
|
|||
$sth->execute([$name, $description, $group_id, $id]);
|
||||
|
||||
header_location("assetclassview.php?assetclass_id=" . $id);
|
||||
break; */
|
||||
break;
|
||||
|
||||
case ("assetclassgroup") :
|
||||
$acg_id = sanitize($_POST['acg_id']);
|
||||
|
@ -593,7 +593,7 @@ if (isset($_POST['edit'])) {
|
|||
$sth->execute([$location_name, $parentlocation_id, $location_info, $location_id]);
|
||||
|
||||
header_location("locationview.php?location_id=" . $location_id);
|
||||
break;
|
||||
break; */
|
||||
|
||||
case ("node") :
|
||||
$node_id = sanitize($_POST['node_id']);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<form method="POST" action="submit.php">
|
||||
<input type="hidden" name="add" value="asset">
|
||||
<form method="POST" action="asset.php">
|
||||
|
||||
<table class="title">
|
||||
<tr>
|
||||
|
@ -8,7 +7,7 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=cancel" alt="{$lang_cancel}" {if $suser_tooltips}title="{$lang_cancel}" {/if}/></a>
|
||||
<input type="image" src="image.php?icon=save" alt="{$lang_submit}" {if $suser_tooltips}title="{$lang_submit}" {/if}/>
|
||||
<input type="image" name="submit[insert]" src="images/page_save.png" alt="{$lang_submit}" {if $suser_tooltips}title="{$lang_submit}" {/if}/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<tr>
|
||||
<td class="label">
|
||||
<img src="image.php?color={$acg.color}" alt="#{$acg.color}">
|
||||
<a href="assetclassgroupview.php?assetclassgroup_id={$acg.id}">{$acg.name}</a>
|
||||
<a href="assetclassgroup.php?f=view&id={$acg.id}">{$acg.name}</a>
|
||||
</td>
|
||||
<td>
|
||||
{$acg.description}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<form method="POST" action="submit.php">
|
||||
<input type="hidden" name="del" value="asset">
|
||||
<input type="hidden" name="asset_id" value="{$asset_id}">
|
||||
<form method="POST" action="asset.php">
|
||||
<input type="hidden" name="id" value="{$asset_id}">
|
||||
|
||||
<table class="title">
|
||||
<tr>
|
||||
|
@ -9,7 +8,7 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=cancel" alt="{$lang_cancel}" {if $suser_tooltips}title="{$lang_cancel}" {/if}/></a>
|
||||
<input type="image" src="image.php?icon=shred" alt="{$lang_asset_del}" {if $suser_tooltips}title="{$lang_asset_del}" {/if}/>
|
||||
<input type="image" name="submit[delete]" src="images/bin.png" alt="{$lang_asset_del}" {if $suser_tooltips}title="{$lang_asset_del}" {/if}/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -29,7 +28,7 @@
|
|||
{$lang_asset_name}
|
||||
</td>
|
||||
<td class="value">
|
||||
<a href="assetview.php?asset_id={$asset_id}">{$asset_name}</a>
|
||||
<a href="asset.php?f=view&id={$asset_id}">{$asset_name}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<form method="POST" action="submit.php">
|
||||
<input type="hidden" name="edit" value="asset">
|
||||
<input type="hidden" name="asset_id" value="{$asset->asset_id}">
|
||||
<input type="hidden" name="assetclass_id" value="{$asset->assetclass_id}">
|
||||
<form method="POST" action="asset.php">
|
||||
<input type="hidden" name="id" value="{$asset->asset_id}">
|
||||
|
||||
<table class="title">
|
||||
<tr>
|
||||
|
@ -11,7 +9,7 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=back" alt="{$lang_cancel}"></a>
|
||||
<input type="image" src="image.php?icon=save" alt="{$lang_submit}">
|
||||
<input type="image" name="submit[update]" src="images/page_save.png" alt="{$lang_submit}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
<a href="assignnodetoasset.php?asset_id={$asset->asset_id}"><img src="image.php?icon=add" alt="{$lang_assignnodetoasset}"></a>
|
||||
{/if}
|
||||
{if $suser_edit}
|
||||
<a href="assetedit.php?asset_id={$asset->asset_id}"><img src="image.php?icon=edit" alt="{$lang_asset_edit}"></a>
|
||||
<a href="asset.php?f=edit&id={$asset->asset_id}"><img src="image.php?icon=edit" alt="{$lang_asset_edit}"></a>
|
||||
{/if}
|
||||
{if $suser_delete}
|
||||
<a href="assetdel.php?asset_id={$asset->asset_id}"><img src="image.php?icon=delete" alt="{$lang_asset_edit}"></a>
|
||||
<a href="asset.php?f=del&id={$asset->asset_id}"><img src="image.php?icon=delete" alt="{$lang_asset_edit}"></a>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -32,7 +32,7 @@
|
|||
{$lang_asset_name}
|
||||
</td>
|
||||
<td class="value">
|
||||
<a href="assetview.php?asset_id={$asset->asset_id}">{$asset->asset_name}</a>
|
||||
<a href="asset.php?f=view&id={$asset->asset_id}">{$asset->asset_name}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
{if $suser_add || $suser_admin}
|
||||
<a href="locationadd.php"><img src="images/building_add.png" alt="{$lang_location_add}" title="{$lang_location_add}" /></a>
|
||||
<a href="location.php?f=add"><img src="images/building_add.png" alt="{$lang_location_add}" title="{$lang_location_add}" /></a>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<form method="POST" action="submit.php">
|
||||
<input type="hidden" name="add" value="location">
|
||||
<form method="POST" action="location.php">
|
||||
|
||||
<table class="title">
|
||||
<tr>
|
||||
|
@ -9,7 +8,7 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=cancel" alt="{$lang_cancel}"></a>
|
||||
<input type="image" src="image.php?icon=save" alt="{$lang_submit}">
|
||||
<input type="image" name="submit[insert]" src="images/page_save.png" alt="{$lang_submit}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -1,39 +1,38 @@
|
|||
<form method="POST" action="submit.php">
|
||||
<input type="hidden" name="del" value="location">
|
||||
<input type="hidden" name="location_id" value="{$location->id}">
|
||||
<form method="POST" action="location.php">
|
||||
<input type="hidden" name="id" value="{$location->id}">
|
||||
|
||||
<table class="title">
|
||||
<tr>
|
||||
<td class="header">
|
||||
<img class="icon" src="images/building.png" alt="" />
|
||||
{$location_name}
|
||||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=cancel" alt="{$lang_cancel}"></a>
|
||||
<input type="image" src="images/building_delete.png" alt="{$lang_location_del}">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="header">
|
||||
<img class="icon" src="images/building.png" alt="" />
|
||||
{$location->name}
|
||||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=cancel" alt="{$lang_cancel}"></a>
|
||||
<input type="image" name="submit[delete]" src="images/building_delete.png" alt="{$lang_location_del}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
|
||||
<table class="info">
|
||||
<tr>
|
||||
<td class="header">
|
||||
{$lang_location_del}
|
||||
</td>
|
||||
<td class="header_right">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">
|
||||
{$lang_location_name}
|
||||
</td>
|
||||
<td class="value">
|
||||
<a href="locationview.php?location_id={$location->id}">{$location->name}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="header">
|
||||
{$lang_location_del}
|
||||
</td>
|
||||
<td class="header_right">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">
|
||||
{$lang_location_name}
|
||||
</td>
|
||||
<td class="value">
|
||||
<a href="location.php?f=view&id={$location->id}">{$location->name}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<form method="POST" action="submit.php">
|
||||
<input type="hidden" name="edit" value="location">
|
||||
<input type="hidden" name="location_id" value="{$location->id}">
|
||||
<form method="POST" action="location.php">
|
||||
<input type="hidden" name="id" value="{$location->id}">
|
||||
|
||||
<table class="title">
|
||||
<tr>
|
||||
|
@ -10,7 +9,7 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=back" alt="{$lang_cancel}"></a>
|
||||
<input type="image" src="image.php?icon=save" alt="{$lang_submit}">
|
||||
<input type="image" name="submit[update]" src="images/page_save.png" alt="{$lang_submit}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
</td>
|
||||
<td align="right">
|
||||
{if $suser_add}
|
||||
<a href="locationadd.php?location_parent={$location->id}"><img src="images/building_add.png" alt="{$lang_sublocation_add}"></a>
|
||||
<a href="location.php?f=add&parent={$location->id}"><img src="images/building_add.png" alt="{$lang_sublocation_add}"></a>
|
||||
{/if}
|
||||
{if $suser_edit}
|
||||
<a href="locationedit.php?location_id={$location->id}"><img src="images/building_edit.png" alt="{$lang_location_edit}"></a>
|
||||
<a href="location.php?f=edit&id={$location->id}"><img src="images/building_edit.png" alt="{$lang_location_edit}"></a>
|
||||
{/if}
|
||||
{if $suser_delete}
|
||||
<a href="locationdel.php?location_id={$location->id}"><img src="images/building_delete.png" alt="{$lang_location_del}"></a>
|
||||
<a href="location.php?f=del&id={$location->id}"><img src="images/building_delete.png" alt="{$lang_location_del}"></a>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -64,7 +64,7 @@
|
|||
</td>
|
||||
<td class="value">
|
||||
{foreach item=sublocation from=$sublocations}
|
||||
<a href="locationview.php?location_id={$sublocation.sublocation_id}">{$sublocation.sublocation_name}</a>
|
||||
<a href="location.php?f=view&id={$sublocation.sublocation_id}">{$sublocation.sublocation_name}</a>
|
||||
{$sublocation.info_short}{if $sublocation.info_length>40}…{/if}
|
||||
<br>
|
||||
{/foreach}
|
||||
|
|
Loading…
Reference in New Issue