<?php
// Purpose : Allow creation of new qww35 database record.
// Include Configuration File
require_once ('../includes/config.inc');
require_once ('../includes/mysql_connect.php'); // Connect to the database.
// Set the page title and include the HTML header.
$page_title = 'Helpdesk Over Web - Add Asset Record';
include ('../includes/header.html');
// Check if form is submitted or blank.
if (isset($_POST['submit'])) // Check if the form has been submitted.
{
require_once ('../includes/mysql_connect.php'); // Connect to the database.
// Retrieve variable values from form.
$assettag = $_POST['assettag'];
$category = $_POST['category'];
$manufacturer = $_POST['manufacturer'];
$model = $_POST['model'];
$purchasedate = $_POST['purchasedate'];
$installdate = $_POST['installdate'];
$user = $_POST['user'];
$spec = $_POST['spec'];
$remarks = $_POST['remarks'];
// Check mandatory fields are complete.
if($assettag == NULL)
echo "<H4><FONT COLOR='red'>Error - No Asset Tag specified!</FONT></H4>";
if($category == NULL)
echo "<H4><FONT COLOR='red'>Error - No Category specified!</FONT></H4>";
if($manufacturer == NULL)
echo "<H4><FONT COLOR='red'>Error - No Manufacturer specified!</FONT></H4>";
if($model == NULL)
echo "<H4><FONT COLOR='red'>Error - No Model specified!</FONT></H4>";
if($spec == NULL)
echo "<H4><FONT COLOR='red'>Error - No Specification given!</FONT></H4>";
// If all OK, insert new user into database.
if($assettag && $category && $manufacturer && $model && $spec)
{
$query = "INSERT INTO assets (AssetTag, Category, Manufacturer, Model, PurchaseDate, InstallDate, User, Specification, Remarks) VALUES ('$assettag', '$category', '$manufacturer', '$model', '$purchasedate', '$installdate', '$user', '$spec', '$remarks');";
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
echo ("<H2>Operation Complete.</H2>");
echo ("<H4>Asset record for " . $manufacturer . " " . $model . " (" . $assettag . ") created.</H4>");
echo ("<H4><A HREF='assetadmin.php'>[ Asset Database Administration ]</A></H4>");
// Include standard HTML footer
include ('../includes/footer.html');
exit();
}
}
// Output text/instructions for user.
echo "<H1>Asset Database</H1>";
echo "<H3>Create New Asset Record</H3>";
echo "<P>Enter asset details in the fields below.</P>";
echo "<TABLE WIDTH='500' PADDING='2' SPACING='2'>";
echo "<form action='newasset.php' method='post'>";
echo "<TR><TD ALIGN='RIGHT'><B>Asset Tag:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD> <input type='text' name='assettag' size='20' maxlength='18' class='textbox'></TD></TR>";
echo "<TR><TD ALIGN='RIGHT'><B>Category:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD> <SELECT NAME='category'>";
$assetsql = "SELECT HWCategoryText FROM hwcategories ORDER BY HWCategoryText;";
$assetlist = mysql_query($assetsql)
or die("Invalid query: " . mysql_error());
while($i = mysql_fetch_row($assetlist))
{
echo "<OPTION >$i[0]</OPTION>";
}
echo "</SELECT></TD></TR>";
echo "<TR><TD ALIGN='RIGHT'><B>Manufacturer:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD> <input type='text' name='manufacturer' size='60' maxlength='50' class='textbox'></TD></TR>";
echo "<TR><TD ALIGN='RIGHT'><B>Model:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD> <input type='text' name='model' size='60' maxlength='50' class='textbox'></TD></TR>";
echo "<TR><TD ALIGN='RIGHT'><B>Purchase Date:</B></TD><TD> <input type='text' name='purchasedate' size='18' class='textbox'> (yyyy-mm-dd format)</TD></TR>";
echo "<TR><TD ALIGN='RIGHT'><B>Install Date:</B></TD><TD> <input type='text' name='installdate' size='18' class='textbox'> (yyyy-mm-dd format)</TD></TR>";
echo "<TR><TD ALIGN='RIGHT'><B>User:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD> <SELECT NAME='user'>";
$assetsql = "SELECT UserID, UserFirstname, UserSurname, Dept FROM users ORDER BY UserID;";
$assetlist = mysql_query($assetsql)
or die("Invalid query: " . mysql_error());
while($i = mysql_fetch_row($assetlist))
{
echo "<OPTION VALUE='$i[0]'>$i[0] - $i[1] $i[2] ($i[3])</OPTION>";
}
echo "</SELECT></TD></TR>";
echo "<TR><TD><B>Specification:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD> <textarea name='spec' cols='60' rows='5'></textarea></TD></TR>";
echo "<TR><TD><B>Comments:</B></TD><TD> <textarea name='remarks' cols='60' rows='5'></textarea></TD></TR>";
echo "<TR><TD ALIGN='CENTER' COLSPAN='2'><input type='submit' value=' Create Asset Record ' name='submit'> <input type='reset' value='Clear'></TD></TR>";
echo "</TABLE></FORM>";
echo "<H4>[ <A HREF='assetadmin.php'>Asset Database Administration</A> ]</H4>";
// Include standard HTML footer
include ('../includes/footer.html');
?>