Changes adopted from version 0.5
This commit is contained in:
192
locationedit.php
192
locationedit.php
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2008 Wietse Warendorff
|
||||
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
|
||||
@@ -20,56 +20,148 @@
|
||||
or contact me at wietsew@users.sourceforge.net
|
||||
*****************************************************************************/
|
||||
|
||||
// includes
|
||||
include("includes.php");
|
||||
|
||||
// get id
|
||||
$location_id = $_GET['location_id'];
|
||||
|
||||
// check authorisation
|
||||
$auth = auth("location", $config_auth_locationedit, $location_id);
|
||||
|
||||
// start output
|
||||
include("header.php");
|
||||
|
||||
// set template
|
||||
$tp = new Template("tpl/locationedit.tpl");
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
// check for submit
|
||||
if ($_SERVER['REQUEST_METHOD']=="POST" ) {
|
||||
$location_id = $_POST['location_id'];
|
||||
$location_name = $_POST['location_name'];
|
||||
$parent = $_POST['parent'];
|
||||
$location_info = $_POST['location_info'];
|
||||
mysql_query("UPDATE location SET location_name='$location_name', parent='$parent', location_info='$location_info' WHERE location_id='$location_id'") or die(mysql_error());
|
||||
// start page
|
||||
// includes
|
||||
include("includes.php");
|
||||
|
||||
header_location("locationview.php?location_id=" . $location_id);
|
||||
}
|
||||
|
||||
// get current information
|
||||
$result = mysql_query("SELECT location_name, parent, location_info FROM location WHERE location_id='$location_id'") or die(mysql_error());
|
||||
$row = mysql_fetch_object($result);
|
||||
$parent = $row->parent;
|
||||
$tp->set("location_id", $location_id);
|
||||
$tp->set("location_name", $row->location_name);
|
||||
$tp->set("location_info", $row->location_info);
|
||||
|
||||
// get parent info
|
||||
$result = mysql_query("SELECT location_id, location_name FROM location ORDER BY location_name");
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
if (($row->location_id==$parent) ? $tp->set("selected", "selected") : $tp->set("selected", ""));
|
||||
$tp->set("parent_id", $row->location_id);
|
||||
$tp->set("parent_name", $row->location_name);
|
||||
$tp->parse("parentrow");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("parent") : $tp->hide("parent"));
|
||||
// get id
|
||||
$location_id = sanitize($_GET['location_id']);
|
||||
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
// start output
|
||||
include("header.php");
|
||||
|
||||
// set template
|
||||
$tp = new Template("tpl/locationedit.tpl", $config_yapter_error);
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
include("footer.php");
|
||||
// setup location
|
||||
// build query
|
||||
$query = "SELECT
|
||||
location.location_name AS location_name,
|
||||
location.location_parent AS location_parent,
|
||||
location.location_info AS location_info
|
||||
FROM
|
||||
location
|
||||
WHERE
|
||||
location.location_id=" . $location_id;
|
||||
|
||||
// run query
|
||||
$location = $db->db_select($query);
|
||||
|
||||
// get parent
|
||||
$location_parent = $location[0]['location_parent'];
|
||||
|
||||
// send to tpl
|
||||
$tp->set("location_id", $location_id);
|
||||
$tp->set("location_name", $location[0]['location_name']);
|
||||
$tp->set("location_info", $location[0]['location_info']);
|
||||
|
||||
// setup parent location
|
||||
// look for locations
|
||||
// build query
|
||||
$query = "SELECT
|
||||
location.location_id AS location_id,
|
||||
location.location_name AS location_name,
|
||||
location.location_parent AS location_parent
|
||||
FROM
|
||||
location
|
||||
ORDER BY
|
||||
location.location_name";
|
||||
|
||||
// run query
|
||||
$locations = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$location_counter = count($locations);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("location_counter", $location_counter);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// to tpl
|
||||
// recursive children check to template
|
||||
function checkchildren($locations, $level) {
|
||||
// include template class
|
||||
global $tp;
|
||||
|
||||
// import location names
|
||||
global $location_names;
|
||||
|
||||
// import current id
|
||||
global $location_id;
|
||||
|
||||
// import parent
|
||||
global $location_parent;
|
||||
|
||||
// action!
|
||||
foreach ($locations as $parent=>$child) {
|
||||
// send vars to template
|
||||
$tp->set("parentlocation_id", $parent);
|
||||
$tp->set("parentlocation_name", $location_names[$parent]);
|
||||
$tp->set("nbsp", str_repeat("- ",$level));
|
||||
|
||||
// set parent selected
|
||||
if($parent==$location_parent) {
|
||||
$tp->set("parentlocation_selected", "selected");
|
||||
} else {
|
||||
$tp->set("parentlocation_selected", "");
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("parentlocation_row");
|
||||
|
||||
// any children?
|
||||
if($child != "") {
|
||||
// yes, so do the loop again!
|
||||
checkchildren($child, $level+1);
|
||||
}
|
||||
}
|
||||
|
||||
// parse and clear for the next round
|
||||
$tp->parse("parentlocation_table");
|
||||
$tp->clear("parentlocation_table");
|
||||
}
|
||||
|
||||
// assemble the tree
|
||||
$tree = location($parents);
|
||||
|
||||
// check for values and build template
|
||||
checkchildren($tree, 0);
|
||||
|
||||
// end page
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
|
||||
// end output
|
||||
include("footer.php");
|
||||
?>
|
||||
Reference in New Issue
Block a user