<?
Include("Includes/global.inc.php");
checkPermissions(1, 1800);
// Has the form been submitted
if ($btnSubmit) {
$manufacturer = validateText("Manufacturer", $txtManufacturer, 2, 50, TRUE, FALSE);
$model = validateText("Model", $txtModel, 2, 50, TRUE, FALSE);
$description = validateText("Product Name", $txtDescription, 2, 150, FALSE, FALSE);
// are required fields were filled out
if (!$strError) {
// Pick the proper sql statement to query the database
if ($peripheral_pk) {
$sql = "UPDATE peripheral_types SET manufacturer='$manufacturer',model='$model',description='$description' WHERE accountID=$accountID AND peripheral_pk=$peripheral_pk";
$strError = "Record updated successfully.";
} else {
$sql = "INSERT INTO peripheral_types (manufacturer,model,description,accountID) VALUES ('$manufacturer','$model','$description',$accountID)";
$strError = "Record created successfully.";
}
$result = dbquery($sql);
$peripheral_pk = "";
$manufacturer = "";
$model = "";
$description = "";
}
// If we are deleting, delete the peripherals tied to the asset
} elseif ($delete AND $sessionSecurity < 1) {
$sql = "DELETE FROM peripherals WHERE peripheral_fk=$peripheral_pk AND accountID=$accountID";
$result = dbquery($sql);
$sql = "DELETE FROM peripheral_types WHERE peripheral_pk=$peripheral_pk AND accountID=$accountID";
$result = dbquery($sql);
$strError = "Record deleted successfully.";
}
// If you're editing load the vars
if ($peripheral_pk) {
$sql = "SELECT * FROM peripheral_types WHERE peripheral_pk=$peripheral_pk AND accountID=$accountID";
$result = dbquery($sql);
$this = mysql_fetch_array($result);
$peripheral_pk = $this["peripheral_pk"];
$manufacturer = $this["manufacturer"];
$model = $this["model"];
$description = $this["description"];
}
if ($peripheral_pk) {
$titlePrefix = "Edit";
$addInstead = " (<a href='admin_peripheral_types.php'>Add new type</a>)";
} else {
$titlePrefix = "Add";
}
writeHeader("$titlePrefix a Peripheral Type");
declareError(TRUE);
?>
<font color='ff0000'>*</font> Indicates a required field.<p>
<FORM METHOD="post" ACTION="<? echo $PHP_SELF?>">
<table border='0' cellpadding='1' cellspacing='0' width='400'>
<tr>
<td width='100'><font color='ff0000'>*</font> Manufacturer:
<INPUT TYPE="hidden" NAME="peripheral_pk" VALUE="<? echo $peripheral_pk; ?>">
</td>
<td width='300'><INPUT SIZE="30" MAXLENGTH="50" TYPE="Text" NAME="txtManufacturer" VALUE="<? echo antiSlash($manufacturer); ?>"></td>
</tr>
<tr>
<td width='100'><font color='ff0000'>*</font> Model:</td>
<td width='300'><INPUT SIZE="30" MAXLENGTH="50" TYPE="Text" NAME="txtModel" VALUE="<? echo antiSlash($model); ?>"></td>
</tr>
<tr>
<td width='100'><font color='ff0000'>*</font> Description:</td>
<td width='300'><INPUT SIZE="30" MAXLENGTH="70" TYPE="Text" NAME="txtDescription" VALUE="<? echo antiSlash($description); ?>"></td>
</tr>
<tr><td colspan='2'> </td></tr>
<tr><td colspan='2'><INPUT TYPE="submit" NAME="btnSubmit" VALUE="Enter Information"> </td></tr>
</table>
</FORM>
<?
// display all known peripheral types
echo "<b>Peripheral Types in Inventory</b> $addInstead<p>";
$hw = "SELECT * FROM peripheral_types WHERE accountID=$accountID ORDER BY manufacturer ASC";
$sql = dbquery($hw);
$results = mysql_num_rows($sql);
if ($results > 0) {
?>
<TABLE border='0' cellpadding='4' cellspacing='0'>
<TR class='title'>
<TD><b>Manufacturer</b> </TD>
<TD><b>Model</b> </TD>
<TD><b>Description</b> </TD>
<TD><b>Action</b></TD>
<?
while ($result = mysql_fetch_array($sql)) {
$peripheral_pk = $result['peripheral_pk'];
$manufacturer = $result['manufacturer'];
$model = $result['model'];
$description = $result['description'];
?>
<TR class='<? echo alternateRowColor(); ?>'>
<TD><i><? echo $manufacturer; ?></i> </TD>
<TD><? echo $model; ?> </TD>
<TD><? echo $description; ?> </TD>
<TD>
<A HREF="admin_peripheral_types.php?peripheral_pk=<? echo $peripheral_pk; ?>">Edit</A>
<? If ($sessionSecurity < 1) { ?>
<A HREF="admin_peripheral_types.php?peripheral_pk=<? echo $peripheral_pk; ?>&delete=yes" onClick="return warn_on_submit('Are you sure you want to delete this peripheral type? All instances of it will disappear (permanently) from the database.');">Delete</A>
<? } ?>
</TD>
</TR>
<?
}
?></table><?
}
writeFooter();
?>