<html xmlns:AI>
	<head>
	<title></title> 
	<link href='dm.css' rel='stylesheet' type='text/css'>
		<?php 
			include "functions.php";
		?>
		<link href='dm.css' rel='stylesheet' type='text/css'>
	</head>
<html>
<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'] : "" );
 					$tn = ( isset($_REQUEST['tn'] ) ? $_REQUEST['tn'] : "" );
					$Name	= ( isset($_REQUEST['Name'] ) ? $_REQUEST['Name'] : "" );
					$NameSZ	= ( isset($_REQUEST['NameSZ'] ) ? $_REQUEST['NameSZ'] : "" );
					$NameJoy	= ( isset($_REQUEST['NameJoy'] ) ? $_REQUEST['NameJoy'] : "" );
					$Email	= ( isset($_REQUEST['Email'] ) ? $_REQUEST['Email'] : "" );
					$guest	= ( isset($_REQUEST['guest'] ) ? $_REQUEST['guest'] : "" );

					if( $action == "edit" ) {
							$query = "INSERT INTO teilnehmer (Name,NameSZ,NameJoy,Email) VALUES ('$Name','$NameSZ','$NameJoy','$Email')";
	    				$result = mysql_query($query);
	    				
	    				$newid = mysql_insert_id();
							$query = "INSERT INTO tnliste (IDevent,IDteilnehmer) VALUES ('$n','$newid')";
	    				$result = mysql_query($query);
					}

					if( $action == "add" ) {
				    $query = "select * from tnliste where IDevent=$n and IDteilnehmer=$guest";
		  		  $result = mysql_query($query);
						if( mysql_num_rows( $result ) == 0 ) {
							$query = "INSERT INTO tnliste (IDevent,IDteilnehmer) VALUES ('$n','$guest')";
	    				$result = mysql_query($query);
	    			}
					}
					
					if( $action == "anmelden" ) {
						$query = "UPDATE tnliste SET Storno='0' WHERE ID=$tn";
    				mysql_query($query);
					}
					
					if( $action == "storno" ) {
						$query = "UPDATE tnliste SET Storno='1' WHERE ID=$tn";
    				mysql_query($query);
					}

					if( $action == "anwesend" ) {
						$query = "UPDATE tnliste SET Anwesend='1' WHERE ID=$tn";
    				mysql_query($query);
					}
					
					if( $action == "abwesend" ) {
						$query = "UPDATE tnliste SET Anwesend='0' WHERE ID=$tn";
    				mysql_query($query);
					}
					
					
			    $query = "select l.ID, t.Name as Name, t.NameSZ,t.NameJoy,t.Email,l.Storno,l.Anwesend from tnliste l, teilnehmer t,event e where l.IDevent=e.ID and l.IDteilnehmer=t.ID and e.ID=$n";
	  		  $result = mysql_query($query);

					print "<table width=100% border='0' cellspacing='3' cellpadding='4'><tr>";
					print "<td bgcolor='#CCCCCC'>Name</td>";
					print "<td bgcolor='#CCCCCC'>Email</td>";
					print "<td bgcolor='#CCCCCC'>SZ</td>";
					print "<td bgcolor='#CCCCCC'>Joy</td>";
					print "<td bgcolor='#CCCCCC'>SZ</td>";
					print "<td colspan='2' bgcolor='#CCCCCC'>&nbsp;</td></tr>";
		  		while ($line = mysql_fetch_array($result)) {
		  			$color = ( $line["Storno"] == 0 ? '#EEEEEE' : '#999999' );
				  	print "<tr valign='top'><td bgcolor='$color'>".$line["Name"]."&nbsp;</td>";
						print "<td bgcolor='$color'>".$line["Email"]."&nbsp;</td>";
						print "<td bgcolor='$color'>".$line["NameSZ"]."&nbsp;</td>";
						print "<td bgcolor='$color'>".$line["NameJoy"]."&nbsp;</td>";
						$ln = $line["ID"];
				  	print "<td bgcolor='$color'><a href=\"edit.php?n=$ln\">Mail schicken</a></td>";
				  	if( $line["Storno"] == 0 ) {
				  		print "<td bgcolor='$color'><a href=\"admin.php?tn=$ln&n=$n&action=storno\">Storno</a></td>";
				  	} else {
				  		print "<td bgcolor='$color'><a href=\"admin.php?tn=$ln&n=$n&action=anmelden\">Wieder anmelden</a></td>";
				  	}
				  	if( $line["Anwesend"] == 1 ) {
				  		print "<td bgcolor='$color'><a href=\"admin.php?tn=$ln&n=$n&action=abwesend\">Anwesend</a></td>";
				  	} else {
				  		print "<td bgcolor='$color'><a href=\"admin.php?tn=$ln&n=$n&action=anwesend\">Nicht Anwesend</a></td>";
				  	}
					}
					print "<tr><td bgcolor='#EEEEEE' colspan=7 align=\"center\"><a href=\"editguest.php?n=0&event=$n\">Neuer Besucher hinzufügen</a> * <a href=\"addguest.php?n=0&event=$n\">Besucher aus anderer Veranstaltung hinzufügen</a></td></tr>";
					
					print "</table>";
				
				?>
				
			</td>
		</tr>
	</table>
	</div>

</body>
</html>
