<!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" />
	</head>

	<body>
    	<?php include("menu.php"); ?>
    	<div  id='contenu'>
    		<?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() ) ;


				switch ( $_POST['action'] ) {
					case "add" :
						$nom = htmlentities(trim($_POST['nom']), ENT_QUOTES);		
				
						if ( $nom!=""){
							$query = "INSERT INTO CLIENT(name) VALUES('$nom')";
							$result = pg_query($link, $query) or die("Erreur SQL !<br />$query<br />".pg_last_error());
						}
						else{
							header('Location: ges_client.php');
							exit();
						}
					break;

					case "mod" :
						$nom1 = htmlentities(trim($_POST['nom1']), ENT_QUOTES);
						$id1 = $_POST['id1'];
						if ( $nom1!=""){
							$query = "UPDATE CLIENT SET name='$nom1' WHERE id_client = '$id1'";
							$result = pg_query($link, $query) or die("Erreur SQL !<br />$query<br />".pg_last_error()) ;
						}
						else{
							header('Location: ges_client.php');
							exit();	
						}
					break;

					case "sup" :
						$id2 = $_POST['id2'];
						$query = "DELETE FROM CLIENT WHERE id_client = '$id2' ;";
						$result = pg_query($link, $query) or die("Erreur SQL !<br />$query<br />".pg_last_error()) ;
					break;
					
					default :
						header('Location: ges_client.php');
						exit();
				}

				header('Location: ges_client.php');
				exit();
			?>
		</div>
	</body>
</html>