Bonjour,
je fais mes premiers pas dans le développement, j'apprend le php et je fais une petite application sur la gestions de personnel, j'ai rencontré un soucis sur mon formulaire de congé . Je n'arrive pas à calculer le nombre de jours entre
deux dates (date de départ et date retour). Tout en excluant le dimanche qui est un jour fermé et les jours fériés. Svp aidez moi....
Voici mon code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> <script type="text/javascript" src="js/jquery.ui.datepicker-fr.js"></script> <script type="text/javascript"> $(function () { $(".datefield").datepicker(); }); </script> <title>Document sans titre</title> </head> <body><br /><br /> <?php $style1="style =\" border: solid #CCCCFF 1px; \""; $style2="style =\" border: solid #FF0000 1px; \""; ?> <?php if(isset($_POST['demander_conge'])){ $demander_conge=$_POST['demander_conge']; $matricule=$_POST['matricule']; $nom=$_POST['nom']; $prenom=$_POST['prenom']; $direction=$_POST['direction']; $service=$_POST['service']; $categorie=$_POST['categorie']; $type_conge=$_POST['type_conge']; $periode_allant=$_POST['periode_allant']; $au=$_POST['au']; $date=$_POST['date']; $nbre_jours=$_POST['nbre_jours']; $duree_service=$_POST['duree_service']; $duree=$_POST['duree']; $jours_compl=$_POST['jours_compl']; //--------------------------------------------- } function champ_vide($var){ if(strlen($var)>1){ return $var; } } function date_vide($var){ if(strlen($var)>=1){ return $var; } } function verif_mat($var){ $syntaxe_mat='#[0-9]{6}[A-Z]$#'; if(preg_match($syntaxe_mat, $var)){ return $var; } } function verification($matricule, $nom, $prenom, $direction, $service, $categorie, $type_conge, $periode_allant, $au, $date, $nbre_jours, $duree_service, $duree, $jours_compl) { if(champ_vide($matricule) && champ_vide($nom) && champ_vide($prenom) && champ_vide($direction) && champ_vide($service) && champ_vide($categorie) && champ_vide($type_conge) && champ_vide($periode_allant) && champ_vide($au) && champ_vide($date) && champ_vide($nbre_jours) && champ_vide($duree_service) && champ_vide($jours_compl)) { if(verif_mat($matricule)) { // Connection a la base des donnees try{ $bdd=new PDO('mysql:host=localhost; dbname=bd_grh', 'root', ''); } catch(Exception $e) { die('Erreur :'.$e->getMessage()); } $numero=$bdd->query('select * from demanderconge'); $sql=$bdd->prepare('insert into demanderconge (matricule, nom, prenom, direction, service, categorie, typeconge, periodeallant, au, date, nbrejours, dureeservice, duree, jourscompl) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); $sql->execute(array($matricule, $nom, $prenom, $direction, $service, $categorie, $type_conge, $periode_allant, $au, $date, $nbre_jours, $duree_service, $duree, $jours_compl)); if($sql!=false) { echo '<h1> Demande de conge enregistrée </h1>'; } else { echo 'Erreur lors de l\'enregistrement'; } } else { echo 'Erreur: numéro de matricule invalides';} } else { echo '<h1> <font color="FF0000"> Tous les champs sont obligatoires </font></h1>'; } } if(isset($demander_conge)){ verification($matricule, $nom, $prenom, $direction, $service, $categorie, $type_conge, $periode_allant, $au, $date, $nbre_jours, $duree_service, $duree, $jours_compl); } ?> <div class="conge"> <fieldset> <legend>Formulaire de demande conge</legend><br /> <form method="post"> <table> <tr><td>Matricule:</td><td><input name="matricule" <?php if(isset($demander_conge)){ if(champ_vide($matricule)) { echo $style1; } else{ echo $style2; } } ?> value="<?php if(isset($demander_conge)){echo $matricule; }?>" /> </td><td>Date de demande</td><td><input name="date" <?php if(isset($demander_conge)){ if(champ_vide($date)){ echo $style1; } else{ echo $style2; } } ?>value="<?php if(isset($demander_conge)){echo $date; }?>" class="datefield" /> </td></tr> <tr><td>Nom</td><td><input name="nom" <?php if(isset($demander_conge)){ if(champ_vide($nom)){ echo $style1; } else{ echo $style2; } } ?> /> </td> <td>Categorie</td><td><select name="categorie" <?php if(isset($demander_conge)){ if(champ_vide($categorie)){ echo $style1; } else{ echo $style2; } } ?>> <option>--Choisir une option --</option> <option value="HC">HC</option> <option value="A1">A1</option> <option value="A2">A2</option> <option value="A3">A3</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option><option value="E"></option><option value="F"></option></select></td></tr> <tr><td>Prenom</td><td><input name="prenom" <?php if(isset($demander_conge)){ if(champ_vide($prenom)){ echo $style1; } else{ echo $style2; } } ?>/></td> <td>Direction </td><td><select name="direction" <?php if(isset($demander_conge)){ if(champ_vide($direction)){ echo $style1; } else{ echo $style2; } } ?>> <option>--Choisir une option--</option> <option value="General">General</option> <option value="Technique">Technique</option> <option value="Commerciale">Commerciale</option> <option value="Financiere">Financiere</option> </select></td></tr> <tr><td>Type conge</td><td><select name="type_conge" <?php if(isset($demander_conge)){ if(champ_vide($type_conge)){ echo $style1; } else{ echo $style2; } } ?>><option> Choisir une option</option> <option value="Administratif">Administratif</option><option value="Pour convention personnel">Pour convention personnel</option> <option value="Maternite">Maternite</option><option value="Maladie">Maladie</option></select></td> <td>Service</td><td><select name="service" <?php if(isset($demander_conge)){ if(champ_vide($service)){ echo $style1; } else{ echo $style2; } } ?>> <option>--Choisir une option--</option> <option value="Etudes"> Etudes</option> <option value="RH"> RH</option> <option value="Comptable"> Comptable</option> <option value="Commerciale"> Commerciale</option> </select></td></tr> </table> <hr /><br /> <table> <tr><td>Periode allant</td> <td><input name="periode_allant" <?php if(isset($demander_conge)){ if(champ_vide($periode_allant)){ echo $style1; } else{ echo $style2; } } ?>value="<?php if(isset($demander_conge)){echo $periode_allant; }?>" class="datefield" /> </td> <td> Duree de service</td><td><select name="duree_service" <?php if(isset($demander_conge)){ if(champ_vide($duree_service)){ echo $style1; } else{ echo $style2; } } ?>> <option>--Choisir une option</option> <option value="3-4">3-4 ans</option><option value="5-9">5-9 ans</option><option value="10-14 ">10-14 ans</option> <option value="15-19">15-19 ans</option><option value="20-24">20-24 ans</option> <option value="25 ans-et plus">25 ans-et plus</option> </select></td></tr> <tr><td> Au </td><td><input name="au" <?php if(isset($demander_conge)){ if(champ_vide($date)){ echo $style1; } else{ echo $style2; } } ?>value="<?php if(isset($demander_conge)){echo $au; }?>" class="datefield" /> </td> <td> Soit</td><td><input name="nbre_jours" <?php if(isset($demander_conge)){ if(champ_vide($nbre_jours)){ echo $style1; } else{ echo $style2; } } ?> /> jours</td></tr> <tr><td>Jours complemantaires </td><td><input name="jours_compl" <?php if(isset($demander_conge)){ if(champ_vide($jours_compl)){ echo $style1; } else{ echo $style2; } } ?>/></td > <td>Duree Total</td><td><input name="duree" <?php if(isset($demander_conge)){ if(champ_vide($duree)){ echo $style1; } else{ echo $style2; } } ?> /></td></tr> </table> <br /><div><table width="194" border="0"> <tr> <td><input name="demander_conge" type="submit" value="Enregistrer" /> </td> <td><a href="pageaccueil.php?contexte=pageconge"> <input name="Retour" type="button" value="Retour"/> </a></td> </tr> </table></div><br /> </form> </fieldset> </div> </body> </html>
Afficher la suite