<?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"];

	//echo 'Action = ' . $action; (for testing)


if ($action == "add") {
			
			$query = "Insert into cardTypes (cardType) Values ('" . $_POST['cardtype'] . "' )";

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

if ($action == "update") {
$checkbox = $_POST['chkdelete'];


	if (empty($checkbox)) {
		//delete not checked, save other updated info

	
		
		$query = "UPDATE cardTypes SET cardType = '" . $_POST['cardtype'] . "'";
		
		
		$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>Card name updated successfully.</font>";

		

	} else { 
		
		
	$query = "DELETE FROM cardTypes WHERE recordKey = '" . $_GET["key"] ."'" ;
	
	

	mysql_query($query) or die(mysql_error());   //execute query

	//confirmation message that delete worked...
	echo "<font color=red>Card type deleted successfully.</font>";

		}
	}	//end of update query

		$query = "SELECT * from cardTypes";


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



echo '<br><div align="center"><a href="index.php"><font color="blue">Back to Main Page</font></a>';


echo '<div align="center"><table border=0 cellpadding=0 cellspacing=8>';

while($nt=mysql_fetch_array($rt)){

	//echo '<tr><td><div align=left>Record Key:<td valign=top><div align=left><input type="text" name="description" size="30" value="' . $nt[recordKey] . '" disabled="disabled">';
	echo '<tr><td><form action="' . $_SERVER['PHP_SELF'] . '?a=update&key=' . $nt[recordKey] . '" method="post"><tr><td><div align=left>Card Type:<td valign="top"><div align=left><input type="text" name="cardtype" size="30" value="' . $nt[cardType] . '">';  

	
	
	

echo '<tr><td valign=top><div align=left>Delete:<td valign=top><div align=left><input type="checkbox" name="chkdelete" value="true">';  

	echo '<tr><td><td valign=top><div align=center><input type="submit" name="save" value="Save"></form><tr><td colspan=2><hr width=100%>';
		
}

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


	
		

	echo '    <form action="' . $_SERVER['PHP_SELF'] . '?a=add" method="post">Add new card type: (ie: Visa) <br><input type="text" name="cardtype" size=50>

		<input type="submit" name="save" value="Save">
		</form>
    <br><a href="index.php"><font color="blue">Return to Main Page</font></a>
		
		</div></table></div>';
	

	

?>