Refactored, no more redirects. Improved error messaging system
This commit is contained in:
34
asset.php
34
asset.php
@@ -58,6 +58,24 @@ switch ($submit = form_get_action()) {
|
||||
$sth->execute([$asset_name, $asset_info, $asset_hostname,
|
||||
$assetclass_id, $asset_intf, $asset_type,
|
||||
$id]);
|
||||
|
||||
// Ext. links
|
||||
if ($config_ext['zabbix']['enabled'] and isset($_POST['x_zbx_host'])) {
|
||||
$zbx_host = sanitize($_POST['x_zbx_host']);
|
||||
$sql = "SELECT extlink_id FROM extlink WHERE asset_id=? AND extlink_type='zabbix'";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
if ($linkid = $sth->fetchColumn()) {
|
||||
$sql = "UPDATE extlink SET extlink_refid=? WHERE extlink_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$zbx_host, $linkid]);
|
||||
} else {
|
||||
$sql = "INSERT INTO extlink (asset_id, extlink_type, extlink_refid) VALUES (?, 'zabbix', ?)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id, $zbx_host]);
|
||||
}
|
||||
}
|
||||
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
@@ -165,7 +183,19 @@ $smarty->assign("nodes", $sth->fetchAll(PDO::FETCH_ASSOC));
|
||||
// ID: extlink_refid int
|
||||
// extlink_uid string
|
||||
|
||||
// $sql = "SELECT extlink_id, extlink_type, extlink_refid, extlink_uid FROM extline WHERE extlink_asset_id=?";
|
||||
if ($config_ext['zabbix']['enabled']) {
|
||||
$smarty->assign("zabbix", true);
|
||||
$sql = "SELECT extlink_refid FROM extlink WHERE extlink_type='zabbix' AND asset_id=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$refid = $sth->fetchColumn();
|
||||
// TODO fetch ext data here
|
||||
//$zbx = new PDO('mysql:host='.$config_ext['zabbix']['host'].';dbname='.$config_ext['zabbix']['db'].';', $config_ext['zabbix']['user'], $config_ext['zabbix']['pass']);
|
||||
//$zbx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
//$zbx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
$smarty->assign('refid', $refid);
|
||||
}
|
||||
|
||||
|
||||
$smarty->display("assetview.tpl");
|
||||
|
||||
@@ -186,6 +216,8 @@ $smarty->assign("type_names", ['Active', 'Passive']);
|
||||
|
||||
$smarty->assign("assetclass_options", db_get_options_assetclass());
|
||||
|
||||
|
||||
|
||||
$smarty->display("assetedit.tpl");
|
||||
|
||||
elseif ($action == ACT_DELETE):
|
||||
|
||||
Reference in New Issue
Block a user