<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
?>
  <html>

  <head>
    <meta http-equiv='content-type' content='text/html;charset=utf-8'>
    <link rel="stylesheet" href="jquery/themes/ui-lightness/jquery-ui-1.9.2.custom.min.css">
    <script src="jquery/jquery-1.8.3.min.js"></script>
    <script src="jquery/jquery-ui-1.9.2.custom.min.js"></script>
    <script src="jquery/jquery.ui.datepicker-fr-CH.min.js"></script>
    <SCRIPT language=JavaScript src='valideformulaire.js?v1' type=text/javascript></SCRIPT>
    <SCRIPT language=JavaScript src='location.js?v2' type=text/javascript></SCRIPT>
    <title>WebBike V<?php echo VERSION; ?></title>
    <?php
    $size = 2;
    if ($ligne = Poste::getPostesByIP()) {
      $size = $ligne['Size'];
    }
    echo "<link href='css/style$size.css' rel='stylesheet' media='screen'>\n";

    echo "<link href='" . CSS_FOLDER . "style.css' rel='stylesheet' media='screen'>\n"
    ?>
  </head>

  <body>
  <?php
  $annee = date("Y");
  if ($new == 1) {
    echo "<form METHOD='GET' name='info' action='ok_location.php'>";
    echo "<input type='hidden' name='pri' value='0'>\n";
    echo "<input type='hidden' name='fact' value='0'>\n";
    echo "<input type='hidden' name='etape' value='0'>\n";
    // BLOC 1 //    
    echo "<TABLE border=1>";
    location_bloc_vehicule(null);
    //    echo "</TABLE><BR>\n";
    // BLOC 2 //    
    //    echo "<TABLE border=1>";
    location_bloc_client(null);
    //    echo "</TABLE><BR>\n";
    // BLOC 3 //    
    //    echo "<TABLE border=1>";
    echo "<TR><TH>Début</TH><TD colspan='3'>";
    $date = mktime($periode * 2 + 8, 0, 0, $mois, $jour, $anneed);
    bloc_date_15min_new("debut", $date);
    echo "</TD></TR>\n";
    echo "<TR><TH>Fin</TH><TD colspan='3'>";
    if (isset($_GET["NoClient"])) {
      $date = mktime(18, 0, 0, $mois, $jour, $anneed);
    } else {
      $date = mktime($periode * 2 + 8, 0, 0, $mois, $jour + 2, $anneed);
    }
    bloc_date_15min_new("fin", $date);
    echo "</TD></TR>";
    //    echo "</TABLE><BR>\n";
    // BLOC 4 //    
    //    echo "<TABLE border=1>";
    location_bloc_tarif(null);
    location_bloc_acompte(null);
    location_km_date_heure_depart(null);
    location_personne_rdv_depart(null);
    echo "</TABLE><BR>\n";
    // BOUTONS //
    location_bouton_valider(null);
    location_bouton_imprimer_contrat(null);
    echo "<BR /><BR /><BIG>Démarrer Location</BIG><BR /><BR />\n";
    location_bouton_demarrer_contrat(null);
    location_bouton_demarrer_contrat_facture(null);
    echo "<BR /><BR /><BIG>Démarrer Prêt</BIG><BR /><BR />\n";
    location_bouton_debut_pret(null);
    echo "</form>";
  }
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
  else {
    if ($ligne = Location::getByNoChassisAndDateDebutExact(addslashes($vhc), $Start)[0]) {
      echo "<form METHOD='GET' name='info' action='ok_location.php'>";
      echo "<input type='hidden' name='vhc' value='$vhc'>\n";
      echo "<input type='hidden' name='Start' value='$Start'>\n";
      echo "<input type='hidden' name='pri' value='0'><BR>\n";
      echo "<input type='hidden' name='fact' value='0'><BR>\n";
      echo "<input type='hidden' name='etape' value='" . $ligne['Etape'] . "'>\n";
      echo "<input type='hidden' name='upd' value='1'>\n";
      // BLOC 1 //        
      echo "<TABLE border=1>";
      location_bloc_vehicule($ligne);
      //        echo "</TABLE><BR>\n";
      // BLOC 2 //        
      //        echo "<TABLE border=1>";
      location_bloc_client($ligne);
      //        echo "</TABLE><BR>\n";
      // BLOC 3 //        
      //        echo "<TABLE border=1>";
      echo "<TR><TH>Début</TH><TD colspan='3'>";
      $date = mktime(substr($ligne['Debut'], 11, 2), substr($ligne['Debut'], 14, 2), 0, substr($ligne['Debut'], 5, 2), substr($ligne['Debut'], 8, 2), substr($ligne['Debut'], 0, 4));
      bloc_date_15min_new("debut", $date);
      echo "</TD></TR>\n";
      echo "<TR><TH>Fin</TH><TD colspan='3'>";
      $date = mktime(substr($ligne['Fin'], 11, 2), substr($ligne['Fin'], 14, 2), 0, substr($ligne['Fin'], 5, 2), substr($ligne['Fin'], 8, 2), substr($ligne['Fin'], 0, 4));
      bloc_date_15min_new("fin", $date);
      echo "</TD></TR>";
      //        echo "</TABLE><BR>\n";
      // BLOC 4 //        
      //        echo "<TABLE border=1>";
      location_bloc_tarif($ligne);
      switch ($ligne['Etape']) {
        case 0:
          if ($ligne['Acompte'] != 0) {
            echo "<TR><TH>Acompte</TH><TD>" . $ligne['Acompte'];
            echo " <BUTTON TYPE='button' onClick='go_facture(" . $ligne['NoCommande'] . ", 0);' style='width:150px'>Facture " . $ligne['NoCommande'] . "</button><BR>\n";
            echo "</TD></TR>";
            $as_acompte = true;
          } else {
            location_bloc_acompte($ligne);
            $as_acompte = false;
          }
          break;
        case 1:
          if ($ligne['Facture'] == 0) {
            if ($ligne['Acompte'] != 0) {
              echo "<TR><TH>Acompte</TH><TD>" . $ligne['Acompte'];
              echo " <BUTTON TYPE='button' onClick='go_facture(" . $ligne['NoCommande'] . ", 0);' style='width:150px'>Facture " . $ligne['NoCommande'] . "</button><BR>\n";
              echo "</TD></TR>";
              $as_acompte = true;
            } else {
              location_bloc_acompte($ligne);
              $as_acompte = false;
            }
          } else {
            if ($ligne['Acompte'] != 0) {
              echo "<TR><TH>Acompte</TH><TD>" . $ligne['Acompte'];
              echo " <BUTTON TYPE='button' onClick='go_facture(" . $ligne['NoCommande'] . ", 0);' style='width:150px'>Facture " . $ligne['NoCommande'] . "</button><BR>\n";
              echo "</TD></TR>";
              $as_acompte = true;
            }
          }
          break;
        case 2:
          if ($ligne['Acompte'] != 0) {
            echo "<TR><TH>Acompte</TH><TD>" . $ligne['Acompte'];
            echo " <BUTTON TYPE='button' onClick='go_facture(" . $ligne['NoCommande'] . ", 0);' style='width:150px'>Facture " . $ligne['NoCommande'] . "</button><BR>\n";
            echo "</TD></TR>";
            $as_acompte = true;
          }
          break;
      }
      //        echo "</TABLE><BR>\n";
      // BLOC 5 //        
      //        echo "<TABLE border=1>\n";
      location_km_date_heure_depart($ligne);
      if ($ligne['Etape'] != 0) {
        location_km_date_heure_retour($ligne);
      }
      location_personne_rdv_depart($ligne);
      echo "</TABLE><BR>\n";
      // BOUTONS //        
      location_bouton_valider($ligne);
      switch ($ligne['Etape']) {
        case 0:
          location_bouton_imprimer_contrat($ligne);
          echo "<BR /><BR /><BIG>Démarrer Location</BIG><BR /><BR />\n";
          location_bouton_demarrer_contrat($ligne);
          location_bouton_demarrer_contrat_facture($ligne);
          if ($ligne['Acompte'] == 0) {
            echo "<BR /><BR /><BIG>Démarrer Prêt</BIG><BR /><BR />\n";
            location_bouton_debut_pret($ligne);
          }
          break;
        case 1:
          location_bouton_imprimer_contrat($ligne);
          if ($ligne["NoCommande"] == "") {
            location_bouton_creer_facture($ligne);
          }
          echo "<BR /><BR /><BIG>Retours</BIG><BR /><BR />\n";
          if ($ligne['Facture'] == 0) {
            location_bouton_retour_avec_facture($ligne);
            if ($ligne['Acompte'] == 0) {
              location_bouton_retour_sans_facture($ligne);
            }
          } else {
            location_bouton_retour_location($ligne);
          }
          break;
        case 2:
          location_bouton_imprimer_contrat($ligne);
          break;
        case 3:
          break;
      }
      echo "</form>";
      if ($ligne['Etape'] < 2 && $ligne['NoCommande'] == 0) {
        echo "<br /><br /><form METHOD='GET' name='infodel' action='del_location.php'>";
        echo "<input type='hidden' name='vhc' value='$vhc'>\n";
        echo "<input type='hidden' name='Start' value='$Start'>\n";
        echo "<BUTTON TYPE='button' onClick='valide_suppresion();'>Supprimer</button><BR>\n";
        echo "</form>";
      }
      if ($ligne['Etape'] == 1) {
        if ($ligne['NoCommande'] != 0) {
          echo "<form>";
          echo "<BUTTON TYPE='button' onClick='go_facture(" . $ligne['NoCommande'] . ", " . $ligne['NoClient'] . ");'>Facture</button><BR>\n";
          echo "</form>";
        }
      }
      if ($ligne['Etape'] == 2) {
        echo "<form>";
        echo "<BUTTON TYPE='button' onClick='go_facture(" . $ligne['NoCommande'] . ", " . $ligne['NoClient'] . ");'>Facture</button><BR>\n";
        echo "</form>";
      }
    }
  }
}
  ?>
  </body>

  </html>