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.
109 lines
3.1 KiB
109 lines
3.1 KiB
<?php
|
|
/*****************************************************************************
|
|
IP Reg, a PHP/MySQL IPAM tool
|
|
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
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
For more information, visit http://sourceforge.net/projects/ipreg,
|
|
or contact me at wietsew@users.sourceforge.net
|
|
*****************************************************************************/
|
|
|
|
// start page
|
|
// includes
|
|
include("includes.php");
|
|
|
|
// get id
|
|
$location_parent = sanitize($_GET['location_parent']);
|
|
|
|
// start output
|
|
include("header.php");
|
|
|
|
// set language variables
|
|
$smarty->assign($lang);
|
|
|
|
|
|
// ************* <option value="0">{$lang_option_none}</option>
|
|
|
|
|
|
// start parent
|
|
// look for locations
|
|
// build query
|
|
$query = "SELECT location_id, location_name, location_parent, location_sort
|
|
FROM location
|
|
ORDER BY location_parent, location_sort, location_name";
|
|
|
|
// run query
|
|
$locations = $db->db_select($query);
|
|
|
|
// count results
|
|
$location_counter = count($locations);
|
|
|
|
// 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_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);
|
|
|
|
// end page
|
|
// output
|
|
$smarty->display("locationadd.tpl");
|
|
|
|
// footer
|
|
include("footer.php");
|
|
?>
|