<html>

<head>
  <meta http-equiv='content-type' content='text/html;charset=utf-8'>
  <title>WebBike V1.0</title>
  <link href="style.css" rel="stylesheet" media="screen">
</head>

<body>
  <?php
  require 'database.inc.php';
  //session_start();
  //session_register("lg_user");
  //session_register("lg_password");
  //session_register("lg_admin");
  //session_register("lg_menu1");
  //session_register("lg_menu2");
  //session_register("lg_menu3");
  //session_register("lg_menu4");
  //session_register("lg_menu5");
  //session_register("lg_menu6");
  function tab_vac($annee, $NoClient)
  {
    //echo $requette2."<br/>\n";
    $resultat2 = AbsenceEmploye::getAbsenceByNoClientAndPeriod($NoClient, $annee . '-01-01', $annee . '-12-31');
    $tot_vac = 0;
    $tot_abs = 0;
    $tot_rec = 0;
    $tot_vacok = 0;
    echo "<TABLE border=1><TR><TH>Type</TH><TH>Début</TH><TH>Fin</TH><TH>Vacances demandées</TH><TH>Indisponibilité</TH><TH>Récupération</TH><TH>Vacances validées</TH></TR>\n";
    foreach ($resultat2 as $ligne2) {
      echo "<TR><TD>";
      echo "<a HREF='employe.php?new=0&Start=" . htmlspecialchars($ligne2['Debut']) . $ligne2['DebutMA'] . "&emp=" . htmlspecialchars($ligne2['NoClient']) . "' TARGET='_blank' rel='opener'>";
      if ($ligne2["Type"] == 0) {
        echo "Vacances";
      } else if ($ligne2["Type"] == 1) {
        echo "Indisponibilité";
      } else if ($ligne2["Type"] == 2) {
        echo "Récupération";
      } else if ($ligne2["Type"] == 3) {
        echo "Vacances validées";
      }
      echo "(" . $ligne2["Motif"] . ")</a></TD><TD>";
      $duree = 0;
      if ($ligne2["DebutMA"] == 0) {
        $duree += 0.5;
        echo "AM ";
      } else {
        echo "PM ";
      }
      echo Cree_Entree_Type("", 2, 0, $ligne2['Debut'], AFFICHAGE);
      echo "</TD><TD>";
      if ($ligne2["FinMA"] == 0) {
        echo "AM ";
      } else {
        $duree += 0.5;
        echo "PM ";
      }
      echo Cree_Entree_Type("", 2, 0, $ligne2['Fin'], AFFICHAGE);
      if ($ligne2["Debut"] != $ligne2["Fin"]) {
        $date = mktime(0, 0, 0, substr($ligne2["Debut"], 5, 2), substr($ligne2["Debut"], 8, 2), substr($ligne2["Debut"], 0, 4));
        $date_str = date("Y-m-d", $date);
        while ($date_str != $ligne2["Fin"]) {
          //echo $date_str." ";
          if (jour_ferie(date("d", $date), date("m", $date), date("Y", $date))) {
            if (date("Y", $date) == $annee) {
              $duree += 1;
            }
          }
          $date = mktime(0, 0, 0, substr($date_str, 5, 2), substr($date_str, 8, 2) + 1, substr($date_str, 0, 4));
          $date_str = date("Y-m-d", $date);
        }
        if (date("w", $date) == 6) {
          $duree -= 1;
        }
        if (date("w", $date) == 0) {
          $duree -= 1;
        }
      }
      echo "</TD><TD>";
      if ($ligne2["Type"] == 0) {
        $tot_vac += $duree;
        echo $duree;
      } else {
        echo "0";
      }
      echo "</TD><TD>";
      if ($ligne2["Type"] == 1) {
        $tot_abs += $duree;
        echo $duree;
      } else {
        echo "0";
      }
      echo "</TD><TD>";
      if ($ligne2["Type"] == 2) {
        $tot_rec += $duree;
        echo $duree;
      } else {
        echo "0";
      }
      echo "</TD><TD>";
      if ($ligne2["Type"] == 3) {
        $tot_vacok += $duree;
        echo $duree;
      } else {
        echo "0";
      }
      echo "</TD></TR>\n";
    }
    echo "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$tot_vac</TH><TH>$tot_abs</TH><TH>$tot_rec</TH><TH>$tot_vacok</TH></TR>";
    echo "</TABLE>\n";
  }
  if ((!empty($User)) && (!empty($Passwd))) {
    $lg_user = $User;
    $lg_password = $Passwd;
  }
  if (Test_User($lg_user, $lg_password) == TRUE) {
    $ligne = Client::getClientByNoClient($NoClient);
    echo "Absences : " . $ligne["Nom"] . " " . $ligne["Prenom"] . "<br />\n";
    tab_vac(Date("Y") - 2, $NoClient);
    tab_vac(Date("Y") - 1, $NoClient);
    tab_vac(Date("Y"), $NoClient);
    tab_vac(Date("Y") + 1, $NoClient);
  }
  ?>
</body>

</html>