From 7e5eb538e2f7c6c3bbe8b6a074466c5ad6a67775 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 13 Jul 2014 12:02:21 +0200 Subject: [PATCH] =?UTF-8?q?task=20#1006=20export=20des=20pi=C3=A8ces=20en?= =?UTF-8?q?=20PDF,=20v=C3=A9rification=20et=20ajout=20message=20d'erreur?= =?UTF-8?q?=20Task=20#1006=20-=20ANCGL=20:=20export=20des=20pi=C3=A8ces=20?= =?UTF-8?q?dans=20un=20grand=20PDF=20avec=20un=20tampon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class_anc_grandlivre.php | 30 ++++++++----- include/class_document_export.php | 71 ++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/include/class_anc_grandlivre.php b/include/class_anc_grandlivre.php index 2a3d920b4..d7a59e113 100644 --- a/include/class_anc_grandlivre.php +++ b/include/class_anc_grandlivre.php @@ -124,17 +124,27 @@ class Anc_GrandLivre extends Anc_Print function button_export_pdf($p_string = "") { - $r = ""; - $r.= HtmlInput::hidden("to", $this->to); - $r.= HtmlInput::hidden("from", $this->from); - $r.= HtmlInput::hidden("pa_id", $this->pa_id); - $r.= HtmlInput::hidden("from_poste", $this->from_poste); - $r.= HtmlInput::hidden("to_poste", $this->to_poste); - $r.= HtmlInput::hidden("act","PDF:AncReceipt"); + if (CONVERT_GIF_PDF <> 'NOT' && PDFTK <> 'NOT') + { + $r = ""; + $r.= HtmlInput::hidden("to", $this->to); + $r.= HtmlInput::hidden("from", $this->from); + $r.= HtmlInput::hidden("pa_id", $this->pa_id); + $r.= HtmlInput::hidden("from_poste", $this->from_poste); + $r.= HtmlInput::hidden("to_poste", $this->to_poste); + $r.= HtmlInput::hidden("act","PDF:AncReceipt"); - $r.= $p_string; - $r.= dossier::hidden(); - $r.=HtmlInput::submit('bt_receipt_anal_pdf', _("Export des pièces en PDF")); + $r.= $p_string; + $r.= dossier::hidden(); + $r.=HtmlInput::submit('bt_receipt_anal_pdf', _("Export des pièces en PDF")); + } + else + { + + $r = ""; + $msg = _("Les extensions pour convertir en pdf ne sont pas installées"); + $r = HtmlInput::button("bt_receipt_anal", _('Export des pièces en PDF'), sprintf('onclick="alert(\'%s\')"',$msg)); + } return $r; } /*! diff --git a/include/class_document_export.php b/include/class_document_export.php index b3bc1ee85..b7e4efe08 100644 --- a/include/class_document_export.php +++ b/include/class_document_export.php @@ -1,19 +1,37 @@ store_convert); mkdir($this->store_pdf); } - + /** + * @brief concatenate all PDF into a single one and save it into the + * store_pdf folder + */ function concatenate_pdf() { + $this->check_file(); $stmt = PDFTK . " " . $this->store_pdf . '/stamp_*pdf output ' . $this->store_pdf . '/result.pdf'; $status = 0; echo $stmt; @@ -43,12 +65,15 @@ class Document_Export $this->feedback[$cnt_feedback]['error'] = $status; } } - + function move_file($p_source, $target) { + $this->check_file(); copy($p_source, $this->store_pdf . '/' . $target); } - + /** + * @brief send the resulting PDF to the browser + */ function send_pdf() { header('Content-Type: application/x-download'); @@ -64,11 +89,13 @@ class Document_Export } /** - * @brief export all the pieces in PDF + * @brief export all the pieces in PDF and transform them into a PDF with + * a stamp * @param $p_array contents all the jr_id */ function export_all($p_array) { + $this->check_file(); ob_start(); var_dump($p_array); global $cn; @@ -139,7 +166,7 @@ class Document_Export { $this->feedback[$cnt_feedback]['file'] = $file_pdf; - $this->feedback[$cnt_feedback]['message'] = ' cannot convert to stamped PDF'; + $this->feedback[$cnt_feedback]['message'] = _(' ne peut pas convertir en PDF'); $this->feedback[$cnt_feedback]['error'] = $status; $cnt_feedback++; continue; @@ -156,5 +183,19 @@ class Document_Export var_dump($this->feedback); // concatenate all pdf into one } - + /** + * @brief check that the files are installed + * throw a exception if one is missing + */ + function check_file() + { + try + { + if (CONVERT_GIF_PDF == 'NO') throw new Exception(_("CONVERT_GIF_PDF n'est pas installé")); + if (PDFTK == 'NO') throw new Exception(_("TKPDF n'est pas installé")); + } catch (Exception $ex) + { + throw ($ex); + } + } }