<!DOCTYPE html>
<html>
	<head>
		<title>Gestion client</title>
		<?php $titre = 'Gestion client'; ?>
		<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_client" action="ges_client_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 class="ui"></span></td>
	    						<td><input type=text id="nom" name="nom"></td>

	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_client.action.value='add'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>


	        		<div id="tabs-2">
    				<!--tab content-->
	    				<table>
							<tr>
	    						<td><label for="id1"> ID </label><span></span></td>
	    						<td>
	    							<select id="id1" name="id1" class="styled-select">
										<option value=""> </option>
											<?php
												$query = "SELECT id_client, name FROM CLIENT ";
												$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_client");
													$nom = pg_fetch_result($result, $i, "name");
													echo '<option value='.$id.'>'; echo $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><button id="valider" onclick="document.forms.ges_client.action.value='mod'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>


	        		<div id="tabs-3">
    				<!--tab content-->
	    				<table>
	    					<tr>
	    						<td><label for="id2"> Nom </label><span></span></td>
	    						<td>
	    							<select id="id2" name="id2" class="styled-select">
										<option value=""> </option>
											<?php
												$query = "SELECT id_client, name FROM CLIENT ";
												$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_client");
													$nom = pg_fetch_result($result, $i, "name");
													echo '<option value='.$id.'>'; echo $nom;
													echo "</option>";
													$i++;
												}
											?>
									</select>
	    						</td>
	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_client.action.value='sup'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>
				</div>
			</form>
			<table>
				<thead>
					<td>ID</td>
					<td>Nom</td>
				</thead>
				<?php
					$query2 = "SELECT * FROM CLIENT ";
					$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_client")."</td>";
						echo "<td>".pg_fetch_result($result2, $b, "name")."</td>";
						?></tr><?php
						$b++;
					}

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