diff --git a/locationadd.php b/locationadd.php index fedb3bb..db5c8ba 100644 --- a/locationadd.php +++ b/locationadd.php @@ -16,35 +16,33 @@ include("header.php"); // ************* -$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); diff --git a/locationsubnetadd.php b/locationsubnetadd.php index 78926b6..8e91434 100644 --- a/locationsubnetadd.php +++ b/locationsubnetadd.php @@ -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"); diff --git a/locationsubnetedit.php b/locationsubnetedit.php index 5f15175..213592e 100644 --- a/locationsubnetedit.php +++ b/locationsubnetedit.php @@ -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"); diff --git a/tpl/locationsubnetedit.tpl b/tpl/locationsubnetedit.tpl index a03aa18..a6d4079 100644 --- a/tpl/locationsubnetedit.tpl +++ b/tpl/locationsubnetedit.tpl @@ -1,6 +1,6 @@
- + @@ -28,7 +28,7 @@ {$lang_location_name}
- {$location_name} + {$location->name}