75 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
| <?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_parent = sanitize($_GET['location_parent']);
 | |
| 
 | |
| 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";
 | |
| $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'];
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // 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;
 | |
| }
 | |
| 		
 | |
| // 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("locationadd.tpl");
 | |
| 		
 | |
| include("footer.php");
 | |
| ?>
 |