<!DOCTYPE html>
<html>
	<head>
		<title>Gestion personnel</title>
		<?php $titre = 'Gestion personnel'; ?>
		<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_perso" action="ges_perso_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="login"> Login </label><span></span></td>
	    						<td><input type=text id="login" name="login"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="mdp"> Mdp </label><span></span></td>
	    						<td><input type=password id="mdp" name="mdp"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="fct"> Fonction </label><span></span></td>
	    						<td><input type=text id="fct" name="fct"></td>
	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_perso.action.value='add'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>


	        		<div id="tabs-2">
    				<!--tab content-->
	    				<table>
	    					<tr>
	    						<td><label for="id1"> Login </label><span></span></td>
	    						<td>
	    							<select id="id1" name="id1" class="styled-select">
										<option value=""> </option>
											<?php
												$query = "SELECT id_personnel, login FROM PERSONNEL ";
												$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_personnel");
													$nom = pg_fetch_result($result, $i, "login");
													echo '<option value='.$id.'>'; echo $nom;
													echo "</option>";
													$i++;
												}
											?>
									</select>
	    						</td>
	    					</tr>
	    					<tr>
	    						<td><label for="login1"> Login </label><span></span></td>
	    						<td><input type=text id="login1" name="login1"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="mdp1"> Mdp </label><span></span></td>
	    						<td><input type=password id="mdp1" name="mdp1"></td>
	    					</tr>
	    					<tr>
	    						<td><label for="fct1"> Fonction </label><span></span></td>
	    						<td><input type=text id="fct1" name="fct1"></td>
	    					</tr>
	    					<tr>
	    						<td><button id="valider" onclick="document.forms.ges_perso.action.value='mod'; submit();"> Valider </button></td>
	    					</tr>
	    				</table>
	        		</div>


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

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