<?php
##############################################################################
# add_games.php3                                                             #
# ajout de matchs au Kestufoot                                               #
#                                                                            #
# Copyright ViralGames SARL 2000                                             #
##############################################################################

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




?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Ajouter un partenaire</div>
<br>

<?php
$error = "";
switch ($submit)
{
	case "Infos":
		$row = db_fetch_array ( main_db_query ("SELECT * FROM Partenaires WHERE Id='".$Id."'"));
		$Nom = stripslashes($row[Nom]);
		$Description = str_replace("<br />","\n",$row[Description]);
		$Lien = $row[Lien];
		$TypeId = $row[TypeId];
		$Id = $row[Id];
	
		break;
		
	case "Valider":
		
		$Description = nl2br($Description);
		$Description = str_replace("\n","",$Description);
		$Description = str_replace("\r","",$Description);
		
		
		
	
		if ($Id!=0)
		{
			main_db_query("UPDATE Partenaires SET Nom='".$Nom."', Description='".$Description."',Lien='".$Lien."',TypeId='".$TypeId."' WHERE Id='".$Id."'");
			
		}		
		else
		{
			main_db_query("INSERT INTO Partenaires (Nom,TypeId,Description,Lien,Date) VALUES ('".$Nom."','".$TypeId."','".$Description."','".$Lien."','".date("Y-m-d H:i:s")."')");	
		}
		break;
		
		$Description = str_replace("<br />","\n",$row[Description]);
		$Description = stripslashes($Description);
		$Nom = stripslashes($Nom);
		
	case "Supprimer":
		# on vérifie que le match n'a pas de résultat sinon la suppression est interdite
		# on supprime tous les paris sur le match (si les paris n'ont pas été validés)
		main_db_query("DELETE FROM Partenaires WHERE Id='".$Id."'");
		$error = "Le partenaire a été supprimé";
	
		
		break;
		
	default :
		$error = "";
		break;
}
?>


<table>
<form method="post" name="main">
	<tr>
		<td>
			Id :
		</td>
		<td>
			<input type="text" name="Id" size=3 value=<?php echo $Id ?>> (0 pour ajouter)
		</td>
	</tr>	
	
	<tr>
		<td>
		   Nom :
		</td>
		<td>
			<input type="text" name="Nom" value="<?php echo $Nom ?>" style="width:300px";>
		</td>
	</tr>
	<tr>
		<td>
		   Type :
		</td>
		<td>
			<select name="TypeId">
			<option value=0></option>
			<?php
			$rows = main_db_query("SELECT * FROM Partenaires_Types ORDER BY Id ASC");
			while($row = db_fetch_assoc($rows))
			{
				$SELECTED = "";
				if($TypeId == $row["Id"])
					$SELECTED = "SELECTED";
				echo "<option value=".$row["Id"]." ".$SELECTED.">".$row["Name"]."</option>";
			}
			?>
			</select>
		</td>
	</tr>
	<tr>
		<td>
			Lien :
		</td>
		<td>
			<input type="text" name="Lien" value="<?php echo $Lien ?>" style="width:300px";> (saisir avec le http://)
		</td>
	</tr>
	<tr>
		<td>
			Description :
		</td>
		<td>
			<textarea name="Description"  style="width:300px;height:100px;font-family:arial;";><?php echo $Description ?></textarea>
		</td>
	</tr>
	<tr>
		<td colspan=2>
			<input name=submit type=submit value="Infos">&nbsp;&nbsp;&nbsp;
			<input name=submit type=submit value="Valider">&nbsp;&nbsp;&nbsp;
			<input name=submit type=submit value="Supprimer">
	
	</td>
	</tr>
	</form>
</table>


<br><br><br><br>

<table border=1>
	<tr class=trTitle>
		<td align=center colspan=9>Liste des Partenaire</td>
	</tr>
	<tr class=trTitle>
		<td>N°</td>
		<td>Nom</td>
		<td>Type</td>
		<td>Lien</td>	
		<td>Description</td>		
		<td>Date</td>			
	</tr>
<?php

$rows=main_db_query("SELECT Partenaires.*,Partenaires_Types.Name AS Type FROM Partenaires LEFT JOIN Partenaires_Types ON Partenaires.TypeId = Partenaires_Types.Id");
$r=0;
while($row=db_fetch_array($rows))
{

	$r++;
	echo "<td><a href='?submit=Infos&Id=".$row[Id]."'>".$row[Id]."</a></td>";
	echo "<td><a href='?submit=Infos&Id=".$row[Id]."'>".$row[Nom]."</a></td>";
	echo "<td>".$row[Type]."</td>";
	echo "<td>".$row[Lien]."</td>";
	echo "<td>".$row[Description]."</td>";
	echo "<td><b>".$row[Date]."</b></td>";

	echo "</tr>";
}
echo "<tr class=trTitle><td colspan=9>&nbsp;$error</td></tr></table>";
?>

</body>
</html>
