Location: PHPKode > projects > PAT and Inventory Management System > m/inventory/view/index2.php
<!--
	Pat and Inventory Management System
	Version 0.2
	Created by Tom Dyer
	Last edited by Tom Dyer 11/9/09
	Item Enquiry
-->
<?php
session_start();	// This connects to the existing session. Allows sharing of variables between pages for a smoother user experience
$directory = $_SESSION['docroot'];
include_once $directory.'/config.php';
?>
<html>
	<title>PIMS | Item Enquiry</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h4>Item Enquiry</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>
		<tr>
		<td>Barcode: </td><td><input type="text" name = "barcode"></td>
		</tr><tr>
		<td><input type="submit" value="Submit"></td>
		</tr>
		</form> 
		</table>
		<br>
		
		
		<?php
		if ($_POST['cmd'] == 'done') {	//Check if form has been submitted
			
			$barcode = $_POST['barcode'];
			$barcode= (int)$barcode; 	// Remove text and/or leading zeros
			
			session_start();	// This connects to the existing session
			
			if(empty($barcode))			//Check that a barcode has been entered
				{
					echo "Please enter a Barcode";
					echo '<br><hr width="100%" /><a href="..">Back</a><br><a href="/">Home</a><br>';
					die;	//Stop if no barcode
				}			//Close barcode check
			mysql_connect(localhost,$username,$password);	//Connect to database
			@mysql_select_db($database) or die( "Unable to select database");
			$bsearch = mysql_query("SELECT * FROM equipment WHERE barcode='$barcode'");	//Get data for set barcode
	
			while($row = mysql_fetch_array($bsearch))	//Start while loop
				{
					$gotbarcode=$row['barcode'];
				  	$gotname=$row['name'];
					$gotretest=$row['retest'];
					$gotdate=$row['date'];
					$gotuser=$row['user'];
				}	//Close While Loop
			if(empty($gotname))	//Check if item exists
				{
					echo "$barcode does not exist in the Database.";
					echo '<br><a href="../add/">Add Item</a>';
					echo '<br><hr width="100%" /><a href="..">Back</a><br><a href="/">Home</a><br>';
					die;	//Stop if item does not exist
				}	//Close existance check
			
			$gsearch = mysql_query("SELECT * FROM gigs WHERE barcode='$barcode'");	//Check if item is on a Gig
			while($grow = mysql_fetch_array($gsearch))	//Start While Loop
			{
				$aref=$grow['ref'];	//Set variables from database record
				$bgig=$grow['gig'];
				$bback=$grow['back'];
			
				if(!empty($aref))
				{
					if(empty($bback))
					{
						echo "This Item is currently checked out to: $bgig ";
						$_SESSION['barcode'] = $barcode;
						$bref = $aref;
						$_SESSION['bref'] = $bref;
						echo '. <a href="checkin.php">Check In</a><br /><br />';
					}
				}
			}	//Close Gig check
			
			echo "Description: <strong>$gotname</strong> <br>";	//Print description
			echo "Barcode: $gotbarcode <br>";	//Print barcode
			if(empty($gotretest))	//check if it is a PAT item
				{
					echo "<small>This item does not require PAT Testing</small>";
					echo '<br><hr width="100%" /><a href="..">Back</a><br><a href="/">Home</a><br>';
					die;
				}	//Close PAT check
			if($gotretest == '1')	//Check retest period plurality
				{
					echo "Retest Period: $gotretest year <br>";
				}
				else
				{	
					echo "Retest Period: $gotretest years <br>";
				}	//close plurality check
			if(empty($gotuser))	//check for PAT Test
				{
					echo '<br><FONT COLOR=red><strong>Item has not been PAT Tested</strong></font>';
					echo '<br><hr width="100%" /><a href="..">Back</a><br><a href="/">Home</a><br>';
					die;	//Stop if no test exists
				}	//Close test check
			echo "Tested by: $gotuser <br>";	//Print last user name
			echo "Test Date: $gotdate <br>";	//Print last test date
			
			 
			/*$sub1year = mktime(0,0,0,date("Y")-1,date("m"),date("d"));	//Set variables for date check
			$compdate = date("d/m/Y", $sub1year);*/
			
			$sub1year = date("Y-m-d", strtotime("-$gotretest years"));	//Set variables for date check
			$compdate = $sub1year;//date("d/m/Y", $sub1year);
						
						
			$fail_date = strtotime($compdate);
			$testdatestr = strtotime($gotdate);
			
			if ($fail_date < $testdatestr) //Date Check
				{ 
					echo '<br><FONT COLOR=green><strong>IN DATE</strong></font>'; 
				} 
				else 
				{ 
					echo "<br><FONT COLOR=red><strong>OUT OF DATE</strong></font>"; 
				}	//Close date check
			
		}	//submit check
		?>
		
		<br><hr width="100%" /><a href="all.php">All</a><br><a href="..">Back</a><br><a href="/">Home</a><br>
	</body>
<html>
Return current item: PAT and Inventory Management System