Make use of Yapter Template Engine
This commit is contained in:
160
locationview.php
160
locationview.php
@@ -4,87 +4,101 @@
|
||||
// get id
|
||||
$location_id = $_GET['location_id'];
|
||||
|
||||
// get all info
|
||||
// set template
|
||||
$tp = new Template("tpl/locationview.tpl");
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
// create breadcrumb arrays
|
||||
$parents = array();
|
||||
$location_names = array();
|
||||
$crumbs = array();
|
||||
|
||||
// get location information and insert to the arrays
|
||||
$result = mysql_query("SELECT location_id, location_name, parent FROM location") or die(mysql_error());
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
$location_names[$row->location_id] = $row->location_name;
|
||||
$parents[$row->location_id] = $row->parent;
|
||||
}
|
||||
|
||||
// function to build array with parents
|
||||
function parent($location_id) {
|
||||
// use names index
|
||||
global $parents;
|
||||
global $crumbs;
|
||||
global $location_names;
|
||||
|
||||
// fill array with this value
|
||||
$crumbs[$location_id] = $location_id;
|
||||
if (($parents[$location_id])>0) {
|
||||
// still not on top, so do it again
|
||||
parent($parents[$location_id]);
|
||||
}
|
||||
|
||||
// return the array
|
||||
return $location_id;
|
||||
}
|
||||
|
||||
// build parents
|
||||
parent($location_id);
|
||||
|
||||
// loop array in reverse order and send to template
|
||||
foreach (array_reverse($crumbs) as $key=>$val) {
|
||||
$tp->set("location_id", $val);
|
||||
$tp->set("location_name", $location_names[$val]);
|
||||
if (($key>0) ? $tp->set("seperator", ". ") : $tp->set("seperator", ""));
|
||||
$tp->parse("locationcrumbrow");
|
||||
}
|
||||
$tp->parse("locationcrumb");
|
||||
|
||||
// get location info
|
||||
$result = mysql_query("SELECT location_name, location_info FROM location WHERE location_id='$location_id'");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
$location_info = $row->location_info;
|
||||
}
|
||||
?>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<b>Location name:</b>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo location_name($location_id, ''); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Location info:</b>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo nl2br($location_info); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Subnet(s):</b>
|
||||
</td>
|
||||
<td>
|
||||
$row=mysql_fetch_object($result);
|
||||
$tp->set("location_info", nl2br($row->location_info));
|
||||
|
||||
<?php
|
||||
// search subnets for this location
|
||||
$result = mysql_query("SELECT s.subnet_id, s.subnet_address, s.subnet_mask FROM subnet s INNER JOIN subnetlocation sl ON s.subnet_id=sl.subnet_id WHERE sl.location_id='$location_id'");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
echo '<a href="subnetview.php?subnet_id='. $row->subnet_id . '">' . $row->subnet_address . '/' . $row->subnet_mask . '</a><br>';
|
||||
$result = mysql_query("SELECT s.subnet_id, s.subnet_address, s.subnet_mask FROM subnet s INNER JOIN subnetlocation sl ON s.subnet_id=sl.subnet_id WHERE sl.location_id='$location_id'") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("subnet_id", $row->subnet_id);
|
||||
$tp->set("subnet_address", $row->subnet_address);
|
||||
$tp->set("subnet_mask", $row->subnet_mask);
|
||||
$tp->parse("subnetrow");
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Sub-location(s):</b>
|
||||
</td>
|
||||
<td>
|
||||
if (($i>0) ? $tp->parse("subnet") : $tp->hide("subnet"));
|
||||
|
||||
<?php
|
||||
// search sub-locations for this location
|
||||
$result = mysql_query("SELECT location_id, location_name FROM location WHERE parent='$location_id' ORDER BY location_name");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
echo '<a href="locationview.php?location_id='. $row->location_id . '">' . $row->location_name . '</a><br>';
|
||||
$result = mysql_query("SELECT location_id, location_name FROM location WHERE parent='$location_id' ORDER BY location_name") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("sublocation_id", $row->location_id);
|
||||
$tp->set("sublocation_name", $row->location_name);
|
||||
$tp->parse("sublocationrow");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("sublocation") : $tp->hide("sublocation"));
|
||||
|
||||
// display options
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_assignlocationtosubnet) {
|
||||
$tp->set("location_id", $location_id);
|
||||
$tp->parse("assignlocationtosubnet");
|
||||
} else {
|
||||
$tp->hide("assignlocationtosubnet");
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
// display only if admin
|
||||
if($_SESSION['suser_level'] >= 2) {
|
||||
?>
|
||||
|
||||
<p>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<img src="images/arrow.gif" border="0"><a href="locationedit.php?location_id=<?php echo $location_id; ?>">Modify location</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img src="images/arrow.gif" border="0"><a href="assignlocationtosubnet.php?location_id=<?php echo $location_id; ?>">Assign subnet</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
// end display only if admin
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_locationedit) {
|
||||
$tp->set("location_id", $location_id);
|
||||
$tp->parse("locationedit");
|
||||
} else {
|
||||
$tp->hide("locationedit");
|
||||
}
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_locationdel) {
|
||||
$tp->set("location_id", $location_id);
|
||||
$tp->parse("locationdel");
|
||||
} else {
|
||||
$tp->hide("locationdel");
|
||||
}
|
||||
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
|
||||
include("footer.php");
|
||||
?>
|
||||
Reference in New Issue
Block a user