<!--
Pat and Inventory Management System
Version 0.1
Created by Tom Dyer
Last edited by Tom Dyer 19/9/09
Checkout Select Gig
-->
<?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 gignames ORDER BY gig ASC"; //get a list of gigs
$result=mysql_query($query);
$num=mysql_numrows($result);
$barcode = $_SESSION['barcode'];
$name = $_SESSION['name'];
?>
<html>
<title> Check Out</title>
<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h4>Check an Item out to a Gig</h4></head>
<body onLoad="document.input.barcode.focus()" LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
<table border="0">
<!--<form action="input.php" method="post" name="input">-->
<form action="" method="post" name="input">
<input type="hidden" name="cmd" value="done"</input>
<tr>
<td>Barcode: </td><td><?php echo "$barcode" ?></td>
</tr><tr>
<td>Description: </td><td><?php echo "$name" ?></td>
</tr><tr>
</tr><tr><td>Select Gig: </td><td><SELECT id="gig" name="gig">
<option value=pick>Choose Gig</option>
<?php //Put gig names in drop down list
$i=0;
while ($i < $num)
{
$gigs=mysql_result($result,$i,"gig");
echo '<option value="'.$gigs.'" ';
echo '>'.$gigs.'</option>';
$i++;
}
?>
</select></td>
</tr><tr>
<td>Quantity: </td><td><input name="quantity" id="quantity" value="1" size="2"></td>
</tr><tr>
<td><input type="submit" value="Select Gig"></td>
</tr>
</form>
</table>
<?php
if($_POST['cmd'] == "done") //Check if form has been submitted
{
$gig = $_POST['gig'];
$quantity = $_POST['quantity'];
if($gig == "pick")
{
echo "Please select a gig";
}
else
{
$bsearch = mysql_query("SELECT * FROM gigs WHERE barcode='$barcode'"); //collect information on selected barcode
while($row = mysql_fetch_array($bsearch)) //Start While Loop
{
$bref=$row['ref']; //Set variables from database record
$bgig=$row['gig'];
$bquantity=$row['quantity'];
$bback=$row['back'];
if(!empty($bref))
{
if($bgig == $gig) //check we are looking at the gig we want.
{
$quantity = $bquantity + $quantity;
mysql_query("UPDATE gigs SET quantity = '$quantity' WHERE ref = '$bref'"); //Update gig to database
echo "$name added to the gig";
$done = 1;
}
}
}
if(empty($row) && empty($done))
{
mysql_query("INSERT INTO `gigs` VALUES ('', '$gig', '$barcode', '$quantity', '')"); //Add gig to database
echo "$name added to the gig";
}
echo '<script language="javascript">window.location="index.php";</script>';
}
}
?>
<br><hr width="100%" /><a href="index.php">Back</a><br>
</body>
</html>