Location: PHPKode > projects > PAT and Inventory Management System > m/inventory/service/index.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. Allows sharing of variables between pages for a smoother user experience
	$directory = $_SESSION['docroot'];
	include_once '../../../config.php';
	
	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();
	
	$_SESSION['barcode'] = $barcode; //set some session variables that will be available to other pages
	$_SESSION['testdate'] = $testdate;
	$_SESSION['user'] = $user;
	
	if(empty($_POST['name']))	//Check if form has been subitted on this page load
	{
		$seluser = $_SESSION['returnuser'];	//if it has not, use the session variable for pre-selected user
	}
	else
	{
		$seluser = $_POST['name'];		//if it has, use the last selected user
	}
	
?> <!-- End PHP section 1 -->

<html> <!-- HTML Form Section Start -->
	<title>PIMS | Service</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h4>Add Service information for an item</h4></head>
	<body onLoad="document.input.name.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>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>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>Service Note: </td><td><textarea rows="5" cols="40" id="notes" name="notes"></textarea></td>
		</tr><tr>
		<td>Barcode: </td><td><input type="text" name = "barcode"/></td>
		</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
		$date=$_POST['date'];
		$notes=$_POST['notes'];
		$barcode=$_POST['barcode'];
		$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="..">Back</a><br><a href="../../../">Home</a><br>'; //Navigation Options
				die; //Stop
			}
		if(empty($barcode)) // Check they entered a barcode
			{
				echo "Please enter a Barcode"; // Tell them what they did wrong
				echo '<br><hr width="100%" /><a href="..">Back</a><br><a href="../../../">Home</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'];
			}
		if(empty($gotname)) // if no description is known, direct user to the create page
			{
				echo "Sorry, This item does not exist";
				echo '<br /><a href="..">Back</a><br><a href="../../../">Home</a><br';
				die;
			}
			
		$newdate=$testdate;	// Data adjust (if required)
		mysql_query("INSERT INTO `service` VALUES ('', '$barcode', '$user', '$date', '$notes')");	//Add gig to database
		$_SESSION['returnuser'] = $user;
		echo "<strong>$gotname</strong> has had '$notes' added to its log";
		
	}
?> <!-- End PHP -->

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