<?php

require 'database.inc.php';
require('entete.php');
if (Test_User($lg_user, $lg_password) == TRUE) {
  if ($ligne = Atelier::getAtelierByNoAtelier($NoAtelier)) {
    $pdf = new ENTETE('P', 'mm', 'A4');
    $pdf->SetTitle("Entete atelier");
    $pdf->SetSubject("Entete atelier");
    $pdf->SetAuthor("Laurent");
    $pdf->SetCreator("Laurent");
    $pdf->SetDisplayMode("fullpage");
    // $pdf->Open();
    $pdf->AddPage();
    $Allocution = "";
    $Nom = $ligne["Nom"];
    $Prenom = $ligne["Prenom"];
    $Adresse = "";
    $NoPostal = "";
    $Localite = "";
    $Natel = "";
    $TelephonePrive = "";
    $TelephonePro = "";
    $Email = "";
    $DateNaissance = "";
    $Marque = "";
    $Famille = "";
    $Model = "";
    $NoPlaque = "";
    $NoChassis = "";
    $NoMoteur = "";
    $DateMiseEnCirculation = "";
    $DateExpertise = "";
    $Couleur = "";
    $DateGarantie = "";
    $TypeGarantie = "";
    $Puissance = "";
    $Description = $ligne["Description"];
    if ($ligne['NoClient'] != 0) {
      if ($ligne2 = Client::getClientByNoClient($ligne['NoClient'])) {
        $Allocution = $ligne2["Allocution"];
        $Nom = $ligne2["Nom"];
        $Prenom = $ligne2["Prenom"];
        $Adresse = $ligne2["Adresse"];
        $NoPostal = $ligne2["NPA"];
        $Localite = $ligne2["Localite"];
        $Natel = $ligne2["Natel"];
        $TelephonePrive = $ligne2["TelPriv"];
        $TelephonePro = $ligne2["TelProf"];
        $Email = $ligne2["Email"];
        $DateNaissance = Cree_Entree_Type("vide", 2, 0, $ligne2['DateNaissance'], AFFICHAGE);
      }
    }
    if (!empty($ligne['NoChasis'])) {
      if ($ligne2 = Vehicule::getVehiculeByNoChassis(addslashes($ligne['NoChasis']))) {
        $Marque = $ligne2["MarqueModel"];
        $Famille = $ligne2["Famille"];
        $Model = $ligne2["Model"];
        $NoPlaque = $ligne2["NoPlaque"];
        $NoChassis = $ligne2["NoChasis"];
        $NoMoteur = $ligne2["NoMoteur"];
        $DateMiseEnCirculation = Cree_Entree_Type("vide", 2, 0, $ligne2['DateCircul'], AFFICHAGE);
        $DateExpertise = Cree_Entree_Type("vide", 2, 0, $ligne2['DateExpert'], AFFICHAGE);
        $Couleur = $ligne2["Couleur"];
        $DateGarantie = Cree_Entree_Type("vide", 2, 0, $ligne2['DateGarantie'], AFFICHAGE);
        $TypeGarantie = $ligne2["TypeGarantie"];
        $Puissance = $ligne2["CV"];
      }
    }
    $pdf->addEntete($NoAtelier, $Allocution, $Nom, $Prenom, $Adresse, $NoPostal, $Localite, $Natel, $TelephonePrive, $TelephonePro, $Email, $DateNaissance, $Marque, $Famille, $Model, $NoPlaque, $NoChassis, $NoMoteur, $DateMiseEnCirculation, $DateExpertise, $Couleur, $DateGarantie, $TypeGarantie, $Puissance, $Description);

    if ($Direct == 1) {
      $printer = "colors";
      if ($ligne = Poste::getPostesByIP()) {
        $printer = $ligne['Printer'];
      }
      $pdf->Output("../files/atelier/e$NoAtelier.pdf", "F");
      $cmd = "lp -d $printer ../files/atelier/e$NoAtelier.pdf";
      exec($cmd);
      unlink("../files/atelier/e$NoAtelier.pdf");
      echo "<script language=JavaScript>\n";
      echo "window.close();\n";
      echo "</script>\n";
    } else {
      header('Content-type: application/pdf');
      header('Content-Disposition: inline; filename="' . $NoCommande . '.pdf"');
      $pdf->Output();
    }
  }
}
