<?php

require 'database.inc.php';
require('entete_client.php');
if (Test_User($lg_user, $lg_password) == TRUE) {
	if ($ligne = Client::getClientByNoClient($NoClient)) {
		$pdf = new ENTETE_CLIENT('P', 'mm', 'A4');
		$pdf->SetTitle("Entete client");
		$pdf->SetSubject("Entete client");
		$pdf->SetAuthor("Laurent");
		$pdf->SetCreator("Laurent");
		$pdf->SetDisplayMode("fullpage");
		//$pdf->Open();
		$pdf->AddPage();
		$Nom = $ligne["Nom"];
		$Prenom = $ligne["Prenom"];
		$DateNaissance = Cree_Entree_Type("vide", 2, 0, $ligne['DateNaissance'], AFFICHAGE);
		$Adresse = $ligne["Adresse"];
		$NoPostal = $ligne["NPA"];
		$Localite = $ligne["Localite"];
		$Pays = $ligne["Pays"];
		$Telephone = "";
		if (trim($ligne['Natel']) != "") {
			$Telephone = Cree_Entree_Type("vide", 7, 0, $ligne['Natel'], AFFICHAGE);
		} else if (trim($ligne['TelPriv']) != "") {
			$Telephone = Cree_Entree_Type("vide", 7, 0, $ligne['TelPriv'], AFFICHAGE);
		} else if (trim($ligne['TelProf']) != "") {
			$Telephone = Cree_Entree_Type("vide", 7, 0, $ligne['TelProf'], AFFICHAGE);
		} else if (trim($ligne['TelAutre']) != "") {
			$Telephone = Cree_Entree_Type("vide", 7, 0, $ligne['TelAutre'], AFFICHAGE);
		}
		$Email = $ligne["Email"];
		$pdf->addEntete($Nom, $Prenom, $DateNaissance, $Adresse, $NoPostal, $Localite, $Pays, $Telephone, $Email);

		if (true) {
			$printer = "colors";
			if ($ligne = Poste::getPostesByIP()) {
				$printer = $ligne['Printer'];
			}
			$pdf->Output("../files/atelier/c$NoAtelier.pdf", "F");
			$cmd = "lp -d $printer ../files/atelier/c$NoAtelier.pdf";
			exec($cmd);
			unlink("../files/atelier/c$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();
		}
	}
}
