<?php
########################################################
# ajout de containers                                  #
########################################################

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


$error = "";

# si aucune date n'a été entrée,on affiche la date actuelle dans les champs texte
$current_european_date = date("Y-m-d H:i:s", my_local_time());
if (!isset($ShowTime))
	$ShowTime = $current_european_date;
if (!isset($EndTime))
	$EndTime = $current_european_date;
?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Gestion des Containers</div>
<br>
<?php

switch($submit)
{
	case "Valider":
		# formatage de toutes les chaines de char
		$Name = AddSlashes($Name);
		
		if ($Id==0)
		{
			# on insere une nouvelle réponse
			main_db_query("INSERT INTO Containers (Name,Container,ShowTime,EndTime) VALUES ('".$Name."','".$Container."','".$ShowTime."','".$EndTime."')");
		}
		else
		{
			# on update si c'est une modif
			main_db_query("UPDATE Containers SET Name='".$Name."',Container='".$Container."',ShowTime='".$ShowTime."',EndTime='".$EndTime."' WHERE Id='".$Id."'");
		}
		$Id=0;
		$Name = "";
		break;
		
	case "Supprimer":
		main_db_query("DELETE FROM Containers WHERE Id='".$Id."'");
		$Id=0;
		$Container = "";
		$Name = "";
		$ShowTime = "";
		$EndTime = "";
		break;
	
	case "Infos":
		$info = db_fetch_array(main_db_query("SELECT * FROM Containers WHERE Id='".$Id."'"));
		
		$Container = $info[Container];
		$Name = $info[Name];
		$ShowTime = $info[ShowTime];
		$EndTime = $info[EndTime];
		break;
}

?>
<div class=universBold>Liste des containers</div>
<table border=1>
	<tr class=trTitle>
		<td>Id</td>
		<td>Container</td>
		<td>Nom</td>	
		<td>ShowTime</td>
		<td>EndTime</td>
	</tr>
	
<?php
$rows=main_db_query("SELECT * FROM Containers");
while($row=db_fetch_array($rows))
{
	if (time_diff_now($row[ShowTime]) > 0 and time_diff_now($row[EndTime]) < 0)
		echo "<tr bgcolor=yellow>";
	else
		echo "<tr>";

	echo "<td>".$row[Id]."</td>";
	echo "<td>".$row[Container]."</td>";
	echo "<td>".stripslashes($row[Name])."</td>";
	echo "<td>".$row[ShowTime]."</td>";
	echo "<td><b>$row[EndTime]</b></td>";
	echo "</tr>";
}
    ?>
</table>
	<form>
<table>
	<tr>
		<td>
			Id :
		</td>
		<td>
			<input type="text" size=3 name=Id value="<?php echo $Id ?>"> (0 pour ajouter un container)
		</td>
	</tr>
	<tr>
		<td>
			Container père :
		</td>
		<td>
			<input type="text" size=3 name=Container value="<?php echo $Container ?>"> (0 par défaut)
		</td>
	</tr>
	<tr>
		<td>
			Nom :
		</td>
		<td>
			<input type="text" size="30" name="Name" value="<?php echo $Name ?>">
		</td>
	</tr>
	<tr>
		<td>
			Date d'affichage :
		</td>
		<td>
			<input type="text" name="ShowTime" value="<?php echo $ShowTime ?>"> AAAA-MM-JJ HH:MM:SS
		</td>
	</tr>
	<tr>
		<td>
			Date limite :
		</td>
		<td>
			<input type="text" name="EndTime" value="<?php echo $EndTime ?>"> AAAA-MM-JJ HH:MM:SS
		</td>
	</tr>
</table>
<br>
    <input type=submit name=submit value="Infos">&nbsp;&nbsp;&nbsp;
    <input type=submit name=submit value="Valider">&nbsp;&nbsp;&nbsp;
	<input type=submit name=submit value="Supprimer"><br>
	</form>
<a class=under href="<?php echo $PHP_SELF ?>">Rafraichir la page</a>