From 2dffe3748d2d983bda5b375fa31b65d77452af0a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 18 Nov 2022 13:41:27 +0100 Subject: [PATCH] Debug v17 - Fix missing delete picto on ODT setup --- .../doc/doc_generic_asset_odt.modules.php | 4 +- .../bom/doc/doc_generic_bom_odt.modules.php | 4 +- .../doc/doc_generic_order_odt.modules.php | 6 ++- .../doc/doc_generic_contract_odt.modules.php | 44 ++++++++++++++----- .../doc/doc_generic_shipment_odt.modules.php | 4 +- .../doc/doc_generic_invoice_odt.modules.php | 4 +- .../doc/doc_generic_member_odt.class.php | 4 +- .../mrp/doc/doc_generic_mo_odt.modules.php | 4 +- .../doc/doc_generic_project_odt.modules.php | 4 +- .../task/doc/doc_generic_task_odt.modules.php | 4 +- .../doc/doc_generic_reception_odt.modules.php | 4 +- .../doc/doc_generic_stock_odt.modules.php | 4 +- ...doc_generic_supplier_order_odt.modules.php | 6 ++- ..._generic_supplier_proposal_odt.modules.php | 4 +- .../doc/doc_generic_ticket_odt.modules.php | 4 +- .../user/doc/doc_generic_user_odt.modules.php | 4 +- .../doc/doc_generic_myobject_odt.modules.php | 21 ++++----- 17 files changed, 91 insertions(+), 38 deletions(-) diff --git a/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php b/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php index b11e2a7e563..8be86dda944 100644 --- a/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php +++ b/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php @@ -173,7 +173,9 @@ class doc_generic_asset_odt extends ModelePDFAsset if ($nbofiles) { $texte .= ''; } diff --git a/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php b/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php index 2dcf5512dc1..bec28b941aa 100644 --- a/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php +++ b/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php @@ -169,7 +169,9 @@ class doc_generic_bom_odt extends ModelePDFBom $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } 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 9239ec0ed4b..5e94397bc91 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 @@ -159,7 +159,7 @@ class doc_generic_order_odt extends ModelePDFCommandes $texte .= $conf->global->COMMANDE_ADDON_PDF_ODT_PATH; $texte .= ''; $texte .= '
'; - $texte .= ''; + $texte .= ''; $texte .= '
'; // Scan directories @@ -176,7 +176,9 @@ class doc_generic_order_odt extends ModelePDFCommandes $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php b/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php index 222286d5592..dad1ebc9122 100644 --- a/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php +++ b/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php @@ -51,8 +51,7 @@ class doc_generic_contract_odt extends ModelePDFContract public $phpmin = array(7, 0); /** - * Dolibarr version of the loaded document - * @var string + * @var string Dolibarr version of the loaded document */ public $version = 'dolibarr'; @@ -94,7 +93,7 @@ class doc_generic_contract_odt extends ModelePDFContract $this->option_freetext = 1; // Support add of a personalised text $this->option_draft_watermark = 0; // Support add of a watermark on drafts - // Recupere emetteur + // Get source company $this->emetteur = $mysoc; if (!$this->emetteur->country_code) { $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined @@ -123,7 +122,7 @@ class doc_generic_contract_odt extends ModelePDFContract $texte .= ''; $texte .= ''; $texte .= ''; - $texte .= ''; + $texte .= '
'; // List of directories area $texte .= ''; - // Add input to upload a new template file. $texte .= '
'.$langs->trans("UploadNewTemplate"); $maxfilesizearray = getMaxFileSizeArray(); @@ -195,6 +193,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject $texte .= ''; $texte .= ''; $texte .= '
'; + $texte .= ''; $texte .= '
'; @@ -161,10 +160,25 @@ class doc_generic_contract_odt extends ModelePDFContract $texte .= '
'; // Scan directories - if (count($listofdir)) { - $texte .= $langs->trans("NumberOfModelFilesFound").': '.count($listoffiles).''; + $nbofiles = count($listoffiles); + if (!empty($conf->global->CONTRACT_ADDON_PDF_ODT_PATH)) { + $texte .= $langs->trans("NumberOfModelFilesFound").': '; + //$texte.=$nbofiles?'':''; + $texte .= count($listoffiles); + //$texte.=$nbofiles?'':''; + $texte .= ''; } + if ($nbofiles) { + $texte .= '
'; + // Show list of found files + foreach ($listoffiles as $file) { + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; + } + $texte .= '
'; + } // Add input to upload a new template file. $texte .= '
'.$langs->trans("UploadNewTemplate"); $maxfilesizearray = getMaxFileSizeArray(); @@ -228,7 +242,7 @@ class doc_generic_contract_odt extends ModelePDFContract $sav_charset_output = $outputlangs->charset_output; $outputlangs->charset_output = 'UTF-8'; - // Load traductions files required by page + // Load translation files required by page $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); if ($conf->contrat->multidir_output[$object->entity]) { @@ -382,16 +396,21 @@ class doc_generic_contract_odt extends ModelePDFContract dol_syslog($e->getMessage(), LOG_INFO); } + // Call the ODTSubstitution hook + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + foreach ($tmparray as $key => $value) { try { - if (preg_match('/logo$/', $key)) { // Image + if (preg_match('/logo$/', $key)) { + // Image if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } - } else // Text - { + } else { + // Text $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { @@ -448,7 +467,7 @@ class doc_generic_contract_odt extends ModelePDFContract } // Call the beforeODTSave hook - $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks // Write new file @@ -457,6 +476,7 @@ class doc_generic_contract_odt extends ModelePDFContract $odfHandler->exportAsAttachedPDF($file); } catch (Exception $e) { $this->error = $e->getMessage(); + dol_syslog($e->getMessage(), LOG_INFO); return -1; } } else { @@ -464,10 +484,12 @@ class doc_generic_contract_odt extends ModelePDFContract $odfHandler->saveToDisk($file); } catch (Exception $e) { $this->error = $e->getMessage(); + dol_syslog($e->getMessage(), LOG_INFO); return -1; } } + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($conf->global->MAIN_UMASK)) { 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 cfb23269ca9..73793c5a757 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 @@ -175,7 +175,9 @@ class doc_generic_shipment_odt extends ModelePdfExpedition $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } 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 061f18e5442..0b8fa2d4621 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 @@ -174,7 +174,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/member/doc/doc_generic_member_odt.class.php b/htdocs/core/modules/member/doc/doc_generic_member_odt.class.php index 2ab951147b9..ed48c93c4de 100644 --- a/htdocs/core/modules/member/doc/doc_generic_member_odt.class.php +++ b/htdocs/core/modules/member/doc/doc_generic_member_odt.class.php @@ -164,7 +164,9 @@ class doc_generic_member_odt extends ModelePDFMember $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php b/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php index 42b3c529fe4..b89c4eab2cd 100644 --- a/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php +++ b/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php @@ -175,7 +175,9 @@ class doc_generic_mo_odt extends ModelePDFMo $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php index 4e8be5f6389..2015da21f61 100644 --- a/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php @@ -468,7 +468,9 @@ class doc_generic_project_odt extends ModelePDFProjects $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php index ba386eedfe7..a7f3eab4a30 100644 --- a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php +++ b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php @@ -433,7 +433,9 @@ class doc_generic_task_odt extends ModelePDFTask $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php b/htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php index 4d8edca7f64..4ebc742b4bb 100644 --- a/htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php +++ b/htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php @@ -168,7 +168,9 @@ class doc_generic_reception_odt extends ModelePdfReception $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php b/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php index 0f5adc3fc7d..eb6ba838d7a 100644 --- a/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php +++ b/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php @@ -172,7 +172,9 @@ class doc_generic_stock_odt extends ModelePDFStock $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php b/htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php index f3177233589..12bbcc12edc 100644 --- a/htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php +++ b/htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php @@ -163,7 +163,7 @@ class doc_generic_supplier_order_odt extends ModelePDFSuppliersOrders // Scan directories $nbofiles = count($listoffiles); - if (!empty($conf->global->COMMANDE_ADDON_PDF_ODT_PATH)) { + if (!empty($conf->global->SUPPLIER_ORDER_ADDON_PDF_ODT_PATH)) { $texte .= $langs->trans("NumberOfModelFilesFound").': '; //$texte.=$nbofiles?'':''; $texte .= count($listoffiles); @@ -175,7 +175,9 @@ class doc_generic_supplier_order_odt extends ModelePDFSuppliersOrders $texte .= ''; } diff --git a/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php b/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php index fc75445123a..55a7710c5a4 100644 --- a/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php @@ -179,7 +179,9 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; diff --git a/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php b/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php index ff6359be5ce..1a2d1e537cc 100644 --- a/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php +++ b/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php @@ -161,7 +161,9 @@ class doc_generic_ticket_odt extends ModelePDFTicket $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php b/htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php index d129c80f126..1c3e346203b 100644 --- a/htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php +++ b/htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php @@ -192,7 +192,9 @@ class doc_generic_user_odt extends ModelePDFUser $texte .= '
'; // Show list of found files foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; + $texte .= '   '.img_picto('', 'delete').''; + $texte .= '
'; } $texte .= '
'; } diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php index 46967d6e4fa..b7dfc374a52 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php @@ -119,7 +119,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject $form = new Form($this->db); $texte = $this->description.".
\n"; - $texte .= '
'; + $texte .= ''; $texte .= ''; $texte .= ''; $texte .= ''; @@ -158,7 +158,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject $texte .= $conf->global->MYMODULE_MYOBJECT_ADDON_PDF_ODT_PATH; $texte .= ''; $texte .= '
'; - $texte .= ''; + $texte .= ''; $texte .= '
'; // Scan directories @@ -172,18 +172,16 @@ class doc_generic_myobject_odt extends ModelePDFMyObject } if ($nbofiles) { - $texte .= '
'; @@ -282,8 +281,10 @@ class doc_generic_myobject_odt extends ModelePDFMyObject $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); + $newfiletmp = $objectref . '_' . $newfiletmp; //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; + // Get extension (ods or odt) $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); if (!empty($conf->global->MAIN_DOC_USE_TIMING)) { @@ -308,7 +309,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject return -1; } - // If CUSTOMER contact defined on order, we use it + // If CUSTOMER contact defined on object, we use it $usecontact = false; $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); if (count($arrayidcontact) > 0) { @@ -348,7 +349,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject // Line of free text $newfreetext = ''; - $paramfreetext = 'ORDER_FREE_TEXT'; + $paramfreetext = 'MYMODULE_MYOBJECT_FREE_TEXT'; if (!empty($conf->global->$paramfreetext)) { $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); }