<?php
if ($_SESSION['FirstName'] == "") {
	echo 'You are not authorized to view this page. <br><br>You may <a href="index.php"><font color=blue>log in here</font>.</a>';
	exit;
	}


//require_once ('mysql_connect.php');
$action          = $_GET["a"];
$itemkey          = $_GET["key"];

//echo "action=" . $action;

 if ($action == "remove") {
                    $query = "Update menuItem set upsell=0 where itemKey='" . $itemkey . "'";
                    if (!mysql_query($query)){
					echo $query;
  					die('Error: ' . mysql_error());
 			 } else {
			//echo $query .'<br>';	//for testing
				echo "<div align=center><font color=red>Upsell options updated successfully.</font></div>";

			}
                 }
if ($action == "update") {
                 $query = "Update menuItem set upsellOrder='" . $_POST['order'] . "' where itemKey='" . $itemkey . "'";
		//echo $query;
                    if (!mysql_query($query)){
					echo $query;
  					die('Error: ' . mysql_error());
 			 } else {
			//echo $query .'<br>';	//for testing
				echo "<div align=center><font color=red>Upsell options updated successfully.</font></div>";
	   }
  }                  //end of update query
  
		$query = "SELECT itemKey, itemName, upsellOrder from menuItem Where upsell=1";


		$rt=mysql_query($query);          // query executed 
		echo mysql_error();                    // if any error is there that will be printed to the screen




echo '<div align="center"><table border=0 cellpadding=0 cellspacing=8><tr><td><td><b><u><div align=center>Item Name<td><b><u><div align=center>Upsell order<td><b><u><div align=center>Remove<td><b><u><div align=center>Save';

while($nt=mysql_fetch_array($rt)){
  echo '<tr><td><form action="'. $_SERVER['PHP_SELF'] . '?a=update&key=' . $nt[itemKey] .'" method="post">';
	echo '<td valign=bottom>' . $nt[itemName] . '<td valign=bottom><input type="text" name="order" size=5 value="' . $nt[upsellOrder] . '">';
	          echo '<td valign=bottom><a href="'. $_SERVER['PHP_SELF'] . '?a=remove&key=' . $nt[itemKey] .'"><font color=blue>Stop upselling</font></a>';
	          echo '<td valign=bottom><input id="save-button" type="submit" name="submit" value="Update"></form>';
		
}

echo '</table><br><br>';


	
		

	echo '<br>
		
		</div></table></div>';
	

	

?>