<?php
include("../config.php3");
include($BIB."bib_generic.php3");

# lit le contenu d'un repertoire
# le met dans un tableau en retour
function getDirArray($sPath) 
{ 
	//Load Directory Into Array 
	$handle=opendir($sPath);
	$r=0;
	while ($file = readdir($handle))
	{
		# on ne veut pas de . et ..
		# on ne prend que les files (par les répertoires par exemple)
		if ($file!="." and $file!=".." and is_file(chop($sPath.$file)))
			$retVal[count($retVal)] = $file;
	}
	
	//Clean up and sort 
	closedir($handle); 

	# on trie
	sort($retVal); 
	
	return $retVal; 
}

?>

<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Gestions des équipes</div>
<br>

<?php
if($submit=="Valider")
{
	for($i=0;$i<$nbTeam;$i++)
	{
		main_db_query("UPDATE Teams SET Categorie = '".$_POST["Categorie_".$i]."' WHERE Id=".$_POST["Id_".$i]);
	}
}

$teams = main_db_query("SELECT * FROM Teams ORDER BY Name ASC");
?>
<div class=universBold>Liste des équipes</div>
<form method="post">
<input type=submit name=submit value="Valider">
<table border=1>
	<tr class=trTitle>
		<td>Id</td>
		<td>Name</td>
		<td>Image</td>
		<td>Image</td>
		<td>Categorie (Page equipe fan)</td>
	</tr>
<?php
$TABCATEG = Array("L1","L2","Nationales","InterNationales");
$i = 0;
while($team = db_fetch_array($teams))
{
	echo "<tr>";
	echo "<td>".$team[Id]."</td>";
	echo "<td>".$team[Name]."</td>";
	echo "<td>".$team[Image]."</td>";
	echo "<td>";
	echo "<img src='".$IMAGES_DIR.$team[Image]."'/>";
	/*
	echo "<select name='Image_".$i."'>";
		
		$fichier = getDirArray($GAME_DIR."Images/flags/");
		for($r=0;$r<count($fichier);$r++)
		{
			if ($fichier[$r] != "." && $fichier[$r] != "..")
			{
				echo "<option value=flags/".$fichier[$r];
				if (("flags/".$fichier[$r])==$team[Image])
					echo " selected";
				echo ">".$fichier[$r];
			}
		}
			
	echo "</select>";
	*/
	echo "</td>";
	echo "<td><select name='Categorie_".$i."'>";
		echo "<option value=''></option>";
		foreach($TABCATEG as $categ)
		{
			$selected = "";
			if($categ == $team["Categorie"])
				$selected = "selected";
			echo "<option value='".$categ."' ".$selected.">".$categ."</option>";
		}		
	echo "</select></td>";
	echo "<input type='hidden' name='Id_".$i."' value='".$team["Id"]."' />";
	echo "</tr>";
	$i++;
}
echo "</table>";
?>
<input type=hidden name=nbTeam value="<?php echo $i;?>">
<input type=submit name=submit value="Valider">
</form>
