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



$action          = $_GET["a"];

$sizeKey  = $_GET["key"];


if (($action == "addsize") && ($_POST['newsize'] !=="")) {
             //check to see if it exists to avoid making duplicate
  $query = "Select * from sizeMaster where sizeName ='" .$_POST['newsize'] . "'" ;
  $rt=mysql_query($query);          // query executed
		echo mysql_error();
if (mysql_num_rows($rt) == 0) {
		$newsize = str_replace('"', 'in.', $_POST['newsize']);
		$newsize = str_replace("'", "-", $newsize);
		
      	//$query = "Insert into sizeMaster (sizeName) Values ('" . $_POST['newsize'] . "')";
		$query = "Insert into sizeMaster (sizeName) Values ('" . $newsize . "')";
		if (!mysql_query($query)){
					echo $query;
  					die('Error: ' . mysql_error());
 			 } else {

				echo "<div align=center><font color=red>Size added successfully.</font></div>";
				$action="edit";	//reset so edit item view will be shown again after update
			}
}  else {
       echo "<div align=center><font color=red>Error! Duplicate size not added.</font></div>";

}

}
if ($action == "delsize") {
      $query = "Delete from sizeMaster where recordKey = '" . $sizeKey . "'";

      if (!mysql_query($query)){
					echo $query;
  					die('Error: ' . mysql_error());
 			 } else {

				echo "<div align=center style='margin-bottom:6px;'><font color=red>Size table updated successfully.</font></div>";
				
			}
 }
 $query ="Select * from sizeMaster" ;
 $rt=mysql_query($query);          // query executed
		echo mysql_error();                    // if any error is there that will be printed to the screen
		echo '<div id="sizes-wrapper" align="center"><table width=50% cellspacing="0"><tr style="background-color:#0f5f81;color:#fff;"><td style="padding:5px;-webkit-border-radius: 6px 0px 0px 0px; -moz-border-radius: 6px 0px 0px 0px; border-radius: 6px 0px 0px 0px;">
    SIZES AVAILABLE<td style="padding:5px;-webkit-border-radius: 0px 6px 0px 0px; -moz-border-radius: 0px 6px 0px 0px; border-radius: 0px 6px 0px 0px;text-align:right;"> DELETE &nbsp;  ';
while($nt=mysql_fetch_array($rt)){      //show current sizes
  echo '<tr><td> ' . $nt["sizeName"] .' <td style="text-align:right;"> <a href="' . $_SERVER['PHP_SELF'] . '?a=delsize&key=' . $nt["recordKey"] .'">Delete this size</a>';

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

		
echo '<div align="center"><form action="' . $_SERVER['PHP_SELF'] . '?a=addsize" method="post">
Add new size description (Small, Med, etc): <br><input type="text" name="newsize" size=20 maxlength=20>
<input id="save-button" type="submit" name="save" value="Add this Size"></form></div>';	

?>