From e6f9c567d98ca05ff3ebeba1f05d4a47e83ba7e3 Mon Sep 17 00:00:00 2001 From: fhenry Date: Mon, 22 Apr 2013 12:08:35 +0200 Subject: [PATCH 1/5] Fix odt as PDF generation --- htdocs/includes/odtphp/odf.php | 9 ++++---- htdocs/includes/odtphp/odt2pdf.sh | 34 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 4f91157438b..03136a20b63 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -459,7 +459,8 @@ IMG; $name=str_replace('.odt', '', $name); $command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name; - //dol_syslog('$execmethod='.$execmethod.' Run command='.$command); + + dol_syslog(get_class($this).'::exportAsAttachedPDF $execmethod='.$execmethod.' Run command='.$command,LOG_DEBUG); if ($execmethod == 1) { exec($command, $output_arr, $retval); @@ -486,16 +487,16 @@ IMG; if($retval == 0) { - //dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); + dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); if (headers_sent($filename, $linenum)) { throw new OdfException("headers already sent ($filename at $linenum)"); } - if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + /*if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.$name.'.pdf"'); readfile("$name.pdf"); - } + }*/ unlink("$name.odt"); } else { //dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); diff --git a/htdocs/includes/odtphp/odt2pdf.sh b/htdocs/includes/odtphp/odt2pdf.sh index b9710682465..28f9ef32b22 100755 --- a/htdocs/includes/odtphp/odt2pdf.sh +++ b/htdocs/includes/odtphp/odt2pdf.sh @@ -2,21 +2,21 @@ # @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com if [ -f "$1.odt" ] -then -pgrep -U `id -u` soffice -if [ $? -ne 0 ] -then -soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard -sleep 2 -fi -jodconverter "$1.odt" "$1.pdf" -if [ $? -ne 0 ] -then -echo "Error while converting odt to pdf" -exit 1 -fi -sleep 1 -else -echo "Error: Odt file does not exist" -exit 1 + then + pgrep -U `id -u` soffice + if [ $? -ne 0 ] + then + soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless & + sleep 2 + fi + jodconverter "$1.odt" "$1.pdf" + if [ $? -ne 0 ] + then + echo "Error while converting odt to pdf" + exit 1 + fi + sleep 1 + else + echo "Error: Odt file does not exist" + exit 1 fi From ee4839c92ed0ba2983936690b0394c9cd885c159 Mon Sep 17 00:00:00 2001 From: fhenry Date: Mon, 22 Apr 2013 15:50:26 +0200 Subject: [PATCH 2/5] Better management for ODT to PDF --- .../doc/doc_generic_order_odt.modules.php | 12 ++++++- .../doc/doc_generic_invoice_odt.modules.php | 12 ++++++- .../pdf/doc_generic_project_odt.modules.php | 12 ++++++- .../doc/doc_generic_proposal_odt.modules.php | 12 ++++++- .../societe/doc/doc_generic_odt.modules.php | 12 ++++++- htdocs/includes/odtphp/odf.php | 31 ++++++++++------- htdocs/includes/odtphp/odt2pdf.sh | 33 ++++++++++++++++--- 7 files changed, 103 insertions(+), 21 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 3330f491e70..623a6b9c8c6 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 @@ -520,10 +520,20 @@ class doc_generic_order_odt extends ModelePDFCommandes // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { - $odfHandler->exportAsAttachedPDF($file); + try { + $odfHandler->exportAsAttachedPDF($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } else { + try { $odfHandler->saveToDisk($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } if (! empty($conf->global->MAIN_UMASK)) 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 8aa417c83c0..b65c6171430 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 @@ -498,10 +498,20 @@ class doc_generic_invoice_odt extends ModelePDFFactures // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { - $odfHandler->exportAsAttachedPDF($file); + try { + $odfHandler->exportAsAttachedPDF($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } else { + try { $odfHandler->saveToDisk($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } if (! empty($conf->global->MAIN_UMASK)) 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 4c81babaa55..a2f8c5fd07a 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 @@ -974,10 +974,20 @@ class doc_generic_project_odt extends ModelePDFProjects // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { - $odfHandler->exportAsAttachedPDF($file); + try { + $odfHandler->exportAsAttachedPDF($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } else { + try { $odfHandler->saveToDisk($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } if (! empty($conf->global->MAIN_UMASK)) 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 d4e485562a4..6a7384ba4d9 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 @@ -483,10 +483,20 @@ class doc_generic_proposal_odt extends ModelePDFPropales // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { - $odfHandler->exportAsAttachedPDF($file); + try { + $odfHandler->exportAsAttachedPDF($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } else { + try { $odfHandler->saveToDisk($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } if (! empty($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 ca93ab1880e..fc609a3de61 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -314,10 +314,20 @@ class doc_generic_odt extends ModeleThirdPartyDoc // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { - $odfHandler->exportAsAttachedPDF($file); + try { + $odfHandler->exportAsAttachedPDF($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } else { + try { $odfHandler->saveToDisk($file); + }catch (Exception $e){ + $this->error=$e->getMessage(); + return -1; + } } if (! empty($conf->global->MAIN_UMASK)) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 03136a20b63..5326af0e116 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -452,14 +452,17 @@ IMG; if( $name == "" ) $name = md5(uniqid()); - //dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG); + dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG); $this->saveToDisk($name); $execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2 - + $name=str_replace('.odt', '', $name); $command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name; + //$dirname=dirname($name); + //$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name.' '.$dirname; + dol_syslog(get_class($this).'::exportAsAttachedPDF $execmethod='.$execmethod.' Run command='.$command,LOG_DEBUG); if ($execmethod == 1) { @@ -471,7 +474,7 @@ IMG; $handle = fopen($outputfile, 'w'); if ($handle) { - dol_syslog("Run command ".$command); + dol_syslog(get_class($this)."Run command ".$command,LOG_DEBUG); $handlein = popen($command, 'r'); while (!feof($handlein)) { @@ -492,19 +495,25 @@ IMG; throw new OdfException("headers already sent ($filename at $linenum)"); } - /*if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.$name.'.pdf"'); readfile("$name.pdf"); - }*/ + } unlink("$name.odt"); } else { - //dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); - //dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG); - echo "Error occured:
"; - foreach($output_arr as $line) - echo $line."
"; - //dol_syslog(get_class($this).'::exportAsAttachedPDF ERROR $line='.$line, LOG_DEBUG); + dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); + dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG); + + if ($retval==126) { + throw new OdfException('Permission execute convert script : ' . $command); + } + else { + foreach($output_arr as $line) { + $errors.= $line."
"; + } + throw new OdfException('ODT to PDF convert fail : ' . $errors); + } } } diff --git a/htdocs/includes/odtphp/odt2pdf.sh b/htdocs/includes/odtphp/odt2pdf.sh index 28f9ef32b22..9268b4a680f 100755 --- a/htdocs/includes/odtphp/odt2pdf.sh +++ b/htdocs/includes/odtphp/odt2pdf.sh @@ -1,18 +1,41 @@ #!/bin/bash # @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com +# @copyright GPL License 2013 - Florian HEnry - florian.henry@open-concept.pro + +# +#if [ -f "$1.odt" ] +# then +# soffice --invisible --convert-to pdf:writer_pdf_Export --outdir $2 "$1.odt" +# retcode=$? +# if [ $retcode -ne 0 ] +# then +# echo "Error while converting odt to pdf: $retcode"; +# exit 1 +# fi +# else +# echo "Error: Odt file does not exist" +# exit 1 +#fi if [ -f "$1.odt" ] then - pgrep -U `id -u` soffice - if [ $? -ne 0 ] + nbprocess=$(pgrep -c soffice) + if [ $nbprocess -ne 1 ] then - soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless & + soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless + retcode=$? + if [ $retcode -ne 0 ] + then + echo "Error running soffice: $retcode" + exit 1 + fi sleep 2 fi jodconverter "$1.odt" "$1.pdf" - if [ $? -ne 0 ] + retcode=$? + if [ $retcode -ne 0 ] then - echo "Error while converting odt to pdf" + echo "Error while converting odt to pdf: $retcode" exit 1 fi sleep 1 From 0513cbe655885339065430188db0cce221f9de27 Mon Sep 17 00:00:00 2001 From: fhenry Date: Tue, 23 Apr 2013 11:12:07 +0200 Subject: [PATCH 3/5] Add debug log (dol_syslog) --- htdocs/comm/list.php | 2 ++ htdocs/product/liste.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/list.php b/htdocs/comm/list.php index e7d6cd2811d..28696228e45 100755 --- a/htdocs/comm/list.php +++ b/htdocs/comm/list.php @@ -137,6 +137,8 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($conf->liste_limit +1, $offset); +dol_syslog('comm:list.php: sql='.$sql,LOG_DEBUG); + $result = $db->query($sql); if ($result) { diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index 9fb9aa8de51..29188400653 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -169,7 +169,7 @@ else $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); - dol_syslog("sql=".$sql); + dol_syslog("product:list.php: sql=".$sql); $resql = $db->query($sql); if ($resql) { From 9ce7e44f006bbe5e1c3c119b3f29dd6df66ef42c Mon Sep 17 00:00:00 2001 From: fhenry Date: Wed, 24 Apr 2013 16:47:15 +0200 Subject: [PATCH 4/5] use price method rather than price2num. price are use in all PDF, so it should be the same on ODT --- htdocs/core/class/commondocgenerator.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 0f4264b223f..c56516257f7 100755 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -245,10 +245,10 @@ abstract class CommonDocGenerator $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), $array_key.'_payment_term_code'=>$object->cond_reglement_code, $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement), - $array_key.'_total_ht'=>price2num($object->total_ht2,2), - $array_key.'_total_vat'=>price2num($object->total_tva,2), - $array_key.'_total_ttc'=>price2num($object->total_ttc,2), - $array_key.'_total_discount_ht' => price2num($object->getTotalDiscount(),2), + $array_key.'_total_ht'=>price($object->total_ht2), + $array_key.'_total_vat'=>price($object->total_tva), + $array_key.'_total_ttc'=>price($object->total_ttc), + $array_key.'_total_discount_ht' => price($object->getTotalDiscount()), $array_key.'_vatrate'=>vatrate($object->tva), $array_key.'_note_private'=>$object->note, $array_key.'_note'=>$object->note_public, @@ -293,12 +293,12 @@ abstract class CommonDocGenerator 'line_product_label'=>$line->product_label, 'line_desc'=>$line->desc, 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), - 'line_up'=>price2num($line->subprice, 2), + 'line_up'=>price($line->subprice), 'line_qty'=>$line->qty, 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), - 'line_price_ht'=>price2num($line->total_ht,2), - 'line_price_ttc'=>price2num($line->total_ttc,2), - 'line_price_vat'=>price2num($line->total_tva,2), + 'line_price_ht'=>price($line->total_ht), + 'line_price_ttc'=>price($line->total_ttc), + 'line_price_vat'=>price($line->total_tva), 'line_date_start'=>$line->date_start, 'line_date_end'=>$line->date_end ); From d9551abb70fcb1cfde64d4b6f86c993d87defd89 Mon Sep 17 00:00:00 2001 From: fhenry Date: Wed, 24 Apr 2013 17:32:08 +0200 Subject: [PATCH 5/5] Fix trad for Extrafield from table --- htdocs/langs/ca_ES/admin.lang | 1 + htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/es_ES/admin.lang | 1 + htdocs/langs/fr_FR/admin.lang | 1 + 4 files changed, 4 insertions(+) diff --git a/htdocs/langs/ca_ES/admin.lang b/htdocs/langs/ca_ES/admin.lang index 2ef97b1cb26..fc0264e1826 100644 --- a/htdocs/langs/ca_ES/admin.lang +++ b/htdocs/langs/ca_ES/admin.lang @@ -354,6 +354,7 @@ ExtrafieldPhone=Telèfon ExtrafieldPrice=Preu ExtrafieldMail=Correu ExtrafieldSelect=Llista de selecció +ExtrafieldSelectList=Llista de selecció de table ExtrafieldSeparator=Separador ExtrafieldCheckBox=Casella de verificació ExtrafieldRadio=Botó de selecció excloent diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 13cd8e505f8..d569e0a261d 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -359,6 +359,7 @@ ExtrafieldPhone = Phone ExtrafieldPrice = Price ExtrafieldMail = Email ExtrafieldSelect = Select list +ExtrafieldSelectList = Select from table ExtrafieldSeparator=Separator ExtrafieldCheckBox=Checkbox ExtrafieldRadio=Radio button diff --git a/htdocs/langs/es_ES/admin.lang b/htdocs/langs/es_ES/admin.lang index 86b6cba5a97..fe4aeba479c 100644 --- a/htdocs/langs/es_ES/admin.lang +++ b/htdocs/langs/es_ES/admin.lang @@ -356,6 +356,7 @@ ExtrafieldPhone=Teléfono ExtrafieldPrice=Precio ExtrafieldMail=Correo ExtrafieldSelect=Lista de selección +ExtrafieldSelectList=Llista de selección de table ExtrafieldSeparator=Separador ExtrafieldCheckBox=Casilla de verificación ExtrafieldRadio=Botón de selección excluyente diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 3b1d3c2f7bc..1dbd9f6df48 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -356,6 +356,7 @@ ExtrafieldPhone = Téléphone ExtrafieldPrice = Prix ExtrafieldMail = Email ExtrafieldSelect = Liste de sélection +ExtrafieldSelectList = Liste issue d'une table ExtrafieldSeparator = Séparateur de champ ExtrafieldCheckBox=Case à cocher ExtrafieldRadio=Case d'option