Fix bugs in location code

master
Thomas Hooge 1 year ago
parent 0696a16030
commit 02b3cfd23f
  1. 43
      locationadd.php
  2. 2
      locationsubnetadd.php
  3. 2
      locationsubnetedit.php
  4. 4
      tpl/locationsubnetedit.tpl

@ -16,35 +16,33 @@ include("header.php");
// ************* <option value="0">{$lang_option_none}</option>
$sql = "SELECT location_id AS id, location_name, location_parent, location_sort
FROM location
ORDER BY location_parent, location_sort, location_name";
$sql = "SELECT location_id AS id, location_name AS name,
location_parent AS parent, location_sort AS sort
FROM location
ORDER BY location_parent, location_sort, location_name";
$sth = $dbh->query($sql);
$locations = $sth->fetchAll();
$location_counter = count($locations);
if ($location_counter > 0) {
foreach ($locations AS $location) {
$location_names[$location['location_id']] = $location['location_name'];
$parents[$location['location_parent']][] = $location['location_id'];
}
if (count($locations) > 0) {
foreach ($locations AS $location) {
$location_names[$location['id']] = $location['name'];
$parents[$location['parent']][] = $location['id'];
}
}
// look for parents
// function to look for parents and create a new array for every child
function location($parents, $parent = 0) {
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;
}
}
return $children;
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;
}
}
return $children;
}
// recursive children check to template
@ -63,8 +61,11 @@ function checkchildren($locations, $level) {
}
$tree = location($parents);
// create tree option list
$location_options = array(0 => '-');
checkchildren($tree, 0);
$smarty->assign("location_options", $location_options);
$smarty->assign("location_parent", $location_parent);

@ -20,7 +20,7 @@ $sth = $dbh->prepare($sql);
$sth->execute([$location_id]);
$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ));
$smarty->assign("subnet_options", $db->options_subnet());
$smarty->assign("subnet_options", db_get_options_subnet());
$smarty->display("locationsubnetadd.tpl");

@ -17,7 +17,7 @@ $sql = "SELECT location_id AS id, location_name AS name
FROM location
WHERE location_id=?";
$sth = $dbh->prepare($sql);
$sth->execute([$zone_id]);
$sth->execute([$location_id]);
$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ));
$smarty->display("locationsubnetedit.tpl");

@ -1,6 +1,6 @@
<form method="POST" action="submit.php">
<input type="hidden" name="redirect" value="locationsubnet">
<input type="hidden" name="location_id" value="{$location_id}">
<input type="hidden" name="location_id" value="{$location->id}">
<table class="title">
<tr>
@ -28,7 +28,7 @@
{$lang_location_name}
</td>
<td class="value">
<a href="locationview.php?location_id={$location_id}">{$location_name}</a>
<a href="locationview.php?location_id={$location->id}">{$location->name}</a>
</td>
</tr>
</table>