CREATE TABLE `employe` (
`ID` BIGINT NOT NULL AUTO_INCREMENT ,
`NOM` VARCHAR( 20 ) ,
`PRENOM` VARCHAR( 20 ) ,
`SALAIRE` DOUBLE DEFAULT '0',
PRIMARY KEY ( `ID` )
);
INSERT INTO `employe` ( `ID` , `NOM` , `PRENOM` , `SALAIRE` )
VALUES (
'', 'Dupond', 'Marcel', '8000'
);
INSERT INTO `employe` ( `ID` , `NOM` , `PRENOM` , `SALAIRE` )
VALUES (
'', 'Martin', 'Xavier', '4000'
);
INSERT INTO `employe` ( `ID` , `NOM` , `PRENOM` , `SALAIRE` )
VALUES (
'', 'Gogol', 'Henri', '3000'
);
INSERT INTO `employe` ( `ID` , `NOM` , `PRENOM` , `SALAIRE` )
VALUES (
'', 'Hugo', 'Victor', '2000'
);
INSERT INTO `employe` ( `ID` , `NOM` , `PRENOM` , `SALAIRE` )
VALUES (
'', 'Gali', 'Daniel', '6000'
);
INSERT INTO `employe` ( `ID` , `NOM` , `PRENOM` , `SALAIRE` )
VALUES (
'', 'Martin', 'Georges', '9000'
);
<?php
session_start();
require_once'Appli/appli.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Afficher le résultat d'un requête</title>
</head>
<body>
<h1> Choisissez dans le menu ci-dessous</h1>
<a href="liste.php?l=1">Afficher la liste des employés</a><br/>
<a href="liste.php?l=2">Afficher la liste des employés par ordre alphabétique</a><br/>
<a href="liste.php?l=3">Afficher la liste des employés par salaire décroissant</a><br/>
<a href="add.php">Ajouter un employé</a><br/>
<a href="delete.php">Supprimer un employé</a><br/>
<?php
if(is_admin())echo '<a href="disconnect.php">Se déconnecter</a><br/>';
?>
</body>
</html>
<?php
session_start();
require_once'Appli/appli.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Afficher la liste des employés</title>
</head>
<body>
<h1>Afficher la liste des employés</h1>
<?php
if(isset($_GET['l'])) {
$l=$_GET['l'];
} else {
$l=1;
}
liste($l,false);
?>
<br/>
<br/>
<a href="index.php">Retour à la page d'accueil</a>
</body>
</html>
<?php
session_start();
require_once'Appli/appli.php';
$_SESSION['add_NOM']='';
$_SESSION['add_PRENOM']='';
$_SESSION['add_SALAIRE']='';
$_SESSION['add_ERROR']=0;
if (is_admin()) {
require 'Appli/addForm.php';
} else {
$_SESSION['connect_target']='Appli/addForm.php';
$_SESSION['connect_error']=0;
$_SESSION['connect_login']='';
require 'Appli/connectForm.php';
}
?>
<?php
session_start();
require_once'Appli/appli.php';
if (is_admin()) {
if(isset($_POST['add'])) {
$nom=$_POST['nom'];
$prenom=$_POST['prenom'];
$salaire=$_POST['salaire'];
$r=add_liste($nom,$prenom,$salaire);
if ($r==0) {
echo '<meta http-equiv="Refresh" content="0;URL=index.php">';
} else {
$_SESSION['add_NOM']=$nom;
$_SESSION['add_PRENOM']=$prenom;
$_SESSION['add_SALAIRE']=$salaire;
$_SESSION['add_ERROR']=$r;
require 'Appli/addForm.php';
}
} else {
echo '<meta http-equiv="Refresh" content="0;URL=index.php">';
}
}
?>
<?php
session_start();
require_once'Appli/appli.php';
if (isset($_POST['connect'])) {
if (isset($_POST['login'])) {
$login = $_POST['login'];
} else {
$login = '';
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
} else {
$password = '';
}
}
if (connect($login, $password)) {
$target=$_SESSION['connect_target'];
} else {
$target = 'Appli/connectForm.php';
$_SESSION['connect_login'] = $login;
$_SESSION['connect_error'] = 1;
} else {
$target='index.php';
}
require $target;
?>
<?php
session_start();
require_once'Appli/appli.php';
disconnect();
?>
<meta http-equiv="Refresh" content="0;URL=index.php">
<?php
session_start();
require_once'Appli/appli.php';
if (is_admin()) {
require 'Appli/deleteForm.php';
} else {
$_SESSION['connect_target']='Appli/deleteForm.php';
$_SESSION['connect_error']=0;
$_SESSION['connect_login']='';
require 'Appli/connectForm.php';
}
?>
<?php
session_start();
require_once'Appli/appli.php';
if (is_admin()) {
$ID = $_GET['ID'];
delete($ID);
require 'Appli/deleteForm.php';
} else {
echo '<meta http-equiv="Refresh" content="0;URL=index.php">';
}
?>
<?php
$host = 'localhost';
$user = 'root';
$password = '';
$base = 'toto';
$admin_login = 'admin';
$admin_password = 'aligator';
?>
<?php
function is_admin()
{
return isset($_SESSION['admin']) and ($_SESSION['admin']==true);
}
function connect($login,$user_password)
{
$r=false;
require 'params.php';
if ($login==$admin_login and $user_password==$admin_password) {
$r=true;$_SESSION['admin']=true;}
return $r;
}
function disconnect()
{
$_SESSION['admin'] = false;
}
function liste($l,$editable)
{
require 'params.php';
mysql_connect($host,$user,$password) or die('Erreur le connexion au SGBD.');
mysql_select_db($base) or die('La base de données n\'existe pas');
if ($l==1) {
$query='SELECT * FROM employe';
} else if ($l==2) {
$query = 'SELECT * FROM employe ORDER BY NOM, PRENOM';
} else {
$query = 'SELECT * FROM employe ORDER BY SALAIRE DESC';
}
$r=mysql_query($query);
mysql_close();
if (editable==false) {
echo'<table><tr><td>NOM</td><td>PRENOM</td><td>SALAIRE</td></tr>';
} else {
echo'<table><tr><td>NOM</td><td>PRENOM</td><td>SALAIRE</td><td> </td></tr>';
}
while ($a=mysql_fetch_object($r)) {
$nom=$a->NOM;
$prenom=$a->PRENOM;
$salaire=$a->SALAIRE;
$ID=$a->ID;
if ($editable==false) {
echo"<tr><td>$nom</td><td>$prenom</td><td>$salaire</td></tr>";
} else {
echo"<tr><td>$nom</td><td>$prenom</td><td>$salaire</td><td><a href=\"deleteAction.php?ID=$ID\">SUPPRIMER</a></td></tr>";
}
echo '</table>';
}
function add_liste($nom,$prenom,$salaire)
{
$r = 0;
if ($nom == '') {
$r = 1;
} else if ($prenom == '') {
$r = 2;
} else if ($salaire == '') {
$r = 3;
} else {
require 'params.php';
mysql_connect($host,$user,$password) or die('Erreur le connexion au SGBD.');
mysql_select_db($base) or die('La base de données n\'existe pas');
$query="INSERT INTO employe (NOM, PRENOM, SALAIRE) VALUES ('$nom', '$prenom', '$salaire')";
mysql_query($query);
mysql_close();
}
return $r;
}
function delete($ID)
{
require 'params.php';
mysql_connect($host,$user,$password) or die('Erreur le connexion au SGBD.');
mysql_select_db($base) or die('La base de données n\'existe pas');
$query="DELETE FROM employe WHERE ID=$ID";
mysql_query($query);
mysql_close();
}
?>
<?php
session_start();
require_once'Appli/appli.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Connexion</title>
</head>
<body>
<h1> Connexion</h1>
<form method="post" action="connect.php">
<table>
<?php
$value=$_SESSION['connect_login'];
echo "<tr><td><b>LOGIN</b></td> <td><input type=\"text\" name=\"login\" value=\"$value\"/></td></tr>";
?>
<tr><td><b>MOT DE PASSE</b></td> <td><input type="password" name="password"/></td></tr>
<tr><td colspan="2"><input type="submit" value="Se connecter" name="connect"><input type="submit" value="Annuler" name="cancel"></td></tr>
</table>
</form>
<br/>
<?php
$error= $_SESSION['connect_error'];
if($error==1)echo'Erreur de connexion';
$_SESSION['connect_error']=0;
?>
<p/>
<a href="index.php">Retour</a>
</body>
</html>
<?php
session_start();
require_once'Appli/appli.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Ajouter</title>
</head>
<body>
<h1>Ajouter un employé</h1>
<form method="post" action="addAction.php">
<table>
<?php
$nom=$_SESSION['add_NOM'];
$prenom=$_SESSION['add_PRENOM'];
$salaire=$_SESSION['add_SALAIRE'];
echo '<tr><td><b>NOM</b></td> <td><input type="text" name="nom" value="'.$nom.'"/></td></tr>';
echo '<tr><td><b>PRENOM</b></td> <td><input type="text" name="prenom" value="'.$prenom.'"/></td></tr>';
echo '<tr><td><b>SALAIRE</b></td> <td><input type="text" name="salaire" value="'.$salaire.'"/></td></tr>';
?>
<tr><td colspan="2"><input type="submit" value="Ajouter" name="add"><input type="submit" value="Annuler" name="cancel"></td></tr>
</table>
</form>
<br/>
<?php
$error=$_SESSION['add_ERROR'];
if ($error==1) echo'ERREUR : le nom est vide';
if ($error==2) echo'ERREUR : le prénom est vide';
if ($error==3) echo'ERREUR : le salaire est vide';
?>
<p/>
<a href="index.php">Retour</a>
</body>
</html>
<?php
session_start();
require_once'Appli/appli.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Suppression</title>
</head>
<body>
<h1> Suppression</h1>
<?php
liste(2,true);
?>
<p/>
<a href="index.php">Retour</a>
</body>
</html>