Location: PHPKode > projects > PAT and Inventory Management System > m/a/index.php
<!--
	Pat and Inventory Management System
	Version 0.1
	Created by Tom Dyer
	Last edited by Tom Dyer 07/01/10
	'A' Page
-->

<?php
session_start();	// This connects an existing session	
include_once '../../config.php';
$_SESSION['docroot'] = $directory;
$_SESSION['servroot'] = $servroot;
?>
<html>
	<title>PIMS</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h2>PIMS</h2></head>
	<body onLoad="document.input.barcode.focus()" LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
		Please enter a Barcode
		<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" size="6"></td>
		</tr><tr>
		<td><input type="submit" value="Submit"></td>
		</tr>
		</form> 
		</table>
		<br>
		
		
		<?php
		if ($_POST['cmd'] == 'done' || !empty($_SESSION['barcode'])) {	//Check if form has been submitted
			if(empty($_POST['barcode']))
			{
				$barcode = $_SESSION['barcode'];
			}
			else
			{
				$barcode = $_POST['barcode'];
				$barcode= (int)$barcode; 	// Remove text and/or leading zeros
			}
			
			if(empty($barcode))			//Check that a barcode has been entered
				{
					echo "Please enter a Barcode";
					echo '<br><hr width="100%" /><a href="../">Menu</a><br><a href="../inventory/checkout/">Check Out Gig</a><br><a href="../inventory/checkin/">Check In Gig</a>';
					die;	//Stop if no barcode
				}			//Close barcode check
			mysql_connect($sqlhost,$username,$password);	//Connect to database
			@mysql_select_db($database) or die( 'Sorry, Session Timed out. <a href="../">Start Again</a>');
			$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 "Sorry, $barcode does not exist in the Database.";
					$_SESSION['barcode'] = $barcode;
					echo '<br><a href="add.php">Add Item</a>';
					echo '<br><a href="add_pat.php">Add Item & Log Test</a>';
						$rbarcode = 'r'.$barcode;
						$rsearch = mysql_query("SELECT * FROM equipment WHERE barcode='$rbarcode'");	//Get data for set barcode
		
						while($row = mysql_fetch_array($rsearch))	//Start while loop
						{
							$gotrbarcode=$row['barcode'];
						  	$gotrname=$row['name'];
						}	//Close While Loop
						if(!empty($gotrbarcode))
						{
							echo "<br><br>Barcode was previously '$gotrname', but this item has been retired from service.";
						}
					echo '<br><hr width="100%" /><a href="../">Menu</a><br><a href="../inventory/checkout/">Check Out Gig</a><br><a href="../inventory/checkin/">Check In Gig</a>';
					die;	//Stop if item does not exist
				}	//Close existance check
				
				/////////////////////////////////////////////////////////////////////////////////////////////////////////////
			//// STANDARD NAMING ENFORCMENT /////////////////////////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////
			$changedsearch = mysql_query("SELECT * FROM namechanged WHERE barcode='$barcode'");	//Get data for set barcode
			while($changerow = mysql_fetch_array($changedsearch))	//Start while loop
			{
				$changedbarcode=$changerow['barcode'];
			}	//Close While Loop
			if(empty($changedbarcode))
			{
				$std1search = mysql_query("SELECT * FROM equipment WHERE barcode='$barcode'");	//Get data for set barcode
				while($std1row = mysql_fetch_array($std1search))	//Start while loop
				{
					$std1name=$std1row['name'];
				}	//Close While Loop
				$std2search = mysql_query("SELECT * FROM names");	//Get data for set barcode
				$matches = 0;
				while($std2row = mysql_fetch_array($std2search))	//Start while loop
				{
					$std2name=$std2row['name'];
					if($std1name == $std2name)
					{
						$matches = 1;
					}
				}	//Close While Loop
				if($matches == 0)
				{
					$_SESSION['barcode'] = $barcode;
					$_SESSION['description'] = $std1name;
					Header("Location: changename.php");
				}
			}
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////
			
			$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'];
				$bquantity=$grow['quantity'];
				$bback=$grow['back'];
			
				if(!empty($aref))
				{
					if($bback < $bquantity)
					{
						$_SESSION['gig'] = $bgig;
						if($bquantity == 1)
						{
							echo "This item is currently checked out to:";
						}
						else
						{
							$tquantity = $bquantity - $bback;
							echo "$tquantity of these items are checked out to:";
						}
						echo ' <a href="../inventory/checkout/checkout.php?gig=';
						echo "$bgig";
						echo '">';
						echo "$bgig</a>";
						$_SESSION['barcode'] = $barcode;
						$bref = $aref;
						$_SESSION['bref'] = $bref;
						echo '. <a href="checkin.php?ref=';
						echo "$bref";
						echo '">Check In</a><br />';
					}
				}
			}	//Close Gig check
			
			echo "<br />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>";
			}	//Close PAT check
			else
			{
				if($gotretest == '1')	//Check retest period plurality
					{}
					else
					{	
						echo "Retest Period: $gotretest years <br>";
					}	//close plurality check
				if(empty($gotuser))	//check for PAT Test
				{
					echo '<FONT COLOR=red><strong>NO PAT Test</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
				else
				{
					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);
								
					echo "Test Date: ";			
					$fail_date = strtotime($compdate);
					$testdatestr = strtotime($gotdate);
					
					if ($fail_date < $testdatestr) //Date Check
					{ 
						echo "<FONT COLOR=green><strong>$gotdate</strong></font>"; 
					} 
					else 
					{ 
						echo "<FONT COLOR=red><strong>$gotdate</strong></font>"; 
					}	//Close date check
				} //close else of PATed check
				
					///////////////////////////
				if ($mydate)
				{
					$mydate_date = strtotime($mydate);
					$testdateste = strtotime($gotdate);
					if ($mydate_date > $testdateste) //Date Check
					{ 
						echo "<br><FONT COLOR=orange><strong>This item will be out of PAT Test by $myevent</strong></font><br>";
					}
				}
				///////////////////////////
				
			} //close else of PAT Check
			$servicesearch = mysql_query("SELECT * FROM service WHERE barcode='$barcode' ORDER BY ref DESC");	//Print any Sevice Logs
			while($srow = mysql_fetch_array($servicesearch))	//Start While Loop
			{
				$sref	=$srow['ref'];	//Set variables from database record
				$suser	=$srow['user'];
				$sdate	=$srow['date'];
				$snotes	=$srow['notes'];
			
				if(!empty($sref))
				{
					echo '<br /><hr width="100%" />';
					echo "Notes:<strong> $snotes</strong>";
					echo "<br />By: $suser";
					echo "<br />On: $sdate";
					
				}
			}	//Close Service check
		$_SESSION['barcode'] = $barcode;
		$_SESSION['name'] = $gotname;
		echo '<br><hr width="100%" />';
		if(!empty($gotretest))
		{
			echo '<br><a href="pat.php">PAT Test Item</a>';
		}
		echo '<br><a href="service.php">Add Service Log</a>';
		echo '<br><a href="checkout.php">Check Item out to a Gig</a>';
		echo '<br><a href="modify.php">Modify Item</a>';
		echo '<br><a href="retire.php">Retire Item</a>';
			
		}	//submit check
		?>
		
		<br><hr width="100%" /><a href="../">Menu</a><br><a href="../inventory/checkout/">Check Out Gig</a><br><a href="../inventory/checkin/">Check In Gig</a>
	</body>
</html>
Return current item: PAT and Inventory Management System