<?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");
require('../config/ficheatt.php');
if (Test_User($lg_user, $lg_password) == TRUE) {
  if ($ligne = Atelier::getAtelierByNoAtelier($NoAtelier)) {
    //       	      	echo "aaa";
    $pdf = new FICHEATT('P', 'mm', 'A4');
    $pdf->SetTitle("Fiche atelier");
    $pdf->SetSubject("Fiche atelier");
    $pdf->SetAuthor("Laurent");
    $pdf->SetCreator("Laurent");
    $pdf->SetDisplayMode("fullpage");
    //$pdf->Open();
    $pdf->AddPage();
    $Adresse = "";
    if ($ligne['NoClient'] != 0) {
      if ($ligne2 = Client::getClientByNoClient($ligne['NoClient'])) {
        $Adresse = $ligne2['Adresse'] . " " . $ligne2['NPA'] . " " . $ligne2['Localite'];
      }
    }
    $MarqueModelCouleur = $ligne['Vehicule'];
    $NoChasis = $ligne['NoChasis'];
    $NoPlaque = "";
    $Km = $ligne['Km'];
    if (!empty($ligne['NoChasis'])) {
      if ($ligne2 = Vehicule::getVehiculeByNoChassis(addslashes($ligne['NoChasis']))) {
        $MarqueModelCouleur = $ligne2['MarqueModel'] . " " . $ligne2['Model'] . " " . $ligne2['Couleur'];
        $NoPlaque = $ligne2['NoPlaque'];
      }
    }
    if ($ligne['Id_Service'] != 0) {
      $pdf->addService($ligne['Nom'], $ligne['Prenom'], $ligne['Telephone'], $Adresse, $MarqueModelCouleur, $NoChasis, $NoPlaque, $Km, Cree_Entree_Type("", 2, 0, $ligne['Date'], AFFICHAGE), Cree_Entree_Type("", 18, 0, $ligne['Restitution'], AFFICHAGE), $ligne['Reception'], $ligne['Description'], $ligne['Temps'], $ligne['Id_Service'], $NoAtelier);
    } else {
      $pdf->addEntete($ligne['Nom'], $ligne['Prenom'], $ligne['Telephone'], $Adresse, $MarqueModelCouleur, $NoChasis, $NoPlaque, $Km, Cree_Entree_Type("", 2, 0, $ligne['Date'], AFFICHAGE), Cree_Entree_Type("", 18, 0, $ligne['Restitution'], AFFICHAGE), $ligne['Reception'], $ligne['Description'], $ligne['Temps'], $NoAtelier);
    }
    //                $pdf->Image("CHG200x52.PNG", 60, 10);
    //                $pdf->addDate("salut");
    //                $pdf->Output();
    if ($Direct == 1) {
      $printer = "colors";
      if ($ligne = Poste::getPostesByIP()) {
        $printer = $ligne['Printer'];
      }
      $pdf->Output("../files/atelier/$NoAtelier.pdf", "F");
      $cmd = "lp -d $printer ../files/atelier/$NoAtelier.pdf";
      //                echo $cmd;
      exec($cmd);
      unlink("../files/atelier/$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();
    }
  }
}
