From 16bcd6b5e55be3b9d549044d9abee303d155edd5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 23 Oct 2013 19:19:54 +0200 Subject: [PATCH] Add error management to avoid blank page when there is no permission to read file. --- .../doc/doc_generic_order_odt.modules.php | 27 +++++++++----- .../doc/doc_generic_shipment_odt.modules.php | 29 +++++++++------ .../doc/doc_generic_invoice_odt.modules.php | 27 +++++++++----- .../pdf/doc_generic_project_odt.modules.php | 37 +++++++++++-------- .../task/pdf/doc_generic_task_odt.modules.php | 33 ++++++++++------- .../doc/doc_generic_proposal_odt.modules.php | 33 ++++++++++------- .../societe/doc/doc_generic_odt.modules.php | 30 +++++++++------ 7 files changed, 132 insertions(+), 84 deletions(-) diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php index e195e55e214..1195722e29e 100644 --- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php +++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -392,15 +392,22 @@ class doc_generic_order_odt extends ModelePDFCommandes // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->commande->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->commande->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] @@ -534,7 +541,7 @@ class doc_generic_order_odt extends ModelePDFCommandes dol_syslog($this->error, LOG_WARNING); return -1; } - + // Replace labels translated $tmparray=$outputlangs->get_translations_for_substitutions(); foreach($tmparray as $key=>$value) diff --git a/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php b/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php index 73571a65646..4b1433ddd77 100644 --- a/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php +++ b/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php @@ -127,7 +127,7 @@ class doc_generic_shipment_odt extends ModelePdfExpedition 'object_total_localtax2'=>price2num($object->total_localtax2), 'object_total_ttc'=>price2num($object->total_ttc), 'object_total_discount_ht' => price2num($object->getTotalDiscount()), - + 'object_vatrate'=>vatrate($object->tva), 'object_note_private'=>$object->note, 'object_note'=>$object->note_public, @@ -392,15 +392,22 @@ class doc_generic_shipment_odt extends ModelePdfExpedition // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->expedition->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->expedition->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] @@ -534,7 +541,7 @@ class doc_generic_shipment_odt extends ModelePdfExpedition dol_syslog($this->error, LOG_WARNING); return -1; } - + // Replace labels translated $tmparray=$outputlangs->get_translations_for_substitutions(); foreach($tmparray as $key=>$value) diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index 084dee16402..b515742a8e1 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -423,15 +423,22 @@ class doc_generic_invoice_odt extends ModelePDFFactures // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->facture->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->facture->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] @@ -514,7 +521,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures dol_syslog($this->error, LOG_WARNING); return -1; } - + // Replace labels translated $tmparray=$outputlangs->get_translations_for_substitutions(); foreach($tmparray as $key=>$value) diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php index 3e0b9c93fb4..501bfc153b0 100644 --- a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php @@ -392,7 +392,7 @@ class doc_generic_project_odt extends ModelePDFProjects } $hookmanager->initHooks(array('odtgeneration')); global $action; - + if (! is_object($outputlangs)) $outputlangs=$langs; $sav_charset_output=$outputlangs->charset_output; $outputlangs->charset_output='UTF-8'; @@ -469,15 +469,22 @@ class doc_generic_project_odt extends ModelePDFProjects // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->projet->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->projet->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] @@ -586,7 +593,7 @@ class doc_generic_project_odt extends ModelePDFProjects if (!empty($object->fk_soc)) $socid = $object->fk_soc; $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); - + foreach ($tasksarray as $task) { @@ -910,14 +917,14 @@ class doc_generic_project_odt extends ModelePDFProjects { $ref_array=array(); $ref_array['type']=$langs->trans($classname); - + $element = new $classname($this->db); $element->fetch($elementarray[$i]); $element->fetch_thirdparty(); //Ref object $ref_array['ref']=$element->ref; - + //Date object $dateref=$element->date; if (empty($dateref)) $dateref=$element->datep; @@ -976,7 +983,7 @@ class doc_generic_project_odt extends ModelePDFProjects dol_syslog($this->error, LOG_WARNING); return -1; } - + // Replace labels translated $tmparray=$outputlangs->get_translations_for_substitutions(); foreach($tmparray as $key=>$value) @@ -1010,7 +1017,7 @@ class doc_generic_project_odt extends ModelePDFProjects $this->error=$e->getMessage(); return -1; } - } + } if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); diff --git a/htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php b/htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php index 3a9c86bdb09..d9960269d3d 100644 --- a/htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php +++ b/htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php @@ -425,7 +425,7 @@ class doc_generic_task_odt extends ModelePDFTask return -1; } } - + if (file_exists($dir)) { @@ -455,15 +455,22 @@ class doc_generic_task_odt extends ModelePDFTask // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->projet->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->projet->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] @@ -677,7 +684,7 @@ class doc_generic_task_odt extends ModelePDFTask $i++; } $this->db->free($resql); - + $odfHandler->mergeSegment($listlinestasktime); } @@ -711,7 +718,7 @@ class doc_generic_task_odt extends ModelePDFTask //$listlines->merge(); $odfHandler->mergeSegment($listtasksfiles); - + } catch(OdfException $e) { @@ -793,7 +800,7 @@ class doc_generic_task_odt extends ModelePDFTask $contact['fullname']=$objectdetail->getFullName($outputlangs,1); $tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs); - + foreach($tmparray as $key => $val) { try diff --git a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php index 7843cf8e057..23f0fc020d3 100644 --- a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php +++ b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php @@ -278,9 +278,9 @@ class doc_generic_proposal_odt extends ModelePDFPropales $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); $newfiletmp=preg_replace('/template_/i','',$newfiletmp); $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); - + $newfiletmp=$objectref.'_'.$newfiletmp; - + // Get extension (ods or odt) $newfileformat=substr($newfile, strrpos($newfile, '.')+1); if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) @@ -344,15 +344,22 @@ class doc_generic_proposal_odt extends ModelePDFPropales // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->propal->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->propal->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] @@ -487,7 +494,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales dol_syslog($this->error, LOG_WARNING); return -1; } - + // Replace labels translated $tmparray=$outputlangs->get_translations_for_substitutions(); foreach($tmparray as $key=>$value) @@ -520,7 +527,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales $this->error=$e->getMessage(); return -1; } - } + } if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index 1259177432f..77d1e76eea1 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -236,16 +236,22 @@ class doc_generic_odt extends ModeleThirdPartyDoc // Open and load template require_once ODTPHP_PATH.'odf.php'; - $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' - ) - ); - + try { + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + } + catch(Exception $e) + { + $this->error=$e->getMessage(); + return -1; + } //print $odfHandler->__toString()."\n"; // Make substitutions into odt of user info @@ -318,7 +324,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc // setVars failed, probably because key not found } } - + // Replace labels translated $tmparray=$outputlangs->get_translations_for_substitutions(); foreach($tmparray as $key=>$value) @@ -351,7 +357,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc $this->error=$e->getMessage(); return -1; } - } + } if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK));