<!--<script type="text/javascript" src="../../1/images/jquery-1.11.1.min.js"></script>-->
<script type="text/javascript" language="javascript" src="../../1/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../1/images/jquery.dataTables.min.css">

<?php

echo "	<h1>Spiele</h1>";

echo "<a class=\"text\" href=\"index.php?link=editmatches2&mode=new\"><img title=\"Neu\" border=0 src=\"../../$_COOKIE[Game]/images/icons/new.png\"> Neues Spiel hinzufügen</a>";

$result=mysql_query("SELECT * FROM matches WHERE Game='$_COOKIE[Game]' ORDER BY Date");
$anzahl=mysql_num_rows($result);
if ($anzahl == 0) {
	echo "Noch kein Spiel vorhanden.";
}
else {
	echo "<h2>$anzahl Spiele:</h2>";
	echo "<table id=\"tblMatches\" class=\"display\">";
	echo "<thead><tr>";
	echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	echo "<td>Datum</td>";
	echo "<td>Gruppe</td>";
	echo "<td>Heim</td>";
	echo "<td>Gast</td>";
	echo "<td>Ergebnis</td>";
	echo "</tr></thead>";
	while ($row=mysql_fetch_assoc($result)) {

		$resultA=mysql_query("SELECT * FROM teams WHERE ID = $row[TeamIDA] AND Game='$_COOKIE[Game]'");
		$rowA=mysql_fetch_assoc($resultA);
		$resultB=mysql_query("SELECT * FROM teams WHERE ID = $row[TeamIDB] AND Game='$_COOKIE[Game]'");
		$rowB=mysql_fetch_assoc($resultB);
		$germandate = date("d.m.Y H:i", strtotime($row[Date]));
		$germandate = date("Y-m-d H:i", strtotime($row[Date]));

		if ($row[GoalsA] == -1 || $row[GoalsB] == -1) {
			$matchresult = "";
		}
		else { $matchresult = "($row[GoalsA]:$row[GoalsB])";
		}
		echo "<tr>";
		echo "<td><a class=\"text\" href=\"index.php?id=$row[ID]&link=editmatches2&mode=delete\"><img title=\"Löschen\" border=0 src=\"../../$_COOKIE[Game]/images/icons/delete.png\"></a>
						 <a class=\"text\" href=\"index.php?id=$row[ID]&teamA=$rowA[Team]&teamB=$rowB[Team]&link=editmatches2&mode=edit\"><img title=\"Editieren\" border=0 src=\"../../$_COOKIE[Game]/images/icons/edit.png\"></a>
						 <a class=\"text\" href=\"index.php?id=$row[ID]&teamA=$rowA[Team]&teamB=$rowB[Team]&link=editmatchesTippInfo\"><img title=\"E-Mails senden...\" border=0 src=\"../../$_COOKIE[Game]/images/icons/email.png\"></a></td>";
		echo "<td>$germandate</td>";
		echo "<td>$row[Level]</td>";
		echo "<td>$rowA[Team]</td>";
		echo "<td>$rowB[Team]</td>";
		echo "<td>$matchresult</td>";
		echo "</tr>";
	}
	echo "</table>";
}

?>

<script type="text/javascript">
	$(function()
	{
		$("#tblMatches").dataTable({
			"order": [[1, "asc"]],
			"paging":false,
			".scrollY": "500px",
			"columnDefs":[
				{
					"orderable":false, 
					"targets":0
				}
			]
		});
	});
</script>