Add('Invalid action: '. $_POST['action']); } break; case 'insert': $node_id_ext = sanitize($_POST['node_id_ext']); $node_id_int = sanitize($_POST['node_id_int']); $nat_type = sanitize($_POST['nat_type']); $sql = "INSERT INTO nat (nat_ext, nat_int, nat_type) VALUE (?, ?, ?)"; $sth = $dbh->prepare($sql); $sth->execute([$node_id_ext, $node_id_int, $nat_type]); header_location("node.php?f=view&id=$node_id_ext"); break; case 'delete': $node_id_ext = sanitize($_POST['node_id_ext']); $sth = $dbh->prepare("DELETE FROM nat WHERE nat_id=?"); try { $sth->execute([$id]); } catch (PDOException $e) { $g_warning->Add($e->getMessage()); } // TODO // header_location("node.php?f=view&id=" . $node_id_ext); $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 n.nat_id AS id, n.nat_type, n.nat_ext, n.nat_int, n.nat_ext_port AS port_ext, n.nat_int_port AS port_int, n.nat_description AS description, n1.node_ip AS node_ip_int, n2.node_ip AS node_ip_ext FROM nat AS n LEFT JOIN node AS n1 ON (n.nat_int=n1.node_id) LEFT JOIN node AS n2 ON (n.nat_ext=n2.node_id) ORDER BY INET_ATON(nat_ext)"; $sth = $dbh->query($sql); $smarty->assign("nats", $sth->fetchAll()); $smarty->display("nat.tpl"); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= $node_id = sanitize($_REQUEST['node_id']); // node_ext $sql = "SELECT node_ip AS node_ip_ext FROM node WHERE node_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$node_id]); $node = $sth->fetch(PDO::FETCH_OBJ); $smarty->assign("node_id_ext", $node_id); $smarty->assign("node_ip_ext", $node->node_ip_ext); // node_int $sql = "SELECT a.asset_name, n.node_id AS node_id_int, n.node_ip AS node_ip_int FROM asset AS a LEFT JOIN node AS n USING (asset_id) WHERE n.node_id NOT IN ( SELECT nat_int FROM nat WHERE nat_ext=? ) AND n.node_id!=? ORDER BY INET_ATON(n.node_ip)"; $sth = $dbh->prepare($sql); $sth->execute([$node_id, $node_id]); $nodes = $sth->fetchAll(); foreach ($nodes as $rec) { $node_options[$rec['node_id_int']] = $rec['node_ip_int'] . '/' . $rec['asset_name']; } $smarty->assign("node_options", $node_options); $nat_type_options[1] = $lang['lang_nat_type_1']; $nat_type_options[2] = $lang['lang_nat_type_2']; $nat_type_options[3] = $lang['lang_nat_type_3']; $smarty->assign("nat_type_options", $nat_type_options); $smarty->display("natadd.tpl"); elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $sql = "SELECT nat_id AS id, nat_type AS type, nat_ext, nat_int FROM nat WHERE nat_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("nat", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("natview.tpl"); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $node_id = sanitize($_GET['node_id']); $sql = "SELECT node_id AS id, node_ip AS ip FROM node WHERE node.node_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$node_id]); $smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("natedit.tpl"); elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== $node_id = sanitize($_REQUEST['node_id']); // node_ext $sth = $dbh->prepare("SELECT node_id AS id_ext, node_ip AS ip_ext FROM node WHERE node_id=?"); $sth->execute([$node_id]); $smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); // options $sql = "SELECT x.nat_id, n.node_ip, a.asset_name FROM nat AS x LEFT JOIN node AS n ON (x.nat_int=n.node_id) LEFT JOIN asset AS a USING (asset_id) WHERE x.nat_ext=? ORDER BY INET_ATON(n.node_ip)"; $sth = $dbh->prepare($sql); $sth->execute([$node_id]); $nats = $sth->fetchAll(); $options = array(); foreach ($nats as $rec) { $options[$rec['nat_id']] = $rec['node_ip'] . '/' . $rec['asset_name']; } $smarty->assign("nat_options", $options); $smarty->display("natdel.tpl"); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo "

Unknown function call: Please report to system development!

\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= $smarty->display('footer.tpl');