Make use of Yapter Template Engine
This commit is contained in:
113
assetedit.php
113
assetedit.php
@@ -1,96 +1,37 @@
|
||||
<?php
|
||||
include("header.php");
|
||||
|
||||
// display only if admin
|
||||
if($_SESSION['suser_level'] >= 2) {
|
||||
|
||||
// check for submit
|
||||
if ($_SERVER['REQUEST_METHOD']=="POST" ) {
|
||||
$asset_id = $_POST['asset_id'];
|
||||
$asset_name = $_POST['asset_name'];
|
||||
$hostname = $_POST['hostname'];
|
||||
$assetclass_id = $_POST['assetclass_id'];
|
||||
$asset_info = $_POST['asset_info'];
|
||||
mysql_query("UPDATE asset SET asset_name='$asset_name', hostname='$hostname', assetclass_id='$assetclass_id', asset_info='$asset_info' WHERE asset_id='$asset_id'") or die(mysql_error());
|
||||
|
||||
header_location("assetview.php?asset_id=" . $asset_id);
|
||||
}
|
||||
|
||||
// get id
|
||||
$asset_id = $_GET['asset_id'];
|
||||
|
||||
// get current information
|
||||
$result = mysql_query("SELECT asset_name, hostname, assetclass_id, asset_info FROM asset WHERE asset_id='$asset_id'");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
$asset_name = $row->asset_name;
|
||||
$hostname = $row->hostname;
|
||||
$assetclass_id = $row->assetclass_id;
|
||||
$asset_info = $row->asset_info;
|
||||
}
|
||||
?>
|
||||
// set template
|
||||
$tp = new Template("tpl/assetedit.tpl");
|
||||
|
||||
<form method="POST" action="assetedit.php">
|
||||
<input type="hidden" name="asset_id" value="<?php echo $asset_id; ?>">
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<b>Edit asset:</b><br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Asset name:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="asset_name" value="<?php echo $asset_name; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Hostname:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="hostname" value="<?php echo $hostname; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Asset class:
|
||||
</td>
|
||||
<td>
|
||||
<select name="assetclass_id">
|
||||
<?php
|
||||
$result = mysql_query("SELECT assetclass_id, assetclass_name FROM assetclass ORDER BY assetclass_name");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
if ($row->assetclass_id==$assetclass_id) {
|
||||
$selected = 'selected';
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
echo '<option value="' . $row->assetclass_id . '" ' . $selected . '>' . $row->assetclass_name . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Asset info:
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="asset_info"><?php echo $asset_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 asset information
|
||||
$result = mysql_query("SELECT asset_name, hostname, assetclass_id, asset_info FROM asset WHERE asset_id='$asset_id'") or die(mysql_error());
|
||||
$row = mysql_fetch_object($result);
|
||||
$assetclass_id = $row->assetclass_id;
|
||||
$tp->set("asset_id", $asset_id);
|
||||
$tp->set("asset_name", $row->asset_name);
|
||||
$tp->set("hostname", $row->hostname);
|
||||
$tp->set("asset_info", $row->asset_info);
|
||||
|
||||
// get assetclass information
|
||||
$result = mysql_query("SELECT assetclass_id, assetclass_name FROM assetclass ORDER BY assetclass_name") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
if (($row->assetclass_id==$assetclass_id) ? $tp->set("selected", "selected") : $tp->set("selected", ""));
|
||||
$tp->set("assetclass_id", $row->assetclass_id);
|
||||
$tp->set("assetclass_name", $row->assetclass_name);
|
||||
$tp->parse("assetclassrow");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("assetclass") : $tp->hide("assetclass"));
|
||||
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
|
||||
include("footer.php");
|
||||
?>
|
||||
Reference in New Issue
Block a user