<?php
//$rlnoemployeurliste = isset($_REQUEST["noemployeur"])?$_REQUEST["noemployeur"]:"0";
$rlnoemployeurliste=0;
?>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" SRC="js/popcalendar.js"></script>
<SCRIPT type="text/javascript" SRC="js/lw_layers.js"></SCRIPT>
<SCRIPT type="text/javascript" SRC="js/lw_menu.js"></SCRIPT>
<script type="text/javascript" src="js/mootools-1.2.4-core-nc.js"></script>
<script type="text/javascript" src="js/imask.js"></script>
<SCRIPT type="text/javascript" SRC="js/ajoutlib.js"></SCRIPT>
<script type="text/javascript">
   var tag=0;
   var valeurliste1;
   var valeurliste2;
   var libflag=-1;

   function proc1(){
      if (tag==0) {
         requestEmploye('2',document.getElementById('lemployeur').value);
         requestPaiement(document.getElementById('lemployeur').value,-1,libflag,0);
         valeurliste1=document.getElementById('lemployeur').selectedIndex;
      }
   }

   function proc2(){
      var prm2=-1;
      if (typeof(document.getElementById('ListeEmployes')!="undefined")){
         if (document.getElementById('ListeEmployes').selectedIndex>0)
            prm2=document.getElementById('ListeEmployes').value;
      }
      requestPaiement(document.getElementById('lemployeur').value,prm2,libflag,0);
      valeurliste2=document.getElementById('ListeEmployes').selectedIndex;
   }

   function verifChangement(liste){
      tag=0;
      if (typeof(document.fermeture.crochet)!="undefined") {
         var champs=document.fermeture.crochet;
         if (champs.length==undefined){
            if (champs.checked) tag=1;
         } else if (champs.length>0) {
            for (i = 0; i < champs.length; i++) {
               if (champs[i].checked){
                  tag++;
               }
            }
         }
         if (tag>0){
            if (confirm("Il y a des modifications qui ne seront pas sauvegardées\nVoulez-vous continuer?","")){
               tag=0;
            } else {
               if (liste==1)
                  document.getElementById('lemployeur').selectedIndex=valeurliste1;
               else
                  document.getElementById('ListeEmployes').selectedIndex=valeurliste2;
            }
         }
      }
      if (tag==0) {
         if (liste==1)
            proc1();
         else
            proc2();
      }
   }


   //Rafra�chir le style de la ligne
   function rafraichirLigne(id){
      var ligne=document.getElementById("Crochet"+id);
      ligne.checked=true;
      var ligne2=document.getElementById("TRCrochet"+id);
      ligne2.style.backgroundColor = '#DA70D6';
      var ligne3=document.getElementById("imgbout"+id);
      ligne3.removeAttribute('src');
      ligne3.setAttribute("src", "images/save.png");

   }

   //Traiter toutes les lignes modifi�es pour sauvegarde
   function traiter(id){
      if (typeof(document.fermeture.crochet)!="undefined"){
         var source=document.getElementById("Crochet"+id+"");
         if (source.checked) {
            var champs2=document.getElementById("TRCrochet"+id+"");
            var prm2=obtientValeurs(champs2);
            traiterlignePaiement(id,prm2);
         }
         /*var champs=document.fermeture.crochet;
         if (champs.length==undefined && champs.checked) {

         }
         else if (champs.length>0) {
            var tableauModif=Array();
            var idt=0;
            for (var cpt = 0; cpt < champs.length; cpt++) {
               if (champs[cpt].checked){
                  tableauModif[idt]=cpt;
                  idt++;
               }
            }
            if (tableauModif.length>0) {
               for (var cpt = 0; cpt < tableauModif.length; cpt++) {
                  var idt=tableauModif[cpt];
                  var champs2=document.getElementById("TRCrochet"+champs[idt].value);
                  var prm2=obtientValeurs(champs2);

                  //alert(champs[idt].value);

                  traiterlignePaiement(champs[idt].value,prm2);
                  var Start = (new Date()).getTime();
                  var condition=true;
                  while(condition) {
                     if( ((new Date()).getTime() - Start) > 2000 ){
                        condition=false;
                     }
                  }
               }
            }
         }*/
      }
   }

   function inclureliberationsfermees(flag){
      if (document.getElementById(flag).checked)
         libflag=1
      else
         libflag=-1;
      verifChangement(2);
   }

   function changerPage(id){
      var prm2=-1;
      if (typeof(document.getElementById('ListeEmployes')!="undefined")){
         if (document.getElementById('ListeEmployes').selectedIndex>0)
            prm2=document.getElementById('ListeEmployes').value;
      }
      requestPaiement(document.getElementById('lemployeur').value,prm2,libflag,id);
      valeurliste2=document.getElementById('ListeEmployes').selectedIndex;
   }
</script>
<table width=100% border=0>
   <tr>
      <td>
         <b>
            <font size=+3>
               Paiements et fermetures
            </font>
         </b>
      </td>

      <td valign=bottom align=right>
         <form name="horloge" action="">
            Temps restant :
            <input readonly="readonly" style="background-color: rgb(204, 204, 204);" name="clock" value="" size="3" dir="rtl" type="text"> min:sec avant la fermeture
            automatique de la session.
            <input type="button" value="Fermer" onclick="javascript:window.location='index2.php';">
         </form>
      </td>
   </tr>
</table>
<script type="text/javascript">
   if (BrowserDetect.browser!=="Explorer" && !ns4) demarreHorloge();
</script>
<form name="menu" action="">
   <table width=50% border=0>
      <tr>
         <td>
            Employeur :<br>
            <select name="lemployeur" id="lemployeur" onchange="verifChangement(1);">
               <?php
               $sqla="SELECT nomemployeur, refemployeur FROM employeurs ORDER BY refemployeur";
               $result=mysql_query("$sqla") or die ("La requête (1) a échouée.");

               while ($champs2=mysql_fetch_row($result)) {
                  if (isset($rlnoemployeur) && $champs2[1]==$rlnoemployeur) {
                     printf("<option selected value='%d'>%s</option>\n",$champs2[1],stripslashes($champs2[0]));
                  }
                  else {
                     printf("<option value='%d'>%s</option>\n",$champs2[1],stripslashes($champs2[0]));
                  }
               }
               ?>
            </select>
         </td>
      </tr>
      <tr>
         <td>
            Employés :<br>
            <select name='ListeEmployes' id='ListeEmployes' size='1' onclick="verifChangement(2);">
               <option value="-1">--------------------</option>
               <?php
               $sqlb="SELECT CONCAT(employes.nomfamille, \", \", employes.prenom,  \", \", IF(ISNULL(employes.adresse1),' ',employes.adresse1),  \", \", IF(ISNULL(employes.ville),' ',employes.ville)) as nomemploye, employes.refemploye FROM employes INNER JOIN employeurs ON employes.refemployeur=employeurs.refemployeur ORDER BY CONCAT(employes.nomfamille, employes.prenom)";
               $result=mysql_query("$sqlb") or die ("La requête (2) a échouée.");
               while ($champs=mysql_fetch_row($result)) {
                  printf("<option value='%d'>%s</option>",$champs[1],htmlentities($champs[0],ENT_QUOTES,$ENCODAGE));
               }
               ?>
            </select>
         </td>
      </tr>
   </table>
</form>
<br>
<form name="inclusionliberationsfermees" action="">
   <label for="flag"><input type="checkbox" id="flag" onclick="inclureliberationsfermees('flag');">Inclure les libérations déjà fermée</label>
</form>
<script type="text/javascript">
   proc1();
</script>
<div id="tagupdate2">
</div>