Make use of Yapter Template Engine

This commit is contained in:
2023-02-13 09:31:40 +01:00
parent 7322231d3e
commit 8d00ee5e1b
100 changed files with 4804 additions and 2666 deletions

View File

@@ -1,129 +1,41 @@
<?php
include("header.php");
// display only if admin
if($_SESSION['suser_level'] >= 2) {
// check for submit
if ($_SERVER['REQUEST_METHOD']=="POST" ) {
$node_id = $_POST['node_id'];
$subnet_id = $_POST['subnet_id'];
$mac = strip_mac($_POST['mac']);
$dns1 = $_POST['dns1'];
$dns2 = $_POST['dns2'];
$node_info = $_POST['node_info'];
mysql_query("UPDATE node SET subnet_id='$subnet_id', mac='$mac', dns1='$dns1', dns2='$dns2', node_info='$node_info' WHERE node_id='$node_id'") or die(mysql_error());
header_location("nodeview.php?node_id=" . $node_id);
}
// get id
$node_id = $_GET['node_id'];
// get node info
$result = mysql_query("SELECT a.asset_name, n.ip, n.mac, n.dns1, n.dns2, n.subnet_id, n.node_info FROM asset a, node n WHERE node_id='$node_id' AND a.asset_id=n.asset_id");
while ($row = mysql_fetch_object($result)) {
$ip = $row->ip;
$subnet_id = $row->subnet_id;
$mac = $row->mac;
$dns1 = $row->dns1;
$dns2 = $row->dns2;
$node_info = $row->node_info;
$asset_name = $row->asset_name;
}
?>
// set template
$tp = new Template("tpl/nodeedit.tpl");
<form method="POST" action="nodeedit.php">
<input type="hidden" name="node_id" value="<?php echo $node_id; ?>">
<table border="0">
<tr>
<td colspan="2">
<b>Edit node:</b><br>
</td>
</tr>
<tr>
<td>
Asset:
</td>
<td>
<?php echo $asset_name; ?>
</td>
</tr>
<tr>
<td>
IP Address:
</td>
<td>
<?php echo $ip; ?>
</td>
</tr>
<tr>
<td>
Subnet:<br>
</td>
<td>
<select name="subnet_id">
<?php
$result = mysql_query("SELECT subnet_id, subnet_address, subnet_mask FROM subnet ORDER BY INET_ATON(subnet_address)");
while ($row = mysql_fetch_object($result)) {
if ($row->subnet_id==$subnet_id) {
$selected = ' selected';
} else {
$selected = '';
}
echo '<option value="' . $row->subnet_id . '" ' . $selected . '>' . $row->subnet_address . '/' . $row->subnet_mask . '</option>';
}
?>
</select>
</td>
<td>
*
</td>
</tr>
<tr>
<td>
MAC Address:
</td>
<td>
<input type="text" name="mac" value="<?php echo $mac; ?>">
</td>
</tr>
<tr>
<td>
DNS name:
</td>
<td>
<input type="text" name="dns1" value="<?php echo $dns1; ?>">
</td>
</tr>
<tr>
<td>
DNS alias:
</td>
<td>
<input type="text" name="dns2" value="<?php echo $dns2; ?>">
</td>
</tr>
<tr>
<td>
Node info:
</td>
<td>
<textarea name="node_info"><?php echo $node_info; ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="Submit"><input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
<?php
// end display only if admin
// set language variables
$tp->setvars($lang);
// get node info
$result = mysql_query("SELECT a.asset_name, n.ip, n.mac, n.dns1, n.dns2, n.subnet_id, n.node_info FROM asset a, node n WHERE node_id='$node_id' AND a.asset_id=n.asset_id") or die(mysql_error());
$row = mysql_fetch_object($result);
$subnet_id = $row->subnet_id;
$tp->set("node_id", $node_id);
$tp->set("asset_name", $row->asset_name);
$tp->set("ip", $row->ip);
$tp->set("mac", write_mac($row->mac));
$tp->set("dns1", $row->dns1);
$tp->set("dns2", $row->dns2);
$tp->set("node_info", nl2br($row->node_info));
// get subnet info
$result = mysql_query("SELECT subnet_id, subnet_address, subnet_mask FROM subnet ORDER BY INET_ATON(subnet_address)") or die(mysql_error());
for ($i=0;$row=mysql_fetch_object($result);$i++) {
if (($row->subnet_id==$subnet_id) ? $tp->set("selected", "selected") : $tp->set("selected", ""));
$tp->set("subnet_id", $row->subnet_id);
$tp->set("subnet_address", $row->subnet_address);
$tp->set("subnet_mask", $row->subnet_mask);
$tp->parse("subnetrow");
}
if (($i>0) ? $tp->parse("subnet") : $tp->hide("subnet"));
// output
$tp->parse();
$tp->spit();
include("footer.php");
?>