Make use of Yapter Template Engine

This commit is contained in:
2023-02-13 09:31:40 +01:00
parent 7322231d3e
commit 8d00ee5e1b
100 changed files with 4804 additions and 2666 deletions

View File

@@ -1,48 +1,69 @@
<?php
include("header.php");
function display_subnet ($location_id) {
$subnet = '';
$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' ORDER BY INET_ATON(subnet_address)");
while ($row = mysql_fetch_object($result)) {
$subnet .= '<a href="subnetview.php?subnet_id='. $row->subnet_id . '">' . $row->subnet_address . '/' . $row->subnet_mask . '</a><br>';
}
return $subnet;
// set template
$tp = new Template("tpl/location.tpl");
// set language variables
$tp->setvars($lang);
// create array with parent index and location names
$parents = array();
$location_names = 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->parent][] = $row->location_id;
}
// displaysubnet link (or not)
if (isset($_GET['displaysubnet'])) {
$displaysubnetlink = '<a href="location.php">(hide subnets)</a>';
} else {
$displaysubnetlink = '<a href="location.php?displaysubnet">(display subnets)</a>';
}
// "menu"
function display_children($parent, $level) {
$result = mysql_query("SELECT location_id, location_name FROM location WHERE parent='$parent' ORDER BY location_name");
while ($row = mysql_fetch_object($result)) {
if (isset($_GET['displaysubnet'])) {
$displaysubnet = display_subnet($row->location_id);
// look for parents and create a new array for every child
function location($parents, $parent = 0) {
$children = array();
foreach ($parents[$parent] as $child) {
if (isset($parents[$child])) {
// element has children
$children[$child] = location($parents, $child);
} else {
$displaysubnet = '';
// no children, set NULL
$children[$child] = NULL;
}
echo '<tr><td>' . str_repeat('&nbsp;&nbsp;&nbsp;',$level) . '<a href="locationview.php?location_id=' . $row->location_id . '">' . $row->location_name . '</a></td><td>&nbsp;</td><td>' . $displaysubnet . '</td></tr>';
display_children($row->location_id, $level+1);
}
return $children;
}
?>
<table border="0">
<tr>
<td>
<b>Location:</b> <?php echo $displaysubnetlink; ?>
</td>
</tr>
<?php display_children('',0); ?>
</table>
<?php
// recursive children check to template
function checkchildren ($array, $level) {
global $tp;
global $location_names;
foreach ($array as $location_id=>$val) {
if($val != "") {
$tp->set("location_id", $location_id);
$tp->set("location_name", $location_names[$location_id]);
$tp->set("nbsp", str_repeat("&nbsp;&nbsp;&nbsp;",$level));
$tp->parse("locationrow");
checkchildren($val, $level+1);
} else {
$tp->set("location_id", $location_id);
$tp->set("location_name", $location_names[$location_id]);
$tp->set("nbsp", str_repeat("&nbsp;&nbsp;&nbsp;",$level));
$tp->parse("locationrow");
}
}
$tp->parse("location");
$tp->clear("location");
}
// assemble the tree
$tree = location($parents);
// check for values and build template
checkchildren($tree, 0);
// output
$tp->parse();
$tp->spit();
include("footer.php");
?>