<?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;
	}


//require_once ('mysql_connect.php');
$action          = $_GET["a"];
$active = $_POST['chkactive'];


	//echo 'Action = ' . $action; (for testing)
//require_once ('config.inc');
if ($action == "delete") {
			
			$query = "Delete From zipCodes WHERE recordKey = '" . $_GET['key'] ."'" ;

			if (!mysql_query($query)){
					echo $query;
  					die('Error: ' . mysql_error());
 			 } else {
				echo "<div align=center><font color=red>Zip code deleted successfully.</font></div>";
				
			}
		}

if ($action == "add") {
			
			$query = "Insert into zipCodes (zip) Values ('" . $_POST['zip'] . "')";

			if (!mysql_query($query)){
					echo $query;
  					die('Error: ' . mysql_error());
 			 } else {
				echo "<div align=center><font color=red>Zip code added successfully.</font></div>";
				
			}
		}

if ($action == "update") {


		if (isset($_POST["zipcode"])) {
		$query = "UPDATE zipCodes SET zip = '" . $_POST['zipcode'] . "'";

		$query = $query . " WHERE recordKey = '" . $_GET['key'] ."'" ;
		//echo $query;
		mysql_query($query) or die(mysql_error());   //execute query

		//confirmation message that delete worked...
		echo "<font color=red>Zip code updated successfully.</font>";

		}

	}	//end of update query

		$query = "SELECT zip, recordKey from zipCodes";


		$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>Zip<td><td><b><u><div align=center>Delete<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[recordKey] . '" method="post">
	<td valign="top"><input type="text" name="zipcode" size="10" value="' . $nt[zip] . '">
	<td><td><a href="' . $_SERVER['PHP_SELF'] . '?a=delete&key=' . $nt[recordKey] . '"><font color="blue">Delete</font></a>
	<td><input id="save-button" type="submit" name="update" value="Save"></form>';  

	
	
	
	
		
}

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


	
		

	echo '
    <form action="' . $_SERVER['PHP_SELF'] . '?a=add" method="post">Add new delivery zip code: <br><input type="text" name="zip" size=10>

		<input id="save-button" type="submit" name="save" value="Save">
		</form><br>
		
		</div></table></div>';
	

	

?>