From e0a3756c6e00948aab2b8bd79c870b9359773901 Mon Sep 17 00:00:00 2001 From: lvessiller-opendsi Date: Wed, 30 Oct 2024 23:35:39 +0100 Subject: [PATCH 1/4] FIX update status on create supplier order for trigger (#31642) --- htdocs/fourn/class/fournisseur.commande.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 49948ebba06..50a5ca62757 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1291,6 +1291,8 @@ class CommandeFournisseur extends CommonOrder { global $langs, $conf, $hookmanager; + $this->oldcopy = dol_clone($this, 2); + $this->db->begin(); $error = 0; @@ -1322,6 +1324,8 @@ class CommandeFournisseur extends CommonOrder // We set order into draft status $this->brouillon = 1; + $this->statut = self::STATUS_DRAFT; + $this->status = self::STATUS_DRAFT; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur ("; $sql .= "ref"; @@ -1410,6 +1414,8 @@ class CommandeFournisseur extends CommonOrder ); if ($result < 0) { dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); // do not use dol_print_error here as it may be a functionnal error + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } @@ -1463,6 +1469,8 @@ class CommandeFournisseur extends CommonOrder // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_CREATE', $user); if ($result < 0) { + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } @@ -1473,12 +1481,16 @@ class CommandeFournisseur extends CommonOrder return $this->id; } else { $this->error = $this->db->lasterror(); + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -2; } } } else { $this->error = $this->db->lasterror(); + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } From 8a55e2f6a4fde700485776d7eed4e482daba0742 Mon Sep 17 00:00:00 2001 From: lvessiller-opendsi Date: Fri, 8 Nov 2024 17:51:44 +0100 Subject: [PATCH 2/4] FIX old copy not needed in supplier order create method (#31733) --- htdocs/fourn/class/fournisseur.commande.class.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 50a5ca62757..020b551f99a 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1291,8 +1291,6 @@ class CommandeFournisseur extends CommonOrder { global $langs, $conf, $hookmanager; - $this->oldcopy = dol_clone($this, 2); - $this->db->begin(); $error = 0; @@ -1324,7 +1322,7 @@ class CommandeFournisseur extends CommonOrder // We set order into draft status $this->brouillon = 1; - $this->statut = self::STATUS_DRAFT; + $this->statut = self::STATUS_DRAFT; // deprecated $this->status = self::STATUS_DRAFT; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur ("; @@ -1414,8 +1412,6 @@ class CommandeFournisseur extends CommonOrder ); if ($result < 0) { dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); // do not use dol_print_error here as it may be a functionnal error - $this->statut = $this->oldcopy->statut; - $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } @@ -1469,8 +1465,6 @@ class CommandeFournisseur extends CommonOrder // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_CREATE', $user); if ($result < 0) { - $this->statut = $this->oldcopy->statut; - $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } @@ -1481,16 +1475,12 @@ class CommandeFournisseur extends CommonOrder return $this->id; } else { $this->error = $this->db->lasterror(); - $this->statut = $this->oldcopy->statut; - $this->status = $this->oldcopy->status; $this->db->rollback(); return -2; } } } else { $this->error = $this->db->lasterror(); - $this->statut = $this->oldcopy->statut; - $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } From 67c2a48fc9862f31f215da4f4e0be0d6c3ce7abf Mon Sep 17 00:00:00 2001 From: Eric - CAP-REL <1468823+rycks@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:39:10 +0100 Subject: [PATCH 3/4] Add missing extrafields on strato pdf model (#31790) * undef var * add main extrafields on object * remove dev debug sorry ! --------- Co-authored-by: Laurent Destailleur --- .../contract/doc/pdf_strato.modules.php | 18 ++++++++++++++++-- .../core/modules/contract/modules_contract.php | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/contract/doc/pdf_strato.modules.php b/htdocs/core/modules/contract/doc/pdf_strato.modules.php index fe6f77b9b9a..52834189978 100644 --- a/htdocs/core/modules/contract/doc/pdf_strato.modules.php +++ b/htdocs/core/modules/contract/doc/pdf_strato.modules.php @@ -7,6 +7,7 @@ * Copyright (C) 2013-2020 Philippe Grand * Copyright (C) 2015 Marcos García * Copyright (C) 2018-2020 Frédéric France + * Copyright (C) 2024 Éric Seigne * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -300,11 +301,24 @@ class pdf_strato extends ModelePDFContract $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10); // Display notes - if (!empty($object->note_public)) { + $notetoshow = empty($object->note_public) ? '' : $object->note_public; + + // Extrafields in note + $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); + if (!empty($extranote)) { + $notetoshow = dol_concatdesc($notetoshow, $extranote); + } + + if (!empty($notetoshow)) { $tab_top -= 2; + $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); + $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow); + $pdf->SetFont('', '', $default_font_size - 1); - $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1); + $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1); $nexY = $pdf->GetY(); $height_note = $nexY - $tab_top; diff --git a/htdocs/core/modules/contract/modules_contract.php b/htdocs/core/modules/contract/modules_contract.php index 577ec4be5d9..2089736b5c2 100644 --- a/htdocs/core/modules/contract/modules_contract.php +++ b/htdocs/core/modules/contract/modules_contract.php @@ -41,6 +41,7 @@ abstract class ModelePDFContract extends CommonDocGenerator * @var string Error code (or message) */ public $error = ''; + public $posxdesc; // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps From 93f23fe452c20d75d87c220b5fdee1559f092534 Mon Sep 17 00:00:00 2001 From: thomas-Ngr Date: Wed, 13 Nov 2024 16:18:08 +0100 Subject: [PATCH 4/4] ODF : fix : escape specials chars in IF ELSE ENDIF $key (#31796) * ODF : fix : escape specials chars in IF ELSE ENDIF $key * fix missing brackets * add delimiter to preg_quote --------- Co-authored-by: Brice Werry --- htdocs/includes/odtphp/Segment.php | 4 ++-- htdocs/includes/odtphp/odf.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index ca8797ba577..f8539e6187c 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -117,14 +117,14 @@ class Segment implements IteratorAggregate, Countable // Remove the IF tag $this->xml = str_replace('[!-- IF '.$key.' --]', '', $this->xml); // Remove everything between the ELSE tag (if it exists) and the ENDIF tag - $reg = '@(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy + $reg = '@(\[!--\sELSE\s' . preg_quote($key, '@') . '\s--\](.*))?\[!--\sENDIF\s' . preg_quote($key, '@') . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy $this->xml = preg_replace($reg, '', $this->xml); } // Else the value is false, then two cases: no ELSE and we're done, or there is at least one place where there is an ELSE clause, then we replace it else { // Find all conditional blocks for this variable: from IF to ELSE and to ENDIF - $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy + $reg = '@\[!--\sIF\s' . preg_quote($key, '@') . '\s--\](.*)(\[!--\sELSE\s' . preg_quote($key, '@') . '\s--\](.*))?\[!--\sENDIF\s' . preg_quote($key, '@') . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER); foreach($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause if (!empty($match[3])) $this->xml = str_replace($match[0], $match[3], $this->xml); diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index b780b550b6d..019d162be00 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -539,7 +539,8 @@ IMG; private function _parse($type='content') { // Search all tags fou into condition to complete $this->vars, so we will proceed all tests even if not defined - $reg='@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; + $reg='@\[!--\sIF\s([\[\]{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; + $matches = array(); preg_match_all($reg, $this->contentXml, $matches, PREG_SET_ORDER); //var_dump($this->vars);exit; @@ -564,7 +565,7 @@ IMG; // Remove the IF tag $this->contentXml = str_replace('[!-- IF '.$key.' --]', '', $this->contentXml); // Remove everything between the ELSE tag (if it exists) and the ENDIF tag - $reg = '@(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy + $reg = '@(\[!--\sELSE\s' . preg_quote($key, '@') . '\s--\](.*))?\[!--\sENDIF\s' . preg_quote($key, '@') . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy $this->contentXml = preg_replace($reg, '', $this->contentXml); /*if ($sav != $this->contentXml) { @@ -578,7 +579,7 @@ IMG; //dol_syslog("Var ".$key." is not defined, we remove the IF, ELSE and ENDIF "); //$sav=$this->contentXml; // Find all conditional blocks for this variable: from IF to ELSE and to ENDIF - $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy + $reg = '@\[!--\sIF\s' . preg_quote($key, '@') . '\s--\](.*)(\[!--\sELSE\s' . preg_quote($key, '@') . '\s--\](.*))?\[!--\sENDIF\s' . preg_quote($key, '@') . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy preg_match_all($reg, $this->contentXml, $matches, PREG_SET_ORDER); foreach($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause if (!empty($match[3])) $this->contentXml = str_replace($match[0], $match[3], $this->contentXml);