<!DOCTYPE html>
<html>
	<head>
		<title>Gestion consommable</title>
		<?php $titre = 'Gestion consommable'; ?>
		<meta charset="UTF-8">
		<?php include 'session.inc.php'; check_login(); ?>
		<link rel="stylesheet" href="style/style.css" />
		<link rel="stylesheet" href="style/style_jquery-ui.css">
		<script type="text/javascript" src="script/jquery.js"></script>
		<script type="text/javascript" src="script/jquery-ui.js"></script>
  		<script>
			$(function() {
				$( "#tabs" ).tabs();
			});
 		</script>

	</head>

	<body>
		<?php
			error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
			Include('../database.params.inc.php');
			$link = pg_connect("host=$machine user=$user password=$pwd dbname=$db")or die("Erreur de Connection !<br />".pg_last_error()) ;
		?>
    	<?php include("menu.php"); ?>
		<div id="contenu">
			<!-- Le contenu doit etre écrit ci-dessous -->

			<form method=post name="ges_conso" action="ges_conso_2.php">
				<input type='hidden' id='action' name='action' value='null'>

				<!-- Systeme d'onglet -->
				<div id="tabs">
					<ul>
						<li><a href="#tabs-1">Ajout</a></li>
						<li><a href="#tabs-2">Modification</a></li>
						<li><a href="#tabs-3">Suppression</a></li>
					</ul>


    				<div id="tabs-1">
    				<!--tab content-->
	    				<table>
	    					<tr>
	    						<td><label for="nom"> Nom </label><span></span></td>
	    						<td><input type=text id="nom" name="nom"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="type"> Type </label><span></span></td>
	    						<td><input type=text id="type" name="type"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="prix"> prix </label><span></span></td>
	    						<td><input type=numeric id="prix" name="prix" min="0"  placeholder="0"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="dispo"> Disponibilité </label><span></span></td>
	    						<td><input type= "radio" id="dispo" name="dispo" value="true"> OUI<input type= "radio" id="dispo" name="dispo" value="false"> NON</td>
	    					</tr>
	    					<tr>
	    						<td><label for="temps"> Temps </label><span></span></td>
	    						<td><input type=time placeholder="00:00:00" name="temps" id="temps"><br></td>
	    					</tr>
	    					<tr>
	    						<td><label for="info"> Informations </label><span></span></td>
	    						<td><input type=text id="info" name="info"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="img"> Image </label><span></span></td>
	    						<input type=hidden name="MAX_FILE_SIZE" value="716800">
	    						<td><input type=file id="img" name="img" ></td>
	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_conso.action.value='add'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>


	        		<div id="tabs-2">
    				<!--tab content-->
	    				<table>
	    					<tr>
	    						<td><label for="prod_list"> Produit </label><span></span></td>
	    						<td>
	    							<select id="prod_list" name="prod_list" class="styled-select">
										<option value=""> </option>
											<?php
												$query = "SELECT id_produit, type, nom FROM PRODUIT ";
												$result = pg_query($link, $query) or die("Erreur SQL !<br />$query<br />".pg_last_error()) ;
												$num = pg_num_rows($result);
												$i = 0;
												while ($i<$num)
												{
													$id = pg_fetch_result($result, $i, "id_produit");
													$type = pg_fetch_result($result, $i, "type");
													$nom = pg_fetch_result($result, $i, "nom");
													echo '<option value='.$id.'>'; echo $type." : ".$nom;
													echo "</option>";
													$i++;
												}
											?>
									</select>
	    						</td>
	    					</tr>
	    					<tr>
	    						<td><label for="nom1"> Nom </label><span></span></td>
	    						<td><input type=text id="nom1" name="nom1"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="type1"> Type </label><span></span></td>
	    						<td><input type=text id="type1" name="type1"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="prix1"> prix </label><span></span></td>
	    						<td><input type=numeric id="prix1" name="prix1" min="0"  placeholder="0"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="dispo1"> Disponibilité </label><span></span></td>
	    						<td><input type= "radio" id="dispo1" name="dispo1" value="true"> OUI<input type= "radio" id="dispo1" name="dispo1" value="false"> NON</td>
	    					</tr>
	    					<tr>
	    						<td><label for="temps1"> Temps </label><span></span></td>
	    						<td><input type=time placeholder="00:00:00" name="temps1" id="temps1"><br></td>
	    					</tr>
	    					<tr>
	    						<td><label for="info1"> Informations </label><span></span></td>
	    						<td><input type=text id="info1" name="info1"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="img1"> Image </label><span></span></td>
	    						<td><input type=file id="img1" name="img1" ></td>
	    						<input type=hidden name="MAX_FILE_SIZE" value="716800">
	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_conso.action.value='mod'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>


	        		<div id="tabs-3">
    				<!--tab content-->
	    				<table>
	    					<tr>
	    						<td><label for="prod_list1"> Produit </label><span></span></td>
	    						<td>
	    							<select id="prod_list1" name="prod_list1" class="styled-select">
										<option value=""> </option>
											<?php
												$query = "SELECT id_produit, type, nom FROM PRODUIT ";
												$result = pg_query($link, $query) or die("Erreur SQL !<br />$query<br />".pg_last_error()) ;
												$num = pg_num_rows($result);
												$i = 0;
												while ($i<$num)
												{
													$id = pg_fetch_result($result, $i, "id_produit");
													$type = pg_fetch_result($result, $i, "type");
													$nom = pg_fetch_result($result, $i, "nom");
													echo '<option value='.$id.'>'; echo $type." : ".$nom;
													echo "</option>";
													$i++;
												}
											?>
									</select>
	    						</td>
	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_conso.action.value='sup'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>
				</div>
			</form>
			<table>
				<thead>
					<td>ID</td>
					<td>Nom</td>
					<td>Type</td>
					<td>Prix</td>
					<td>Dispo</td>
					<td>temps</td>
					<td>information</td>
					<td>img</td>
				</thead>
				<?php
					$query2 = "SELECT * FROM PRODUIT ORDER BY id_produit";
					$result2 = pg_query($link, $query2) or die("Erreur SQL !<br />$query<br />".pg_last_error()) ;
					$tot = pg_num_rows($result2);
					$b = 0;
					while ($b < $tot) {
						?><tr><?php
						echo "<td>".pg_fetch_result($result2, $b, "id_produit")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "nom")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "type")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "prix")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "dispo")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "temps")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "information")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "img")."</td>";
						?></tr><?php
						$b++;
					}

				?>
			</table>
		</div>
	</body>
</html>