<?
Include("Includes/global.inc.php");
checkPermissions(1, 1800);
// Has the form been submitted
if ($btnSubmit) {
// are required fields were filled out
$type_desc = validateText("Description", $txtDesc, 2, 40, TRUE, FALSE);
$strProcessor = validateText("Processor", $txtProcessor, 2, 40, TRUE, FALSE);
$strHD = validateText("Hard drive", $txtHD, 2, 40, FALSE, FALSE);
$strGraphics = validateText("Graphics card", $txtGraphics, 2, 40, FALSE, FALSE);
$strRAM = validateText("RAM", $txtRAM, 2, 40, TRUE, FALSE);
$strCD = validateText("CD/DVD", $txtCD, 2, 40, FALSE, FALSE);
$strRemovable = validateText("Removable drive", $txtRemovable, 2, 40, FALSE, FALSE);
$strSound = validateText("Sound", $txtSound, 2, 40, FALSE, FALSE);
$strSpeakers = validateText("Speakers", $txtSpeakers, 2, 40, FALSE, FALSE);
$strOther1 = validateText("Other 1", $txtOther1, 2, 40, FALSE, FALSE);
$strOther2 = validateText("Other 2", $txtOther2, 2, 40, FALSE, FALSE);
if (!$strError) {
// Pick the proper sql statement to query the database
if ($id) {
$strSQL = "UPDATE hw_types SET type_desc='$type_desc', processor='$strProcessor', HD='$strHD', graphics='$strGraphics', RAM='$strRAM', cd_dvd='$strCD', removable='$strRemovable', soundcard='$strSound', speakers='$strSpeakers', other1='$strOther1', other2='$strOther2' WHERE accountID=$accountID AND type_pk=$id";
$strError = "Record updated successfully.";
} else {
$strSQL = "INSERT INTO hw_types (type_desc, processor, HD, graphics, RAM, cd_dvd, removable, soundcard, speakers, other1, other2, accountID) VALUES ('$type_desc', '$strProcessor', '$strHD', '$strGraphics', '$strRAM', '$strCD', '$strRemovable', '$strSound', '$strSpeakers', '$strOther1', '$strOther2', $accountID)";
$strError = "Record created successfully.";
}
$result = dbquery($strSQL);
$id = "";
$type_desc = "";
$strProcessor = "";
$strHD = "";
$strGraphics = "";
$strRAM = "";
$strCD = "";
$strRemovable = "";
$strSound = "";
$strSpeakers = "";
$strOther1 = "";
$strOther2 = "";
}
} elseif ($delete AND $sessionSecurity < 1) {
$strSQL = "DELETE FROM hardware WHERE type=$id AND accountID=$accountID";
$result = dbquery($strSQL);
$strSQL = "DELETE FROM hw_types WHERE type_pk=$id AND accountID=$accountID";
$result = dbquery($strSQL);
$strError = "Record deleted successfully.";
}
// If you're editing load the vars
if ($id && !$strError) {
$strSQL = "SELECT * FROM hw_types WHERE type_pk=$id AND accountID=$accountID";
$result = dbquery($strSQL);
$row = mysql_fetch_array($result);
$id = $row["type_pk"];
$type_desc = $row["type_desc"];
$strHD = $row["HD"];
$strGraphics = $row["graphics"];
$strCD = $row["cd_dvd"];
$strRemovable = $row["removable"];
$strSound = $row["soundcard"];
$strSpeakers = $row["speakers"];
$strProcessor = $row["processor"];
$strRAM = $row["RAM"];
$strOther1 = $row["other1"];
$strOther2 = $row["other2"];
}
if ($id) {
$titlePrefix = "Edit";
$addInstead = " (<a href='admin_hw_types.php'>Add new type</a>)";
} else {
$titlePrefix = "Add";
}
writeHeader("$titlePrefix a System Type");
declareError(TRUE);
?>
<font color='ff0000'>*</font> Indicates a required field.<p>
<FORM METHOD="post" ACTION="<? echo $PHP_SELF?>">
<table border='0' width='100%'>
<tr>
<td width='110'><font color='ff0000'>*</font> Description:</td>
<td>
<INPUT TYPE="hidden" NAME="id" VALUE="<? echo $id; ?>">
<INPUT SIZE="30" MAXSIZE="40" TYPE="Text" NAME="txtDesc" VALUE="<? echo antiSlash($type_desc); ?>">
</td>
</tr>
<tr>
<td width='110'><font color='ff0000'>*</font> Processor:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtProcessor" VALUE="<? echo antiSlash($strProcessor); ?>"></td>
</tr>
<tr>
<td width='110'>Hard drive:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtHD" VALUE="<? echo antiSlash($strHD); ?>"></td>
</tr>
<tr>
<td width='110'>Graphics card:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtGraphics" VALUE="<? echo antiSlash($strGraphics); ?>"></td>
</tr>
<tr>
<td width='110'><font color='ff0000'>*</font> RAM:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtRAM" VALUE="<? echo antiSlash($strRAM); ?>"></td>
</tr>
<tr>
<td width='110'>CD/DVD drive:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtCD" VALUE="<? echo antiSlash($strCD); ?>"></td>
</tr>
<tr>
<td width='110'>Removable drive:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtRemovable" VALUE="<? echo antiSlash($strRemovable); ?>"></td>
</tr>
<tr>
<td width='110'>Sound card:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtSound" VALUE="<? echo antiSlash($strSound); ?>"></td>
</tr>
<tr>
<td width='110'>Speakers:</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtSpeakers" VALUE="<? echo antiSlash($strSpeakers); ?>"></td>
</tr>
<tr>
<td width='110'>Other (1):</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtOther1" VALUE="<? echo antiSlash($strOther1); ?>"></td>
</tr>
<tr>
<td width='110'>Other (2):</td>
<td><INPUT SIZE="30" MAXLENGTH="40" TYPE="Text" NAME="txtOther2" VALUE="<? echo antiSlash($strOther2); ?>"></td>
</tr>
<tr><td colspan='2'> </td></tr>
<tr><td colspan='2'><INPUT TYPE="submit" NAME="btnSubmit" VALUE="Enter Information"> </td></tr>
</table>
</FORM>
<?
echo "<b>System Types in Inventory</b> $addInstead <p>\n";
$strSQL = "SELECT type_pk, type_desc, processor FROM hw_types WHERE accountID=$accountID
ORDER BY type_desc ASC";
$result = dbquery($strSQL);
$numResults = mysql_num_rows($result);
if ($numResults > 0) {
?>
<table border='0' cellpadding='4' cellspacing='0'>
<TR class='title'>
<TD><b>Description</b> </TD>
<TD><b>Processor</b> </TD>
<TD><b>Action</b></TD></TR>
<?
while ($row2 = mysql_fetch_array($result)) {
$type_pk = $row2['type_pk'];
$type_desc = $row2['type_desc'];
$processor = $row2['processor'];
?>
<TR class='<? echo alternateRowColor(); ?>'>
<TD><?=$type_desc;?> </TD>
<TD><?=$processor;?> </TD>
<TD>
<A HREF="admin_hw_types.php?id=<? echo $type_pk; ?>">Edit</A>
<? If ($sessionSecurity < 1) { ?>
<A HREF="admin_hw_types.php?id=<? echo $type_pk; ?>&delete=yes" onClick="return warn_on_submit('Are you sure you want to delete this system type? All instances of it in the database will be permanently deleted...');">Delete</A>
<? } ?>
</TD>
</TR>
<?
}
echo "</table>";
}
writeFooter();
?>