Changes adopted from version 0.5

This commit is contained in:
2023-02-13 10:42:09 +01:00
parent faf5f368f5
commit 76ccecca7f
198 changed files with 10261 additions and 5068 deletions

View File

@@ -1,7 +1,7 @@
<?php
/*****************************************************************************
IP Reg, a PHP/MySQL IPAM tool
Copyright (C) 2008 Wietse Warendorff
Copyright (C) 2007-2009 Wietse Warendorff
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,93 +20,195 @@
or contact me at wietsew@users.sourceforge.net
*****************************************************************************/
// includes
include("includes.php");
// get id
$location_id = $_GET['location_id'];
// check authorisation
$auth = auth("location", $config_auth_locationview, $location_id);
// start output
include("header.php");
// set template
$tp = new Template("tpl/locationview.tpl");
// set language variables
$tp->setvars($lang);
// create breadcrumb arrays
$parents = array();
$location_names = array();
$crumbs = array();
// get location information and insert to the arrays
$result = mysql_query("SELECT location_id, location_name, parent FROM location") or die(mysql_error());
while ($row = mysql_fetch_object($result)) {
$location_names[$row->location_id] = $row->location_name;
$parents[$row->location_id] = $row->parent;
}
// function to build array with parents
function parent($location_id) {
// use names index
global $parents;
global $crumbs;
global $location_names;
// start page
// includes
include("includes.php");
// fill array with this value
$crumbs[$location_id] = $location_id;
if (($parents[$location_id])>0) {
// still not on top, so do it again
parent($parents[$location_id]);
// get id
$location_id = sanitize($_GET['location_id']);
// start output
include("header.php");
// set template
$tp = new Template("tpl/locationview.tpl", $config_yapter_error);
// set language variables
$tp->setvars($lang);
// start locationcrumb
// get locations
// build query
$query = "SELECT
location.location_id AS location_id,
location.location_name AS location_name,
location.location_parent AS location_parent
FROM
location";
// run query
$locations = $db->db_select($query);
// count results
$location_counter = count($locations);
// counter to tpl
$tp->set("location_counter", $location_counter);
// any loactions?
if ($location_counter>0) {
// get objects
foreach($locations AS $location) {
// create arrays
$location_names[$location['location_id']] = $location['location_name'];
$parents[$location['location_id']] = $location['location_parent'];
}
}
// build parents array
// function to build array with parents for this location
function parent($location_id) {
// use names index
global $parents;
global $crumbs;
global $location_names;
// fill array with this value
$crumbs[$location_id] = $location_id;
if (($parents[$location_id])>0) {
// still not on top, so do it again
parent($parents[$location_id]);
}
// return the array
return $location_id;
}
// build parents
parent($location_id);
// to tpl
// loop in reverse order
foreach (array_reverse($crumbs) as $key=>$val) {
// send vars to template
$tp->set("location_id", $val);
$tp->set("location_name", $location_names[$val]);
// include seperator?
if (($key>0) ? $tp->set("seperator", ".&nbsp;") : $tp->set("seperator", ""));
// parse block
$tp->parse("locationcrumb_row");
}
// parse block
$tp->parse("locationcrumb_table");
// setup location
// build query
$query = "SELECT
location.location_info AS location_info
FROM
location
WHERE
location.location_id=" . $location_id;
// run query
$location = $db->db_select($query);
// send to tpl
$tp->set("location_id", $location_id);
$tp->set("location_info", nl2br($location[0]['location_info']));
// setup sublocations
// build query
$query = "SELECT
location.location_id AS sublocation_id,
location.location_name AS sublocation_name
FROM
location
WHERE
location.location_parent=" . $location_id . "
ORDER BY
location.location_name";
// run query
$sublocations = $db->db_select($query);
// count results
$sublocation_counter = count($sublocations);
// counter to tpl
$tp->set("sublocation_counter", $sublocation_counter);
// any nodes?
if ($sublocation_counter>0) {
// get objects
foreach($sublocations AS $sublocation) {
// send to tpl
$tp->set("sublocation_id", $sublocation['sublocation_id']);
$tp->set("sublocation_name", $sublocation['sublocation_name']);
// parse row
$tp->parse("sublocation_row");
}
// parse block
$tp->parse("sublocation_table");
} else {
// hide block
$tp->hide("sublocation_table");
}
// setup subnets
// build query
$query = "SELECT
subnet.subnet_id AS subnet_id,
subnet.subnet_address AS subnet_address,
subnet.subnet_mask AS subnet_mask
FROM
subnet,
subnetlocation
WHERE
subnetlocation.location_id=" . $location_id . "
AND subnetlocation.subnet_id=subnet.subnet_id
ORDER BY
INET_ATON(subnet.subnet_address)";
// return the array
return $location_id;
}
// build parents
parent($location_id);
// loop array in reverse order and send to template
foreach (array_reverse($crumbs) as $key=>$val) {
$tp->set("location_id", $val);
$tp->set("location_name", $location_names[$val]);
if (($key>0) ? $tp->set("seperator", ".&nbsp;") : $tp->set("seperator", ""));
$tp->parse("locationcrumbrow");
}
$tp->parse("locationcrumb");
// get location info
$result = mysql_query("SELECT location_name, location_info FROM location WHERE location_id='$location_id'");
$row=mysql_fetch_object($result);
$tp->set("location_info", nl2br($row->location_info));
// search subnets for this location
$result = mysql_query("SELECT s.subnet_id, s.subnet_address, s.subnet_mask FROM subnet s INNER JOIN subnetlocation sl ON s.subnet_id=sl.subnet_id WHERE sl.location_id='$location_id'") or die(mysql_error());
for ($i=0;$row=mysql_fetch_object($result);$i++) {
$tp->set("subnet_id", $row->subnet_id);
$tp->set("subnet_address", $row->subnet_address);
$tp->set("subnet_mask", $row->subnet_mask);
$tp->parse("subnetrow");
}
if (($i>0) ? $tp->parse("subnet") : $tp->hide("subnet"));
// search sub-locations for this location
$result = mysql_query("SELECT location_id, location_name FROM location WHERE parent='$location_id' ORDER BY location_name") or die(mysql_error());
for ($i=0;$row=mysql_fetch_object($result);$i++) {
$tp->set("sublocation_id", $row->location_id);
$tp->set("sublocation_name", $row->location_name);
$tp->parse("sublocationrow");
}
if (($i>0) ? $tp->parse("sublocation") : $tp->hide("sublocation"));
// run query
$subnets = $db->db_select($query);
// output
$tp->parse();
$tp->spit();
// count results
$subnet_counter = count($subnets);
include("footer.php");
// counter to tpl
$tp->set("subnet_counter", $subnet_counter);
// any nodes?
if ($subnet_counter>0) {
// get objects
foreach($subnets AS $subnet) {
// send to tpl
$tp->set("subnet_id", $subnet['subnet_id']);
$tp->set("subnet_address", $subnet['subnet_address']);
$tp->set("subnet_mask", $subnet['subnet_mask']);
// parse row
$tp->parse("subnet_row");
}
// parse block
$tp->parse("subnet_table");
} else {
// hide block
$tp->hide("subnet_table");
}
// end page
// output
$tp->parse();
$tp->spit();
// footer
include("footer.php");
?>