Location: PHPKode > projects > PAT and Inventory Management System > m/a/pat.php
	Pat and Inventory Management System
	Version 0.4
	Created by Tom Dyer
	Last edited by Tom Dyer 11/9/09
	PAT Test
	session_start();	// This connects to the existing session
	$directory = $_SESSION['docroot'];
	include_once '../../config.php';
	$servroot = $_SESSION['servroot'];
	mysql_connect($sqlhost,$username,$password);						//connect to the database
	@mysql_select_db($database) or die( "Unable to select database");
	$query="SELECT * FROM users ORDER BY name ASC";						//get a list of users
	$seluser = $_SESSION['returnuser'];	//if it has not, use the session variable for pre-selected user
	$barcode = $_SESSION['barcode'];
	$name = $_SESSION['name'];
?> <!-- End PHP section 1 -->

<html> <!-- HTML Form Section Start -->
	<title>PIMS | Log a Test</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h4>Log a successful PAT Test</h4></head>
	<body onLoad="document.input.barcode.focus()" LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->

		<table border="0">
		<form action="" method="post" name="input">
		<input type="hidden" name="cmd" value="done"</input><!-- hidden value so that submission of the form can be checked for... -->
		<td>Barcode: </td><td><?php echo "$barcode" ?></td>
		<td>Description: </td><td><?php echo "$name" ?></td>
		<td>Tested By: </td><td><SELECT id="name" name="name"><option value=pick>Choose Name</option><?php
														while ($i < $num) {
														echo '<option value="'.$names.'" ';
															if ($names == $seluser){
															echo ' selected="selected"';
															} else {}
														echo '>'.$names.'</option>';
														?></select></td><!-- Name feild in the form of a drop-down-box. Names found via SQL, and the last entered name is remembered so remains selected. -->
		<td>Test Date<small>(Y-M-D)</small>: </td><td><input id="date" name="date" value="<?php echo date("Y-m-j"); ?>"/></td><!-- Date Feild. Date auto-fills with the current. -->
		<td><input type="submit" value="Submit"></td>
<html><!-- HTML Form Section End -->

	if ($_POST['cmd'] == 'done') {// Check the form has been submitted
		$user=$_POST['name']; //set variables from form data
		$barcode= (int)$barcode; // Remove text and/or leading zeros
		if($user == 'pick') // Check if user has entered a name
				echo "Please select your Name"; // Tell them what they did wrong
				echo '<br><hr width="100%" /><a href="index.php">Back</a><br>'; //Navigation Options
				die; //Stop
		mysql_connect($sqlhost,$username,$password); //reconnect to database
		@mysql_select_db($database) or die( "Unable to select database"); //select database
		$bsearch = mysql_query("SELECT * FROM equipment WHERE barcode='$barcode'"); //get item info

		while($row = mysql_fetch_array($bsearch)) //make item info into variables
				echo $gotbarcode.'<br';
				echo $gotname.'<br';
				echo $gotretest.'<br';
				echo $gotdate.'<br';
				echo $gotuser.'<br';
		$newdate=$testdate;	// Data adjust (if required)
		mysql_query("UPDATE equipment SET date = '$newdate' WHERE barcode = '$barcode'"); //update the date field for the known barcode
		mysql_query("UPDATE equipment SET user = '$user' WHERE barcode = '$barcode'"); //update the user field for the know barcode
		$_SESSION['returnuser'] = $user;
		echo "<strong>$gotname</strong> has been successfully entered. Previously tested by <strong>$gotuser</strong>";
		echo '<script language="javascript">window.location="index.php";</script>';
?> <!-- End PHP -->

<body LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
<br><hr width="100%" /><a href="index.php">Back</a><!-- Navigational Options -->
Return current item: PAT and Inventory Management System