<?php
require_once ('menu/client/promo/PHPMailer/class.phpmailer.php');
require_once('menu/client/promo/PHPMailer/class.smtp.php');

function GetEmail($NoClient){
  if ($ligne = Client::getClientByNoClient($NoClient)){
    return $ligne['Email'];
  }
  return false;
}

function SendEmailSrvc($to, $valide,$date,$vehicule){
  $formatdate= explode("-", $date);
  $date2 =date("d M Y", mktime(0,0,0,$formatdate[1],$formatdate[2],$formatdate[0]));
        $mail = new PHPMailer();
        $mail->isSMTP();
        $mail->setLanguage('fr', 'phpmailer/language/');
  $mail->From = 'service@hondageneve.com';
  $mail->Subject = "Centre Honda Genève Votre rendez-vous";
    if ($valide == 1 ){
    $mail->Body = "
       
      Madame, Monsieur,

      Votre rendez-vous as été validé pour votre ".$vehicule." à la date du ".$date2."
    
      Merci de nous contacter en cas d'empêchement ou de changement.

      Soit en répondant à cet e-mail soit par téléphone au: 022 339 70 00
      ";
    } 
    else {
      $mail->Body = "
       
      Madame, Monsieur,

      Nous n'avons malheureusement pas pu confirmer votre rendez-vous à la date souhaitée.    
      
      Merci de nous contacter pour de plus amples informations.

      Soit en répondant à cet e-mail soit par téléphone au: 022 339 70 00
      ";
    }
    $mail->addAddress($to); 
    if(!$mail->send()) {
    echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
  }

function atelier_bloc_client_vehicule($ligne)
{
  $no_plaque = "";
  if ($_GET["new"]==1)
  {
  	$no_client = "";
  	$nom = "";
  	$prenom = "";
  	$telephone = "";
  	$no_chasis = "";
  	$vehicule = "";
  	$km = "";
  }
  else 
  {
  	$no_client = $ligne['NoClient'];
  	$nom = $ligne['Nom'];
  	$prenom = $ligne['Prenom'];
  	$telephone = $ligne['Telephone'];
  	$no_chasis = $ligne['NoChasis'];
  	$vehicule = $ligne['Vehicule'];
  	$km = $ligne['Km'];
	if ($no_chasis != "")
	{
	  $requette = "SELECT NoPlaque FROM vehicules WHERE NoChasis = :nochasis";
    $statement = Connection::getStatement($requette);
    $statement->bindParam(":nochasis", $no_chasis);
    $statement->execute();
    if ($ligne = $statement->fetch())
    {
		  $no_plaque = $ligne["NoPlaque"];
	  }		  
	}
  }
	
  echo "<TR><TH>No Client</TH><TD colspan='3'><Input type='text' name='NoClient' value='".$no_client."' readonly><BUTTON type='button' onClick='recherche_client_ajax(2);'>Recherche</BUTTON></TD></TR>\n";
  echo "<TR><TH>Nom</TH><TD><Input type='text' name='Nom' value='".htmlentities($nom,ENT_QUOTES,'UTF-8')."'></TD>\n";
  echo "<script language=JavaScript>\n";
  echo "this.document.forms['info'].elements['Nom'].focus();\n";
  echo "</script>\n";
  echo "<TH>Prenom</TH><TD><Input type='text' name='Prenom' value='".htmlentities($prenom,ENT_QUOTES,'UTF-8')."' onchange='recherche_client_ajax(2);'></TD></TR>\n";
  $clicktocall = "";
  if($ligne2=Poste::getPostesByIP())
  {
  	  $interne=$ligne2['NoInterne'];
      if ($interne != 0)
	  {
		$clicktocall .= " <a href=\"javascript:appel_avec_formatage('Telephone', $interne);\"><img src=\"images/phone.gif\"/></a>";
	  }
	}
  echo "<TR><TH>Telephone</TH><TD colspan='3'><Input type='text' name='Telephone' value='".$telephone."'>$clicktocall</TD></TR>\n";
  //echo "<TR><TH>No Chasis</TH><TD colspan='3'><Input type='text' id='NoChasis' name='NoChasis' value='".$no_chasis."' readonly><BUTTON type='button' onClick='recherche_vhc_ajax(0,1);'>Recherche</BUTTON><BUTTON type='button' onClick='efface_vhc();'>Effacer</BUTTON></TD></TR>\n";
  echo "<TR><TH>No Chasis</TH><TD><Input type='text' id='NoChasis' name='NoChasis' value='".$no_chasis."' readonly><BUTTON type='button' onClick='recherche_vhc_ajax(0,1);'>Recherche</BUTTON><BUTTON type='button' onClick='efface_vhc();'>Effacer</BUTTON></TD><TH>No plaques</TH><TD class='noplaque'>$no_plaque</TD></TR>\n";
  echo "<TR><TH>Vehicule</TH><TD><Input type='text' name='Vehicule' value='".$vehicule."'></TD>\n";
  echo "<TH>Km</TH><TD><Input type='text' name='Km' value='".$km."'></TD></TR>\n";
}
function atelier_bloc_service($ligne)
{
  if ($_GET["new"]==1)
  {
  	$Id_Vhc = 0;
  }
  else
  {
  	$Id_Vhc = $ligne["Id_Vhc"];
  }
  
  echo "<TR><TH>Service</TH><TD colspan='3'><select name='service' onchange='duree_service()'><option value='0'>-</option>";
  if ($Id_Vhc!=0)
  {
    $requette0 = "SELECT * FROM chassis_model WHERE Id = :idvhc";
    $statement = Connection::getStatement($requette0);
    $statement->bindParam(":idvhc", $Id_Vhc);
    $statement->execute();
    $ligne0 = $statement->fetch();
  	$requette2 = "SELECT * FROM service_vhc WHERE Id_vhc = :idvhc ORDER BY Km";
  	$statement = Connection::getStatement($requette2);
    $statement->bindParam(":idvhc", $Id_Vhc);
    $statement->execute();
  	while ($ligne2 = $statement->fetch())
  	{
      echo "<option value='".$ligne2['Id']."'";
      if ($ligne2['Id']==$ligne['Id_Service'])
      {
        echo " selected='1'";
      }
	  switch ($ligne0['Type_Service'])
	  {
	    case "Texte":
          echo ">".$ligne2['Nom']."</option>";
		break;
		default:
          echo ">Service ".$ligne2['Km']."</option>";
		break;
	  }
      echo "<script language=javascript>document.tab_duree[".$ligne2["Id"]."] = ".$ligne2["Duree"].";</script>";
  	}
  }
  echo "</select>\n<div id=\"serviceoptions\">\n";
  if ($Id_Vhc!=0)
  {
	  $requette2 = "SELECT service_option.Nom_court, vhc_option.Id, vhc_option.Duree  FROM vhc_option, service_option WHERE vhc_option.Id_vhc = :idvhc AND vhc_option.Id_option = service_option.Id";
    $statement = Connection::getStatement($requette2);
    $statement->bindParam(":idvhc", $Id_Vhc);
    $statement->execute();
  	while ($ligne2 = $statement->fetch())
  	{
      echo "<input type=\"checkbox\" name=\"option_".$ligne2["Id"]."\" duree=\"".$ligne2["Duree"]."\" onchange=\"duree_service()\"";
      $requette3 = "SELECT * FROM atelier_option".ID_GARAGE." WHERE Id_atelier = :idatelier AND Id_option = :idoption";
      $statement = Connection::getStatement($requette3);
      $statement->bindParam(":idatelier", $ligne["NoAtelier"]);
      $statement->bindParam(":idoption", $ligne2["Id"]);
      $statement->execute();
      if ($statement->fetch())
      {
        echo " checked=\"checked\"";
      }
      echo ">".$ligne2["Nom_court"]."<br />\n";
	  }	
  }
  echo "</div>\n";
  echo "<button type='button' onClick='dialog_historique();'>Historique</button></TD></TR>\n";
  	  
}
function atelier_bloc_date_heure_mecano($ligne)
{
  if ($_GET["new"]==1)
  {
  	$annee = $_GET["annee"];
  	$mois = $_GET["mois"];
  	$jour = $_GET["jour"];
	$date = "$annee-$mois-$jour";
  	//$heure = "08";
  	//$minutes = "00";
  	$duree = "";
  	$mecano = $_GET["mecano"];
  }
  else 
  {
  	$annee = substr($ligne['Date'],0,4);
  	$mois = substr($ligne['Date'],5,2);
  	$jour = substr($ligne['Date'],8,2);
	$date = $ligne['Date'];
  	//$heure = substr($ligne['Heure'],0,2);
  	//$minutes = substr($ligne['Heure'],3,2);
  	$duree = $ligne['Temps'];
  	$mecano = $ligne['Mecano'];
  }
  
  echo "<TR><TH>Date</TH><TD colspan='3'>".Cree_Entree_Type("Date",2,0,$date,MODIFICATION)."</TD></TR>\n";
  //echo "<TR><TH>Date</TH><TD colspan='3'>".Input_Date("Date",$annee,$mois,$jour)."</TD></TR>\n";
  //echo "<TR><TH>Heure</TH><TD colspan='3'>".Input_Heure_15("HD",$heure,$minutes)."</TD></TR>\n";
  echo "<TR><TH>Durée prévu</TH><TD><Input type='text' name='Temps' value='".$duree."'></TD>\n";
  echo "<TH>Mecano</TH><TD colspan='3'><select name='Mecano'><option value='0'>-</option>";
  $requette2="SELECT employes".ID_GARAGE.".NoClient, clients.Prenom FROM employes".ID_GARAGE.", clients WHERE (employes".ID_GARAGE.".Actif = 1 OR employes".ID_GARAGE.".NoClient = :mecano) AND employes".ID_GARAGE.".HeureAtelier > 0 AND employes".ID_GARAGE.".NoClient = clients.NoClient ORDER BY clients.Prenom";
  $statement = Connection::getStatement($requette2);
  $statement->bindParam(":mecano", $mecano);
  $statement->execute();
  while($ligne2=$statement->fetch())
  {
    echo "<option value='".$ligne2["NoClient"]."'";
    if ($ligne2["NoClient"]==$mecano)
    {
      echo " selected";
    }
    echo ">".$ligne2["Prenom"]."</option>";
  }
  echo "</select></TD></TR>\n";
  $requette3="SELECT * FROM atelier_suite".ID_GARAGE." WHERE NoAtelier = :noatelier";
  $statement = Connection::getStatement($requette3);
  $statement->bindParam(":noatelier", $ligne["NoAtelier"]);
  $statement->execute();
  $resultat3=$statement->fetchAll();
  $nbresultat3=count($resultat3);
  echo "<TR><TD>Autres dates</TD><TD colspan='3'><input type='hidden' name='NbDatesAutre' id='NbDatesAutre' value='$nbresultat3'><TABLE id='TableDatesAutre'><TR><TH>&nbsp;</TH><TH>Date</TH><TH>Durée</TH><TH>Mécano</TH></TR>\n";
  $cpt = 1;
  foreach ($resultat3 as $ligne3)
  {
    echo "<TR id=\"trDateAutre$cpt\"><TD><a href=\"javascript:supprimer_date_autre($cpt);\"><img style=\"background-color:white;\" src=\"images/b_drop.png\" border=\"0\"></a></TD><TD><input type='hidden' name='NoSuite$cpt' value='".$ligne3["NoSuite"]."'>".Cree_Entree_Type("Date$cpt",2,0,$ligne3["Date"],MODIFICATION)."</TD><TD><Input type='text' name='Temps$cpt' value='".$ligne3["Temps"]."'></TD><TD><select name='Mecano$cpt'><option value='0'>-</option>";
    $statement = Connection::getStatement($requette2);
    $statement->bindParam(":mecano", $mecano);
    $statement->execute();
    while($ligne2=$statement->fetch())
    {
      echo "<option value='".$ligne2["NoClient"]."'";
      if ($ligne2["NoClient"]==$ligne3["Mecano"])
      {
        echo " selected";
      }
      echo ">".$ligne2["Prenom"]."</option>";
    }
	echo "</select></TD></TR>\n";
	$cpt++;
  }
  echo "</TABLE><button type='button' onclick='ajouter_date_autre();'>Ajouter date</button></TD></TR>\n";
}
function atelier_bloc_description($ligne)
{
  if ($_GET["new"]==1)
  {
  	$description = "";
  	$reception = "";
  }
  else
  {
  	$description = $ligne["Description"];
  	$reception = $ligne['Reception'];  	
  }
  
  echo "<TR><TH>Description</TH><TD colspan='3'><TextArea name='Description' Rows=4 Cols=80>".htmlentities($description,ENT_COMPAT | ENT_HTML401,'UTF-8')."</TextArea></TD></TR>\n";
  echo "<TR><TH>Réceptionaire</TH><TD colspan='3'><Input type='text' name='Reception' value='".$reception."'></TD></TR>\n";
}
function atelier_bloc_retour_vhc_pret($ligne)
{
  if ($_GET["new"]==1)
  {
  	$annee = $_GET["annee"];
  	$mois = $_GET["mois"];
  	$jour = $_GET["jour"];
  	//$heure = "17";
  	//$minutes = "00";
  }
  else
  {
  	$annee = substr($ligne['Restitution'],0,4);
  	$mois = substr($ligne['Restitution'],5,2);
  	$jour = substr($ligne['Restitution'],8,2);
  	//$heure = substr($ligne['Restitution'],11,2);
  	//$minutes = substr($ligne['Restitution'],14,2);  	
  }
  
  //echo "<TR><TH>Retour client</TH><TD colspan='3'>".Input_Date_Heure("HF",$annee,$mois,$jour,$heure,$minutes)."</TD></TR>\n";
  echo "<TR><TH>Vehicule de prêt</TH><TD colspan='3'><select name='vhc_pret'><option value=''>-</option>";
  $resultat = CatLoc::getCatlocByPret();
  foreach($resultat as $ligne)
  {
    $resultats2 = VehiculesLocation::getVehiculeLocationByCatLoc($ligne['NoCatLoc']);
    foreach($resultats2 as $ligne2)
    {
      $requette3="SELECT COUNT(*) FROM location".ID_GARAGE." WHERE NoChasis='".addslashes($ligne2['NoChasis'])."' AND((Debut>='$annee-$mois-$jour 00:00:00' AND Debut<='$annee-$mois-$jour 23:59:59') OR (Fin>='$annee-$mois-$jour 00:00:00' AND Fin<='$annee-$mois-$jour 23:59:59') OR (Debut<'$annee-$mois-$jour 00:00:00' AND Fin>'$annee-$mois-$jour 23:59:59'))";
      $statement3 = Connection::getStatement($requette3);
      $statement3->execute();
      if($ligne3=$statement3->fetch())
      {
        $is_pret=($ligne3[0]!=0);
      }
      if(!$is_pret)
      {
        $requette3="SELECT Debut FROM location".ID_GARAGE." WHERE NoChasis='".addslashes($ligne2['NoChasis'])."' AND Debut>'$annee-$mois-$jour 23:59:59' ORDER BY Debut LIMIT 0, 1";
        $statement3 = Connection::getStatement($requette3);
        $statement3->execute();
        if($ligne3=$statement3->fetch())
        {
          $prem=mktime(0,0,0,substr($ligne3[0],5,2),substr($ligne3[0],8,2),substr($ligne3[0],0,4));
          $actu=mktime(0,0,0,$mois,$jour,$annee);
          $j=(($prem-$actu)/(60*60*24))." jours";
        }
        else
        {
          $j="";
        }
        $ligne3=Vehicule::getVehiculeByNoChassis(addslashes($ligne2['NoChasis']));;
        echo "<option value='".$ligne2['NoChasis']."'>".$ligne3['Model']." ".$ligne3['NoPlaque']." ".$j."</option>";
      }
    }
  }
  echo "</select></TD></TR>\n";
}
function atelier_bloc_acompte($ligne)
{
  echo "<TR><TH>Acompte</TH><TD colspan='3'><Input type='text' name='Acompte' value='0'>";
  if(As_Right_Groupe(6))
  {
    $resultat2 = ModePayement::getVisibleModePayment();
  }
  else
  {
    $no_caisse=1;

    if($ligne1=Poste::getPostesByIP())
    {
      $no_caisse=$ligne1['NoCaisse'];
    }
    $resultat2 = ModePayement::getModePayementsByNoCaisse($no_caisse);
  }
  echo " <SELECT name='ModePayement' size='1'>\n";
    foreach ($resultat2 as $ligne2)
    {
      if(($ligne2['Type']==2) && (!Is_Banque()))
      {
      }
      else
      {
        if(As_Right_Groupe(6))
        {
          echo "  <option value='" . $ligne2['NoMode'] . " " . $ligne2['NoCaisse'] . "'>" . $ligne2['Description'] . " caisse " . $ligne2['NoCaisse'] . "</option>\n";
        }
        else
        {
          echo "  <option value='" . $ligne2['NoMode'] . " " . $ligne2['NoCaisse'] . "'>" . $ligne2['Description'] . "</option>\n";
        }
      }
    }
  echo " </SELECT>\n";
  echo "</TD></TR>\n";
}
function atelier_bouton_web($ligne)
{
  echo "<button type='button' onClick='valider_web();'>Accepter</button>\n";
  echo "<button type='button' onClick='refuser_web();'>Refuser</button>\n";
}
function atelier_bouton_valider($ligne)
{
  echo "<button type='button' onClick='valider_atelier();'>Valider</button>\n";
}
function atelier_bouton_fiche_atelier($ligne)
{
  echo "<button type='button' onClick='imprimer_atelier();' style='width:100px'>Fiche atelier</button>\n";
}
function atelier_bouton_entete($ligne)
{
  echo "<button type='button' onClick='imprimer_entete();' style='width:100px'>Entête</button>\n";
  echo "<button type='button' onClick='imprimer_entete2();' style='width:100px'>Entête simple</button>\n";
}
function atelier_bouton_fiche_atelier_reception($ligne)
{
  echo "<button type='button' onClick='reception_imprimer_atelier();' style='width:150px'>Fiche atelier + reception</button>\n";
}
function atelier_bouton_reception_vhc($ligne)
{
  echo "<button type='button' onClick='reception_atelier();' style='width:150px'>Récéption véhicule</button>\n";
}
function atelier_bouton_travaux_termines($ligne)
{
  echo "<button type='button' onClick='facture(1);'>Travaux terminés</button>\n";
}
function atelier_bouton_facture($ligne)
{
  echo "<button type='button' onClick='facture(1);'>Facture</button>\n";
}
function atelier_bouton_gf($ligne)
{
  echo "<button type='button' onClick='facture(2);'>Garantie fourniseur</button>\n";
}
function atelier_bouton_gg($ligne)
{
  echo "<button type='button' onClick='facture(3);'>Garantie garage</button>\n";
}
function atelier_bouton_devis($ligne)
{
  echo "<button type='button' onClick='facture(4);'>Devis</button>\n";
}
function atelier_bouton_facture_interne($ligne)
{
  echo "<button type='button' onClick='facture(5);'>Facture interne</button>\n";
}
function atelier_bouton_sans_facture($ligne)
{
  echo "<button type='button' onClick='facture(0);'>Sans facture</button>\n";
}
function atelier_bouton_facture_existante($ligne)
{
  echo "<button type='button' onClick='facture(6);'>Facture existante</button><input type='text' name='NoCommande2'>\n";
}
function atelier_bouton($ligne)
{
	
}
function print_fiche_atelier($NoAtelier)
{
  // double definition
  //define('FPDF_FONTPATH','font/');
  require('../config/ficheatt.php');
  $requette="SELECT * FROM atelier".ID_GARAGE." WHERE NoAtelier=:noatelier";
  $statement = Connection::getStatement($requette);
  $statement->bindParam(":noatelier", $NoAtelier);
  $statement->execute();
    if($ligne=$statement->fetch())
    {
      $pdf = new FICHEATT( 'P', 'mm', 'A4' );
      $pdf->SetTitle("Fiche atelier");
      $pdf->SetSubject("Fiche atelier");
      $pdf->SetAuthor("Laurent");
      $pdf->SetCreator("Laurent");
      $pdf->SetDisplayMode("fullpage");
      $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']))
      {
        $requette2="SELECT * FROM vehicules WHERE NoChasis='".addslashes($ligne['NoChasis'])."'";
        $statement = Connection::getStatement($requette2);
        $statement->execute();
       	if($ligne2=$statement->fetch())
        {
            $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);
      }
                
      $printer="colors";
      if($resultat=Poste::getPostesByIP())
      {
  	      $printer=$ligne['Printer'];
      }
      $pdf->Output("../files/atelier/$NoAtelier.pdf","F");
      $cmd="lp -d $printer ../files/atelier/$NoAtelier.pdf";
      exec($cmd);
	  unlink("../files/atelier/$NoAtelier.pdf");
    }
}
function print_entete($NoAtelier)
{
  // already defined
  //define('FPDF_FONTPATH','font/');
  require('entete.php');
  $requette="SELECT * FROM atelier".ID_GARAGE." WHERE NoAtelier=:noatelier";
  $statement = Connection::getStatement($requette);
  $statement->bindParam(":noatelier", $NoAtelier);
  $statement->execute();
  if($ligne=$statement->fetch())
  {
        $pdf = new ENTETE( 'P', 'mm', 'A4' );
        $pdf->SetTitle("Entete atelier");
        $pdf->SetSubject("Entete atelier");
        $pdf->SetAuthor("Laurent");
        $pdf->SetCreator("Laurent");
        $pdf->SetDisplayMode("fullpage");
        $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)
        {
          $requette2="SELECT * FROM clients WHERE NoClient=:noclient";
          $statement = Connection::getStatement($requette2);
          $statement->bindParam(":noclient", $ligne['NoClient']);
          $statement->execute();
            if($ligne2=$statement->fetch())
            {
              $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']))
        {
          $requette2="SELECT * FROM vehicules WHERE NoChasis='".addslashes($ligne['NoChasis'])."'";
          $statement = Connection::getStatement($requette2);
          $statement->execute();
            if($ligne2=$statement->fetch())
            {
              $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);
                
      $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");
    }
}
function print_entete2($NoAtelier)
{
  require('entete.php');
  $requette="SELECT * FROM atelier".ID_GARAGE." WHERE NoAtelier=:noatelier";
  $statement = Connection::getStatement($requette);
  $statement->bindParam(":noatelier", $NoAtelier);
  $statement->execute();
    if($ligne=$statement->fetch())
    {
        $pdf = new ENTETE( 'P', 'mm', 'A4' );
        $pdf->SetTitle("Entete atelier");
        $pdf->SetSubject("Entete atelier");
        $pdf->SetAuthor("Laurent");
        $pdf->SetCreator("Laurent");
        $pdf->SetDisplayMode("fullpage");
        $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)
        {
          $requette2="SELECT * FROM clients WHERE NoClient=:noclient";
          $statement = Connection::getStatement($requette2);
          $statement->bindParam(":noclient", $ligne['NoClient']);
          $statement->execute();
            if($ligne2=$statement->fetch())
            {
              $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']))
        {
          $requette2="SELECT * FROM vehicules WHERE NoChasis='".addslashes($ligne['NoChasis'])."'";
          $statement = Connection::getStatement($requette2);
          $statement->execute();
          if($ligne2=$statement->fetch())
          {
              $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->addEntete2($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);
                
      $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");
    }
}
?>