<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<title></title> 
	<link href='dm.css' rel='stylesheet' type='text/css'>
<?php
	include "functions.php";
?>
<body leftmargin=0 topmargin=0>
	<div align="center">
	<table width="100%" border="0" cellspacing="3" cellpadding="0">
		<?php
			include "header.php";
		?>
		<tr>
			<td align="center" valign="top" class="content">
				<?php
					DBConnect();

 					$action = ( isset($_REQUEST['action'] ) ? $_REQUEST['action'] : "" );
 					$n = ( isset($_REQUEST['n'] ) ? $_REQUEST['n'] : "" );
					$Name	= ( isset($_REQUEST['Name'] ) ? $_REQUEST['Name'] : "" );
					$NameSZ	= ( isset($_REQUEST['NameSZ'] ) ? $_REQUEST['NameSZ'] : "" );
					$NameJoy	= ( isset($_REQUEST['NameJoy'] ) ? $_REQUEST['NameJoy'] : "" );
					$Email	= ( isset($_REQUEST['Email'] ) ? $_REQUEST['Email'] : "" );

					if( $action == "edit" ) {
						if( $n == 0 ) {
							$query = "INSERT INTO teilnehmer (Name,NameSZ,NameJoy,Email) VALUES ('$Name','$NameSZ','$NameJoy','$Email')";
	    				$result = mysql_query($query);
	    			} else {
							$query = "UPDATE teilnehmer SET Name='$Name',NameSZ='$NameSZ',NameJoy='$NameJoy',Email='$Email' WHERE ID=$n";
	    				mysql_query($query);
	    			}
					}

					if( $action == "delete" ) {
						$query = "delete from teilnehmer WHERE ID=$n";
    				mysql_query($query);
					}
					
			    $query = "SELECT ID,Email,Name,NameSZ,NameJoy,NameFetlife FROM teilnehmer order by Email";
	  		  $result = mysql_query($query);

					print "<table width=100% border='0' cellspacing='3' cellpadding='4'><tr>";
					print "<td bgcolor='#CCCCCC'>Name</td><td bgcolor='#CCCCCC'>Email</td><td bgcolor='#CCCCCC'>SZ</td><td bgcolor='#CCCCCC'>Joy</td>";
					print "<td colspan='2' bgcolor='#CCCCCC'>&nbsp;</td></tr>";
		  		while ($line = mysql_fetch_array($result)) {
				  	print "<tr valign='top'><td bgcolor='#EEEEEE'>".$line["Name"]."&nbsp;</td>";
						print "<td bgcolor='#EEEEEE'>".$line["Email"]."&nbsp;</td>";
						print "<td bgcolor='#EEEEEE'>".$line["NameSZ"]."&nbsp;</td>";
						print "<td bgcolor='#EEEEEE'>".$line["NameJoy"]."&nbsp;</td>";
						$ln = $line["ID"];
				  	print "<td bgcolor='#EEEEEE'><a href=\"editguest.php?n=$ln\">Bearbeiten</a></td>";
				  	print "<td bgcolor='#FF0000'><a href=\"guests.php?n=$ln&action=delete\">Entfernen</a></td></tr>";
					}
					print "<tr><td bgcolor='#EEEEEE' colspan=5 align=\"center\"><a href=\"editguest.php?n=0\">Neuen Teilnehmer hinzufügen</a></td></tr>";
					
					print "</table>";
				
				?>
				
			</td>
		</tr>
	</table>
	</div>

</body>
</html>
