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
-->
		
<?php
	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
	$result=mysql_query($query);
	
	$num=mysql_numrows($result);
	
	mysql_close();
	$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... -->
		<tr>
		<td>Barcode: </td><td><?php echo "$barcode" ?></td>
		</tr><tr>
		<td>Description: </td><td><?php echo "$name" ?></td>
		</tr><tr>
		<td>Tested By: </td><td><SELECT id="name" name="name"><option value=pick>Choose Name</option><?php
														$i=0;
														while ($i < $num) {
														$names=mysql_result($result,$i,"name");
														echo '<option value="'.$names.'" ';
															if ($names == $seluser){
															echo ' selected="selected"';
															} else {}
														echo '>'.$names.'</option>';
														$i++;
														}
														?></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. -->
		</tr><tr>
		<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. -->
		</tr><tr>
		<td><input type="submit" value="Submit"></td>
		</tr>
		</form> 
		</table>
		
		
	</body>
<html><!-- HTML Form Section End -->

<?php 
	if ($_POST['cmd'] == 'done') {// Check the form has been submitted
		
		$user=$_POST['name']; //set variables from form data
		$testdate=$_POST['date'];
		$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
			{
				$gotbarcode=$row['barcode'];
			  	$gotname=$row['name'];
				$gotretest=$row['retest'];
				$gotdate=$row['date'];
				$gotuser=$row['user'];
				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 -->

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