<?php
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>Déclaration de CodeType de Tracking</div>
<br>

<table border=1>
	<tr class=trTitle>
		<td>Id</td>
		<td>CodeType</td>
		<td>Description</td>

	</tr>
<?php
switch($submit)
{
	case "Valider":
		$info = db_fetch_array(main_db_query("SELECT * FROM Tracking_Type WHERE Id='".$Id."'"));
	
		$CodeType = str_replace("_","",$CodeType);
		
		if ($Id==0)
		{
			#nouveau
			main_db_query("INSERT INTO Tracking_Type (CodeType, Description) VALUES ('".$CodeType."', '".$Description."')");
		}
		else
		{
			# on update si c'est une modif
			main_db_query("UPDATE Tracking_Type SET CodeType='".$CodeType."', Description = '".$Description."' WHERE Id='".$Id."'");
		}

		break;
		
	case "Supprimer":
		main_db_query("DELETE FROM Tracking_Type WHERE Id='".$Id."'");
		$Id=0;
		$Description = "";
		$CodeType = "";

		break;
	
	case "Infos":
		$info = db_fetch_array(main_db_query("SELECT * FROM Tracking_Type WHERE Id='".$Id."'"));
		$Id = $info[Id];
		$Description = $info[Description];
		$CodeType = $info[CodeType];
		
		break;
}




$rows = main_db_query("SELECT * FROM Tracking_Type ORDER BY Id ASC");

while($row = db_fetch_array($rows))
{
	echo "<tr><td><a href='?Id=".$row['Id']."&submit=Infos'>".$row['Id']."</a></td>";
	echo "<td>".$row['CodeType']."</td>";
	echo "<td align=left>".$row['Description']."</td>";
	echo "</tr>";
}

?>
</table>


<form>
<table>
	<tr>
		<td>
			Id (vide ou egal 0 pour ajout):
		</td>
		<td>
			<input type="text" size=10 name=Id value="<?php echo $Id ?>">
		</td>
	</tr>
	<tr>
		<td>
			CodeType (20 car. sans "_"):
		</td>
		<td>
			<input type="text" size=20 name=CodeType value="<?php echo $CodeType ?>">
		</td>
	</tr>
	<tr>
		<td>
			Description (250 car.) :
		</td>
		<td>
			<input type="text" size=50 name=Description value="<?php echo $Description ?>">
		</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>