You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.5 KiB
104 lines
2.5 KiB
<?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");
|
|
|
|
$location_id = sanitize($_GET['location_id']);
|
|
|
|
include("header.php");
|
|
|
|
// location
|
|
$query = "SELECT
|
|
location_name,
|
|
location_parent,
|
|
location_info,
|
|
location_sort
|
|
FROM
|
|
location
|
|
WHERE
|
|
location_id=" . $location_id;
|
|
|
|
$location = $db->db_select($query);
|
|
|
|
$location_parent = $location[0]['location_parent'];
|
|
|
|
$smarty->assign("location_id", $location_id);
|
|
$smarty->assign("location_name", $location[0]['location_name']);
|
|
$smarty->assign("location_info", $location[0]['location_info']);
|
|
$smarty->assign("location_sort", $location[0]['location_sort']);
|
|
|
|
// parent location
|
|
$query = "SELECT
|
|
location_id,
|
|
location_name,
|
|
location_parent
|
|
FROM
|
|
location
|
|
WHERE
|
|
location_id != " . $location_id . "
|
|
ORDER BY
|
|
location_name";
|
|
|
|
$locations = $db->db_select($query);
|
|
|
|
$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'];
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
$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");
|
|
|
|
include("footer.php");
|
|
?>
|
|
|