<?php

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

if (!isset($rankStart))
	$rankStart = 0;
	
$nbRowsToShow = 24;

	switch( $_POST['valider'] )
	{
		case "Info" :
			if($_POST['idReponse'])
			{
				$rowReponse = db_fetch_assoc(main_db_query("SELECT * FROM SAV_ReponsesType  WHERE Id = '".$_POST['idReponse']."'"));
				$idReponse = $_POST['idReponse'];
				$TitreReponse = $rowReponse['Titre'];
				$ContenuReponse = $rowReponse['Contenu'];

			}
		break;
		case "Modifier" :
			if($_POST['idReponse'])
			{
				main_db_query("UPDATE SAV_ReponsesType  SET Titre= '".$_POST['TitreReponse']."',Contenu= '".$_POST['ContenuReponse']."' WHERE Id = '".$_POST['idReponse']."'");

			}
			else
				$error = "Modification non effective : veuillez saisir l'id de la reponse à modifier";
		break;
		case "Ajouter":
			if( $_POST['TitreReponse'] && $_POST['ContenuReponse'])
			{
				main_db_query("INSERT INTO SAV_ReponsesType (Titre,Contenu) VALUES ( '".$_POST['TitreReponse']."','".$_POST['ContenuReponse']."') ");
			}
			else
				$error = "Veuillez saisir le Titre et un contenu à la reponse à ajouter";
		break;
		case "Supprimer":
			if( $_POST['idReponse'] )
			{
				main_db_query( "DELETE FROM SAV_ReponsesType  WHERE Id = ".$_POST['idReponse'] );
			}
			else
				$error = "Veuillez saisir l'id de la reponse à supprimer";
		break;
	}



?>
<html>
<head>
	<title>- Administration -</title>
</head>
<body>
<link rel="stylesheet" href="admin.css">

<div class=universBold> Liste des SAV_ReponsesType  </div>
<table border=1 style="width:100%;">
	<tr class=trTitle>
		<td width=15px>Id</td>
		<td >Titre</td>
		<td >Contenu</td>
	</tr>
<?php
	$rows=main_db_query("SELECT * FROM SAV_ReponsesType  ORDER BY Titre ASC LIMIT ".$rankStart.",".$nbRowsToShow); 
	while($row=db_fetch_array($rows)) 
	{
?>
	<tr>
		<td align=right>&nbsp;<?php echo $row[Id]; ?></td> 
		<td><?php echo $row[Titre]; ?>&nbsp;</td> 
		<td><?php echo $row[Contenu]; ?>&nbsp;</td> 
	</tr> 
<?php 
	} 
?>
</table><br>
<table cellpadding=0 cellspacing=0 border=0 width=300px>
	<tr>
<?php
	if ($rankStart !=0)
	{
?>
		<td>
			<a class=under href="<?php echo $PHP_SELF."?rankStart=".($rankStart - $nbRowsToShow); ?>">&laquo; Les <?php echo $nbRowsToShow; ?> précédents</a>
		</td>
		<td>
			<a class=under href="<?php echo $PHP_SELF."?rankStart=0"; ?>">top</a>
		</td>
<?php
	}
?>
		<td align=right>
			<a class=under href="<?php echo $PHP_SELF."?rankStart=".($rankStart + $nbRowsToShow); ?>">Les <?php echo $nbRowsToShow; ?> suivants &raquo;</a>
		</td>
	</tr>
</table>
<br><br>
<div class=error><?php echo $error; ?></div>
<br>
<div class=universBold> Ajout/Suppression des Régions </div>
<br>

<form method="post" name="main">
<table cellspacing=10 cellpadding=0 border=0 class=univers>
	<tr>
		<td width=100px>
			Id (0 pour ajout) :
		</td>
		<td>
			<input type="text" size="5" name="idReponse" value="<?php echo $idReponse; ?>">
		</td>
	</tr>
	<tr>
		<td width=100px>
			Titre :
		</td>
		<td>
			<input type="text" size="50" name="TitreReponse" value="<?php echo $TitreReponse; ?>">
		</td>
	</tr>
	<tr>
		<td width=100px>
			Contenu :
		</td>
		<td>
		<?php 
			if(!isset($ContenuReponse))
			{
				$rowRepType = db_fetch_assoc(main_db_query("SELECT * FROM SAV_ReponsesType WHERE Titre='Vide'"));
				$ContenuReponse = $rowRepType['Contenu'];
			}
			?>		
			<textarea cols=80 rows=20 name="ContenuReponse" size=1><?php echo $ContenuReponse; ?></textarea>
		</td>
	</tr>
	<tr>
		<td colspan=2>
			<input type="submit" name="valider" value="Info">
			<input type="submit" name="valider" value="Ajouter">
			<input type="submit" name="valider" value="Modifier">
			<input type="submit" name="valider" value="Supprimer" onclick="return confirm( 'Etes vous sur de vouloir supprimer cette reponse ?' )">
		</td>
	</tr>
</table>
</form>

</body>
</html>

