From 884493c1fb985adaaa537c11f4350d940cc68cb1 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 4 Jul 2023 15:52:55 +0200 Subject: =?UTF-8?q?fonctions=20fichiers=20s=C3=A9par=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions.php | 63 +++++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 42 deletions(-) (limited to 'src/functions.php') diff --git a/src/functions.php b/src/functions.php index 0b075b5..1bbb40c 100644 --- a/src/functions.php +++ b/src/functions.php @@ -100,7 +100,9 @@ function rechercheClient(string $input, Clients $Client): array return($result); } -function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) + +// remplacer par une classe Latex +function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) { $latex = ''; $year = ''; @@ -111,7 +113,10 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n // verso d'une enveloppe $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config $file_name = 'enveloppe_verso.tex'; - makeFiles($latex_path, $pdf_path, $file_name, $latex); + makeFile($latex_path, $file_name, $latex); + + latexToPdf($latex_path, $file_name, $pdf_path); + if($Client !== null) { @@ -119,11 +124,16 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n // recto d'une enveloppe $latex_recto_path = $latex_path . 'enveloppes_recto/'; - $pdf_verso_path = $pdf_path . 'enveloppes_recto/'; - $data['code_postal'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 + $pdf_recto_path = $pdf_path . 'enveloppes_recto/'; + $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 + $latex = makeLatex('enveloppe_recto', $data); // injection des variables $file_name = $Client->getCodeClient() . '.tex'; - makeFiles($latex_recto_path, $pdf_verso_path, $file_name, $latex); + makeFolder($latex_recto_path); + makeFile($latex_recto_path, $file_name, $latex); + + makeFolder($pdf_recto_path); + latexToPdf($latex_recto_path, $file_name, $pdf_recto_path); // facture, devis, location if($Presta !== null && $PrestaDetails !== null) @@ -138,9 +148,14 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année $pdf_year_path = $pdf_path . $year . '/'; $data = array_merge($data, $PrestaDetails->getAll()); + $latex = makeLatex($type, $data, $Date); // injection des variables $file_name = $Presta->getCodePresta() . '.tex'; - makeFiles($latex_year_path, $pdf_year_path, $file_name, $latex); + makeFolder($latex_year_path); + makeFile($latex_year_path, $file_name, $latex); + + makeFolder($pdf_year_path); + latexToPdf($latex_year_path, $file_name, $pdf_year_path); } elseif($type === 'cesu' || $type === 'non_vendue') {} // pas de document @@ -153,7 +168,6 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n } } - function makeLatex(string $type, array $data = [], Dates $Date = null) { $date = ''; @@ -172,38 +186,3 @@ function makeLatex(string $type, array $data = [], Dates $Date = null) // normallement le code PHP inséré avec include est nettoyé en quittant la fonction return($latex); } - -function makeFiles($latex_path, $pdf_path, $file_name, $latex) -{ - makeFolder($latex_path); - makeFolder($pdf_path); - file_put_contents($latex_path. $file_name, $latex); // écriture du fichier - latexToPdf($latex_path, $file_name, $pdf_path); -} - -function makeFolder(string $path) -{ - if(!file_exists($path)) - { - mkdir($path); - chmod($path, 0755); // droits en octal - } -} - -// compilation à partir d'un fichier .tex -function latexToPdf(string $latexPath, string $fileName, string $pdfPath) -{ - $outputDir = ''; - if($pdfPath !== '') - { - $outputDir = '-output-directory=' . $pdfPath . ' '; - } - - // compilation - exec('pdflatex ' . $outputDir . $latexPath . $fileName); - - // nettoyage - $basename = basename($fileName, '.tex'); - unlink($pdfPath . $basename . '.aux'); - unlink($pdfPath . $basename . '.log'); -} -- cgit v1.2.3