<?php
require($_SERVER["DOCUMENT_ROOT"]."/gestionconges/config/db_config.php");
mysql_connect("$db_host","$db_user","$db_password") or die(mysql_error());
mysql_select_db("congedb") or die (mysql_error());
echo "<h3>Demande de congé :</h3>";
$matricule = isset($_GET["matricule"]) ? mysql_real_escape_string(trim($_GET['matricule'] )) : "";
$len = strlen($matricule);
if ($len > 0) {
processHolidayRequest();
} else {
displayForm();
}
function processHolidayRequest() {
$sql = " select
matricule,
nomprenom,
departement,
responsable,
nbrejoursan,
nbrejoursrest
FROM
employees
WHERE
matricule = '$matricule'";
$requeteid = mysql_query($sql) or die("Erreur SQL " . mysql_errno() . ": " . mysql_error() . " dans la requete " . $sql);
$ligne=mysql_fetch_assoc($requeteid);
echo "<p></p>";
echo "Matricule : ";
echo $matricule;
echo " <td> Nom : ", $ligne["nomprenom"], " </td>";
echo " <td><p>Département : ", $ligne["departement"], " </td>";
echo " <td> Responsable : ", $ligne["responsable"], " </td></p>";
echo " <td><p>Nombre de jours annuel : ", $ligne["nbrejoursan"], " </td>";
echo " <td> Nombre de jours restant : ", $ligne["nbrejoursrest"], " </td></p>";
echo "</tr>\n";
//set up variables for use in the update query
$nom = mysql_real_escape_string($ligne["nomprenom"]);
$resp = mysql_real_escape_string($ligne["responsable"]);
$de = isset($_POST["de"])? $_POST['de'] : '';
$a = isset($_POST["a"])? $_POST['a'] : '';;
$approuver = '0';
//convert the dates
$de = date("Y-m-d", strtotime(trim($de)));
$a = date("Y-m-d", strtotime(trim($a)));
$query = " INSERT
INTO conge
set
matricule = '$matricule',
nom = '$nom',
responsable = '$resp',
de = '$de',
a = '$a',
approuver = '$approuver'";
mysql_query($query) or die(mysql_error() . "<br/>sql etait: $query<br/>");
showSuccessMessage();
} //end process function
function displayForm() {
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" enctype="application/x-[URL unfurl="true"]www-form-urlencoded">[/URL]
<center>
<table>
<tr>
<td>
De :
</td>
<td>
<input type="text" name="de" size="8">
</td>
</tr>
<tr>
<td>
A :
</td>
<td>
<input type="text" name="a" size="8">
</td>
</tr>
<tr>
<td>
<input type="reset" value="Annuler" />
</td>
<td>
<input type="submit" value="Demander Approbation" />
</td>
</td>
</tr>
</table>
</center>
</form>
<? }
function showSuccessMessage(){
echo " Votre demande est bien envoyé à votre supérieur pour approbation";
}
?>