<?php
if (isset($_SESSION['FirstName']))  {

echo '<br><div align="right">';

//include ("usermenu.php");


echo '</div><br><br> ';
}
?> 
         
<div id="menu-items">
    	
	<a name="top"></a>

<?php

$category          = $_GET["cat"];

if($action=="additem"){

	//test fields to make sure they are filled in
	if(($_POST['itemid']==0)OR($_POST['quantity']==0)){ //required fields not filled in...
		echo '<font color="red">We apologize, but there was an error adding this item to your order. Please try again or call us to let us help 		you.</font>';
	} else {	//*******fields are filled in, add item to couponItem

	//insert record into couponItem table
	$query = "Insert into couponItem (itemNumber, qty, customerID, size, subitems, categoryKey) values ('" . $_POST['itemid'] . "', '" . $_POST['quantity'] . "', '" . 		$_SESSION['UserKey']  . "', '" . $_POST['size'] . "', '";
		if ($category=="Pizza"){
			$query .= "1";
		} else {
			$query .= "0";
		}
		$query .="','" . $_POST['categorykey'] . "')";

		//echo $query . "<br>";
		mysql_query($query);          // query executed 
		echo mysql_error();                    // if any error is there that will be printed to the screen

	}
}

if ($action=="submit"){




	include('couponItems.php');
}

echo '<br>';

$query = "SELECT recordKey, categoryName, orderNum from menuCategory WHERE active ='1' And categoryName <> 'Pizza Toppings' And categoryName <> 'Pizza Crust' Order By orderNum";
$rt=mysql_query($query);          // query executed 
		echo mysql_error();                    // if any error is there that will be printed to the screen
while($nt=mysql_fetch_array($rt)){

	echo '<a href="#' . $nt[categoryName] . '">'  . $nt[categoryName] . '</a> &nbsp;';      
}
echo '<br><br>';

//pull category list
$query = "SELECT recordKey, categoryName, orderNum from menuCategory WHERE active ='1' And categoryName <> 'Pizza Toppings' And categoryName <> 'Pizza Crust' Order By orderNum";
$rt=mysql_query($query);          // query executed 
echo mysql_error();                    // if any error is there that will be printed to the screen

while($nt=mysql_fetch_array($rt)){   //if categories are found, pull item records
	//print category level info
	echo '<table width="100%" cellpadding=0 cellspacing=0 border=0><tr><td colspan=4 bgcolor="yellow"><a id="' . $nt[categoryName] . '" name="' . $nt[categoryName] . '"></a><h1>' . $nt[categoryName] . '</h1>';

	$query2 = "SELECT itemKey, ItemName, categoryKey, itemPrice, description, multisized from menuItem WHERE active = '1' AND categoryKey='"  . $nt[recordKey] . "' Order By ItemName";
	
	$rt2=mysql_query($query2);          // query executed 
	echo mysql_error();                    // if any error is there that will be printed to the screen
                          	
	while($nt2=mysql_fetch_array($rt2)){
		//print item level info

		echo '<tr><td><h2>'  . $nt2[ItemName] . '&nbsp;<td valign="bottom"></h2>';		
		echo '<tr><td colspan="4"><h3>'.  $nt2[description] . '</h3>';
	
		echo '<tr><td colspan=4><div align="center"><table border=0 width="80%">'; //begin pricing table

		if($nt2[multisized]==0) {  //show single item price
		
		echo '<form action="' . $_SERVER['PHP_SELF'] . '?a=additem&cat=' . $nt[categoryName] . '" method="post"><input type="hidden" name="itemid" value="' . $nt2[itemKey] . '">';
	
		echo '<tr><td width=35%><td valign="bottom"><span class="menu-price">$'  . $nt2[itemPrice] . '</span><input type="hidden" name="price" value="' . $nt2[itemPrice] . '"><input type="hidden" name="categorykey" value="' . $nt2[categoryKey] . '"><td><div align="right">Qty: <input type="text" name="quantity" size=3> <input type="submit" name="order" value="Add to order" /></form></div>';
		
		} else {
			
			$query3 = "Select size, price from itemSize where itemKey = '" . $nt2[itemKey] . "'";
			$rt3=mysql_query($query3);          // query executed 
			echo mysql_error();                    // if any error is there that will be printed to the screen
			while($nt3=mysql_fetch_array($rt3)){
				echo '<form action="' . $_SERVER['PHP_SELF'] . '?a=additem&cat=' . $nt[categoryName] . '" method="post"><input type="hidden" name="itemid" value="' . $nt2[itemKey] . '"><tr><td width=35%><div align="left"><h2>'  . $nt3[size] .'</h2></div><input type="hidden" name="size" value="' . $nt3[size] . '"><td><div align="left">
				<span class="menu-price">$' . $nt3[price] . '</span><input type="hidden" name="price" value="' . $nt3[price] . '"><input type="hidden" name="categorykey" value="' . $nt2[categoryKey] . '">';
				echo '<td valign="bottom"><div align="right">Qty: <input type="text" name="quantity" size=3> <input type="submit" name="order" value="Add to order" /></form></div>';
			}

			
		}

		echo '</table></div><tr><td colspan="4" height="1" width="100%" bgcolor="black">';
		
	}
	

	mysql_close;
	echo ' <tr><td colspan="4"><a href="#top">BACK TO TOP</a><br><br></table>';

}
	//now print pizza toppings at the end since these can not be added to order individually, can only be added to a pizza

	$query = "SELECT recordKey, categoryName from menuCategory WHERE active ='1' And categoryName = 'Pizza Toppings'";
	$rt=mysql_query($query);          // query executed 
	echo mysql_error();                    // if any error is there that will be printed to the screen
	while($nt=mysql_fetch_array($rt)){
		$categoryKey = $nt[recordKey];
		//echo $nt[recordKey] . '- ' . $nt[categoryName];
	}
	if (mysql_num_rows($rt) !== 0) {
		echo '<div align="right"><h2>Pizza Toppings</h2>';
		$query2 = "SELECT ItemName, itemPrice, description from menuItem WHERE active = '1' AND categoryKey='"  . 	$categoryKey . "' Order By ItemName";
		//echo $query2;
		$rt2=mysql_query($query2);          // query executed 
		echo mysql_error();                    // if any error is there that will be printed to the screen
		while($nt2=mysql_fetch_array($rt2)){
			echo $nt2[ItemName] . '.....$' . number_format($nt2[itemPrice], 2, '.', ',') . '<br>';
		}
	}
	echo '</div>';
?> 

</div>