<script language="javascript">
jQuery(document).ready(function($) { jQuery('.wbdatepicker').datepicker($.datepicker.regional[ "fr-CH" ]); });
</script>
<?php
  $max=40;
  if(isset($datestr))
  {
    $jour=substr($datestr,0,2);
    $mois=substr($datestr,3,2);
    $annee=substr($datestr,6,4);
  }
  else if(!isset($jour))
  {
    $jour=date("d");
    $mois=date("m");
    $annee=date("Y");
  }
  echo "<TABLE cellpadding=4 cellspacing=0>\n";
  echo "<TR><TD BGCOLOR=#f2f2f2 style='border-bottom:0.5pt solid black;border-top:0.5pt solid black;border-left:0.5pt solid black;border-right:0.5pt solid black;color: black;'>EMP</TD>";
  for($cpt=-1;$cpt<$max;$cpt++)
  {
    $date=mktime(0,0,0,$mois,$jour+$cpt,$annee);
    $a_jour = date("d",$date);
    $a_mois = date("m",$date);
    $a_annee = date("Y",$date);
    $a_semaine = date("w",$date);
    echo "<TD nowrap colspan=2 style='border-bottom:0.5pt solid black;border-top:0.5pt solid black;border-right:0.5pt solid black;color: black;'";
    if (jour_ferie($a_jour,$a_mois,$a_annee)==0)
    {
      echo " COLOR=#000000 BGCOLOR=#FFa500";
    }
    else
    {
      echo " COLOR=#000000 BGCOLOR=#f2f2f2";
    }
    echo ">" . substr(nom_jour($a_semaine),0,2) . "<br/>$a_jour.$a_mois<br/>$a_annee</TD>";
  }
  echo "</TR>\n";
  $nom_emp="LOCATION";
  $date=mktime(0,0,0,$mois,$jour-1,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  $date_debut="$a_annee-$a_mois-$a_jour";
  $date=mktime(0,0,0,$mois,$jour+$max-1,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  $date_fin="$a_annee-$a_mois-$a_jour";
  $nb_abs=0;
  if ($resultat3 = AbsenceEmploye::getAbsenceByNoClientAndPeriod(1, $date_debut, $date_fin))
  {
    foreach($resultat3 as $ligne3)
    {
      $deb=$ligne3['Debut'];
      $fin=$ligne3['Fin'];
      $abs_deb[$nb_abs]=substr($deb,0,4).substr($deb,5,2).substr($deb,8,2)."0".$ligne3['DebutMA'];
      $abs_fin[$nb_abs]=substr($fin,0,4).substr($fin,5,2).substr($fin,8,2)."0".$ligne3['FinMA'];
      $abs_type[$nb_abs]=$ligne3['Type'];
      $abs_nom[$nb_abs]= "<A TITLE='Debut ". Cree_Entree_Type("",2,0,$ligne3['Debut'],AFFICHAGE)." Fin ".Cree_Entree_Type("",2,0,$ligne3['Fin'],AFFICHAGE)."' HREF='employe.php?new=0&Start=" . htmlspecialchars($ligne3['Debut']).$ligne3['DebutMA'] . "&emp=" . htmlspecialchars($ligne3['NoClient']) . "' TARGET='_blank' rel='opener'>" . $ligne3['Motif'] . "&nbsp;</A>";
      $nb_abs++;
    }
  }
  echo "<TR>\n <TH BGCOLOR=#f2f2f2 nowrap style='border-bottom:0.5pt solid black;border-left:0.5pt solid black;border-right:0.5pt solid black;color: black;'>$nom_emp</TH>\n";
  $cpt_abs=0;
  $abs_start=0;
  $abs_stop=0;
  $abs_size=0;
  for($cpt=-1;$cpt<$max;$cpt++)
  {
    $date=mktime(0,0,0,$mois,$jour+$cpt,$annee);
    $a_jour = date("d",$date);
    $a_mois = date("m",$date);
    $a_annee = date("Y",$date);
    $a_semaine = date("w",$date);
    for($cpt2=0;$cpt2<2;$cpt2++)
    {
      $tmp_txt="<A TITLE='nouvelle location' HREF='employe.php?new=1&jour=$a_jour&mois=$a_mois&annee=$a_annee&periode=$cpt2&NoClient=1' TARGET='_blank' rel='opener'>l</A>";
      $abs_size++;
      if ($abs_start==0)
        echo " <TD ALIGN='center'";
      if ($cpt2<10)
        $tmp_date= $a_annee . $a_mois . $a_jour . "0" . $cpt2;
      else
        $tmp_date= $a_annee . $a_mois . $a_jour . $cpt2;
      if ($nb_abs>$cpt_abs)
      {
        if ($tmp_date>=$abs_deb[$cpt_abs] && $abs_start==0)
        {
          echo " BGCOLOR='";
          switch ($abs_type[$cpt_abs])
          {
            case 0:
              echo "#FFFFFF";
            break;
            case 1:
              echo "#00EF00";
            break;
            case 2:
              echo "#FF8000";
            break;
            case 3:
              echo "#FFFF00";
            break;
          }
          echo "' NOWRAP";
          $abs_start=1;
          $abs_size=1;
          if($tmp_date>$abs_deb[$cpt_abs])
          {
            $abs_nom[$cpt_abs]=htmlspecialchars("<-- ") . $abs_nom[$cpt_abs];
          }
          if ($tmp_date==$abs_fin[$cpt_abs])
          {
            $abs_start=0;
            $abs_stop=1;
            echo " COLSPAN=$abs_size class=case2";
            $tmp_txt="<B>".$abs_nom[$cpt_abs]."</B>";
            $cpt_abs++;
            $abs_size=0;
          }
        }
        else if ($tmp_date==$abs_fin[$cpt_abs])
        {
          $abs_start=0;
          $abs_stop=1;
          echo " COLSPAN=$abs_size class=case2";
          $tmp_txt="<B>".$abs_nom[$cpt_abs]."</B>";
          $cpt_abs++;
          $abs_size=0;
        }
        else if (jour_ferie($a_jour,$a_mois,$a_annee)==0 && $abs_start==0)
        {
          echo " BGCOLOR=#8080FF class=case1";
        }
        else if ($abs_start==0 && $abs_stop==0)
        {
          echo " class=case1";
        }
      }
      else if (jour_ferie($a_jour,$a_mois,$a_annee)==0)
      {
        echo " BGCOLOR=#8080FF class=case1";
      }
      else
      {
        echo " class=case1";
      }
      if ($abs_start==0)
        echo ">$tmp_txt</TD>\n";
      $abs_stop=0;
    }
  }
  if ($abs_start==1)
  {
    echo " COLSPAN=$abs_size class=case2";
    $tmp_txt="<B>".$abs_nom[$cpt_abs]. htmlspecialchars(" -->") ."</B>";
    echo ">$tmp_txt</TD>\n";
  }
  echo "</TR>\n";
//----------------------------------------------------------------------------------------------------
  $nom_emp="TOUS";
  $date=mktime(0,0,0,$mois,$jour-1,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  $date_debut="$a_annee-$a_mois-$a_jour";
  $date=mktime(0,0,0,$mois,$jour+$max-1,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  $date_fin="$a_annee-$a_mois-$a_jour";
  $nb_abs=0;
  if ($resultat3 = AbsenceEmploye::getAbsenceByNoClientAndPeriod(0, $date_debut, $date_fin))
  {
    foreach($resultat3 as $ligne3)
    {
      $deb=$ligne3['Debut'];
      $fin=$ligne3['Fin'];
      $abs_deb[$nb_abs]=substr($deb,0,4).substr($deb,5,2).substr($deb,8,2)."0".$ligne3['DebutMA'];
      $abs_fin[$nb_abs]=substr($fin,0,4).substr($fin,5,2).substr($fin,8,2)."0".$ligne3['FinMA'];
      $abs_type[$nb_abs]=$ligne3['Type'];
      $abs_nom[$nb_abs]= "<A TITLE='Debut ". Cree_Entree_Type("",2,0,$ligne3['Debut'],AFFICHAGE)." Fin ".Cree_Entree_Type("",2,0,$ligne3['Fin'],AFFICHAGE)."' HREF='employe.php?new=0&Start=" . htmlspecialchars($ligne3['Debut']).$ligne3['DebutMA'] . "&emp=" . htmlspecialchars($ligne3['NoClient']) . "' TARGET='_blank' rel='opener'>" . $ligne3['Motif'] . "&nbsp;</A>";
      $nb_abs++;
    }
  }
  echo "<TR>\n <TH BGCOLOR=#f2f2f2 nowrap style='border-bottom:0.5pt solid black;border-left:0.5pt solid black;border-right:0.5pt solid black;color: black;'>$nom_emp</TH>\n";
  $cpt_abs=0;
  $abs_start=0;
  $abs_stop=0;
  $abs_size=0;
  for($cpt=-1;$cpt<$max;$cpt++)
  {
    $date=mktime(0,0,0,$mois,$jour+$cpt,$annee);
    $a_jour = date("d",$date);
    $a_mois = date("m",$date);
    $a_annee = date("Y",$date);
    $a_semaine = date("w",$date);
    for($cpt2=0;$cpt2<2;$cpt2++)
    {
      $tmp_txt="<A TITLE='nouvelle location' HREF='employe.php?new=1&jour=$a_jour&mois=$a_mois&annee=$a_annee&periode=$cpt2&NoClient=0' TARGET='_blank' rel='opener'>l</A>";
      $abs_size++;
      if ($abs_start==0)
        echo " <TD ALIGN='center'";
      if ($cpt2<10)
        $tmp_date= $a_annee . $a_mois . $a_jour . "0" . $cpt2;
      else
        $tmp_date= $a_annee . $a_mois . $a_jour . $cpt2;
      if ($nb_abs>$cpt_abs)
      {
        if ($tmp_date>=$abs_deb[$cpt_abs] && $abs_start==0)
        {
          echo " BGCOLOR='";
          switch ($abs_type[$cpt_abs])
          {
            case 0:
              echo "#FFFFFF";
            break;
            case 1:
              echo "#00EF00";
            break;
            case 2:
              echo "#FF8000";
            break;
            case 3:
              echo "#FFFF00";
            break;
          }
          echo "' NOWRAP";
          $abs_start=1;
          $abs_size=1;
          if($tmp_date>$abs_deb[$cpt_abs])
          {
            $abs_nom[$cpt_abs]=htmlspecialchars("<-- ") . $abs_nom[$cpt_abs];
          }
          if ($tmp_date==$abs_fin[$cpt_abs])
          {
            $abs_start=0;
            $abs_stop=1;
            echo " COLSPAN=$abs_size class=case2";
            $tmp_txt="<B>".$abs_nom[$cpt_abs]."</B>";
            $cpt_abs++;
            $abs_size=0;
          }
        }
        else if ($tmp_date==$abs_fin[$cpt_abs])
        {
          $abs_start=0;
          $abs_stop=1;
          echo " COLSPAN=$abs_size class=case2";
          $tmp_txt="<B>".$abs_nom[$cpt_abs]."</B>";
          $cpt_abs++;
          $abs_size=0;
        }
        else if (jour_ferie($a_jour,$a_mois,$a_annee)==0 && $abs_start==0)
        {
          echo " BGCOLOR=#8080FF class=case1";
        }
        else if ($abs_start==0 && $abs_stop==0)
        {
          echo " class=case1";
        }
      }
      else if (jour_ferie($a_jour,$a_mois,$a_annee)==0)
      {
        echo " BGCOLOR=#8080FF class=case1";
      }
      else
      {
        echo " class=case1";
      }
      if ($abs_start==0)
        echo ">$tmp_txt</TD>\n";
      $abs_stop=0;
    }
  }
  if ($abs_start==1)
  {
    echo " COLSPAN=$abs_size class=case2";
    $tmp_txt="<B>".$abs_nom[$cpt_abs]. htmlspecialchars(" -->") ."</B>";
    echo ">$tmp_txt</TD>\n";
  }
  echo "</TR>\n";
//----------------------------------------------------------------------------------------------------
  if ($resultat = Employee::getActifEmployee())
  {
    foreach($resultat as $ligne)
    {
        if($ligne2 = Client::getClientByNoClient($ligne['NoClient']))
        {
          $nom_emp = $ligne2['Nom'] . " " . $ligne2['Prenom'];
        }
      $date=mktime(0,0,0,$mois,$jour-1,$annee);
      $a_jour = date("d",$date);
      $a_mois = date("m",$date);
      $a_annee = date("Y",$date);
      $date_debut="$a_annee-$a_mois-$a_jour";
      $date=mktime(0,0,0,$mois,$jour+$max-1,$annee);
      $a_jour = date("d",$date);
      $a_mois = date("m",$date);
      $a_annee = date("Y",$date);
      $date_fin="$a_annee-$a_mois-$a_jour";
      $nb_abs=0;
      if ($resultat3 = AbsenceEmploye::getAbsenceByNoClientAndPeriod($ligne['NoClient'], $date_debut, $date_fin))
      {
        foreach($resultat3  as $ligne3)
        {
          $deb=$ligne3['Debut'];
          $fin=$ligne3['Fin'];
          $abs_deb[$nb_abs]=substr($deb,0,4).substr($deb,5,2).substr($deb,8,2)."0".$ligne3['DebutMA'];
          $abs_fin[$nb_abs]=substr($fin,0,4).substr($fin,5,2).substr($fin,8,2)."0".$ligne3['FinMA'];
          $abs_type[$nb_abs]=$ligne3['Type'];
          $abs_nom[$nb_abs]= "<A TITLE='Debut ". Cree_Entree_Type("",2,0,$ligne3['Debut'],AFFICHAGE)." Fin ".Cree_Entree_Type("",2,0,$ligne3['Fin'],AFFICHAGE)."' HREF='employe.php?new=0&Start=" . htmlspecialchars($ligne3['Debut']).$ligne3['DebutMA'] . "&emp=" . htmlspecialchars($ligne3['NoClient']) . "' TARGET='_blank' rel='opener'>" . $ligne3['Motif'] . "&nbsp;</A>";
          $nb_abs++;
        }
      }
      echo "<TR>\n <TD BGCOLOR=#f2f2f2 nowrap style='border-bottom:0.5pt solid black;border-left:0.5pt solid black;border-right:0.5pt solid black;color: black;'><a HREF='absences.php?NoClient=".$ligne['NoClient']."' TARGET='_blank' rel='opener'>$nom_emp</a></TD>\n";
      $cpt_abs=0;
      $abs_start=0;
      $abs_stop=0;
      $abs_size=0;
      for($cpt=-1;$cpt<$max;$cpt++)
      {
        $date=mktime(0,0,0,$mois,$jour+$cpt,$annee);
        $a_jour = date("d",$date);
        $a_mois = date("m",$date);
        $a_annee = date("Y",$date);
        $a_semaine = date("w",$date);
        for($cpt2=0;$cpt2<2;$cpt2++)
        {
          $tmp_txt="<A TITLE='nouvelle location' HREF='employe.php?new=1&jour=$a_jour&mois=$a_mois&annee=$a_annee&periode=$cpt2&NoClient=" . htmlspecialchars($ligne['NoClient']) . "' TARGET='_blank' rel='opener'>l</A>";
          $abs_size++;
          if ($abs_start==0)
            echo " <TD ALIGN='center'";
          if ($cpt2<10)
            $tmp_date= $a_annee . $a_mois . $a_jour . "0" . $cpt2;
          else
            $tmp_date= $a_annee . $a_mois . $a_jour . $cpt2;
          if ($nb_abs>$cpt_abs)
          {
            if ($tmp_date>=$abs_deb[$cpt_abs] && $abs_start==0)
            {
              echo " BGCOLOR='";
              switch ($abs_type[$cpt_abs])
              {
                case 0:
                  echo "#FFFFFF";
                break;
                case 1:
                  echo "#00EF00";
                break;
                case 2:
                  echo "#FF8000";
                break;
                case 3:
                  echo "#FFFF00";
                break;
			  }
              echo "' NOWRAP";
              $abs_start=1;
              $abs_size=1;
              if($tmp_date>$abs_deb[$cpt_abs])
              {
                $abs_nom[$cpt_abs]=htmlspecialchars("<-- ") . $abs_nom[$cpt_abs];
              }
              if ($tmp_date==$abs_fin[$cpt_abs])
              {
                $abs_start=0;
                $abs_stop=1;
                echo " COLSPAN=$abs_size class=case2";
                $tmp_txt="<B>".$abs_nom[$cpt_abs]."</B>";
                $cpt_abs++;
                $abs_size=0;
              }
            }
            else if ($tmp_date==$abs_fin[$cpt_abs])
            {
              $abs_start=0;
              $abs_stop=1;
              echo " COLSPAN=$abs_size class=case2";
              $tmp_txt="<B>".$abs_nom[$cpt_abs]."</B>";
              $cpt_abs++;
              $abs_size=0;
            }
            else if (jour_ferie($a_jour,$a_mois,$a_annee)==0 && $abs_start==0)
            {
              echo " BGCOLOR=#8080FF class=case1";
            }
            else if ($abs_start==0 && $abs_stop==0)
            {
              echo " class=case1";
            }
          }
          else if (jour_ferie($a_jour,$a_mois,$a_annee)==0)
          {
            echo " BGCOLOR=#8080FF class=case1";
          }
          else
          {
            echo " class=case1";
          }
          if ($abs_start==0)
            echo ">$tmp_txt</TD>\n";
          $abs_stop=0;
        }
      }
      if ($abs_start==1)
      {
        echo " COLSPAN=$abs_size class=case2";
        $tmp_txt="<B>".$abs_nom[$cpt_abs]. htmlspecialchars(" -->") ."</B>";
        echo ">$tmp_txt</TD>\n";
      }
      echo "</TR>\n";
    }
  }
  echo "</TABLE>\n";
  echo "<TABLE><TR><TD><form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='3'>";
  $date=mktime(0,0,0,$mois,$jour-14,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  echo "<SCRIPT language=JavaScript>\ntype=$Type;\nsous_type=$Sous_Type;\nmemnoform=5;\njour_down=$a_jour;\nmois_down=$a_mois;\nannee_down=$a_annee;\n</SCRIPT>\n";
  echo "<INPUT type='hidden' name='jour' value='$a_jour'><INPUT type='hidden' name='mois' value='$a_mois'><INPUT type='hidden' name='annee' value='$a_annee'>";
  echo "<BUTTON type='submit'>AV</BUTTON></form></TD>";
  echo "<TD><form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='3'>";
  $date=mktime(0,0,0,$mois,$jour+14,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  echo "<SCRIPT language=JavaScript>\njour_up=$a_jour;\nmois_up=$a_mois;\nannee_up=$a_annee;\n</SCRIPT>\n";
  echo "<INPUT type='hidden' name='jour' value='$a_jour'><INPUT type='hidden' name='mois' value='$a_mois'><INPUT type='hidden' name='annee' value='$a_annee'>";
  echo "<BUTTON type='submit'>AP</BUTTON></form></TD></TR></TABLE><BR>\n";
  echo "<form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='3'>";
  echo "<TABLE><TR><TD>";
  $date=mktime(0,0,0,$mois,$jour,$annee);
  $date=date("d.m.Y",$date);
  echo "<input type='text' class='wbdatepicker' name='datestr' value='$date' size='10'>";
  // echo "<TH>Jour</TH><INPUT type='text' name='jour' value='$jour' size=2></TD>";
  //echo "<TH>Mois</TH><TD><INPUT type='text' name='mois' value='$mois' size=2></TD>";
  //echo "<TH>Annee</TH><TD><INPUT type='text' name='annee' value='$annee' size=4>";
  echo "</TD><TD><BUTTON type='submit'>GO</BUTTON></TD></TR>";
  echo "</TABLE>";
  echo "</form>";
?>
