From 7d52ee1e864bfe33b9ae4ad2f97f7ccc162dc7f3 Mon Sep 17 00:00:00 2001 From: David Beniamine Date: Mon, 29 Apr 2024 15:46:32 +0200 Subject: [PATCH] Make odt model work --- .../dons/doc/doc_generic_don_odt.modules.php | 14 +++++++------- htdocs/don/admin/donation.php | 10 +++++++++- htdocs/don/class/don.class.php | 11 ++++++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/dons/doc/doc_generic_don_odt.modules.php b/htdocs/core/modules/dons/doc/doc_generic_don_odt.modules.php index 66b8abcb4f485..4bdeff99fe3fc 100644 --- a/htdocs/core/modules/dons/doc/doc_generic_don_odt.modules.php +++ b/htdocs/core/modules/dons/doc/doc_generic_don_odt.modules.php @@ -21,7 +21,7 @@ */ /** - * \file htdocs/core/modules/don/doc/doc_generic_dons_odt.modules.php + * \file htdocs/core/modules/don/doc/doc_generic_don_odt.modules.php * \ingroup societe * \brief File of class to build ODT documents for third parties */ @@ -245,7 +245,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails // Load translation files required by the page $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); - if ($conf->dons->dir_output) { + if ($conf->don->dir_output) { // If $object is id instead of object if (!is_object($object)) { $id = $object; @@ -259,7 +259,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $object->fetch_thirdparty(); - $dir = $conf->dons->dir_output; + $dir = $conf->don->dir_output; $objectref = dol_sanitizeFileName($object->ref); if (!preg_match('/specimen/i', $objectref)) { $dir .= "/".$objectref; @@ -300,9 +300,9 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails //print "file=".$file; //print "conf->societe->dir_temp=".$conf->societe->dir_temp; - dol_mkdir($conf->dons->dir_temp); - if (!is_writable($conf->dons->dir_temp)) { - $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->dons->dir_temp); + dol_mkdir($conf->don->dir_temp); + if (!is_writable($conf->don->dir_temp)) { + $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->don->dir_temp); dol_syslog('Error in write_file: ' . $this->error, LOG_ERR); return -1; } @@ -368,7 +368,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $odfHandler = new odf( $srctemplatepath, array( - 'PATH_TO_TMP' => $conf->dons->dir_temp, + 'PATH_TO_TMP' => $conf->don->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}' diff --git a/htdocs/don/admin/donation.php b/htdocs/don/admin/donation.php index e726d70b135d1..509465bc47257 100644 --- a/htdocs/don/admin/donation.php +++ b/htdocs/don/admin/donation.php @@ -52,6 +52,7 @@ /* * Action */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; if ($action == 'specimen') { $modele = GETPOST('module', 'alpha'); @@ -228,7 +229,14 @@ while (($file = readdir($handle)) !== false) { if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(html_|doc_)/', $file)) { if (file_exists($dir.'/'.$file)) { - $name = substr($file, 0, dol_strlen($file) - 12); + if (preg_match('/^doc/', $file)) { + $start = 4; + $end = 16; + } else { + $start = 0; + $end = 12; + } + $name = substr($file, $start, dol_strlen($file) - $end); $classname = substr($file, 0, dol_strlen($file) - 12); require_once $dir.'/'.$file; diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index 483a53465ee27..3253ff1a7fb45 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -1029,7 +1029,10 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided } } - //$modelpath = "core/modules/dons/"; + $modelpath = "core/modules/dons/"; + if (preg_match('/.odt$/', $modele)) { + $modelpath .= 'doc/'; + } // TODO Restore use of commonGenerateDocument instead of dedicated code here //return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -1062,7 +1065,7 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided $file = $prefix."_".preg_replace('/^html_/', '', $modele).".modules.php"; // On verifie l'emplacement du modele - $file = dol_buildpath($reldir."core/modules/dons/".$file, 0); + $file = dol_buildpath($reldir.$modelpath.$file, 0); if (file_exists($file)) { $filefound = 1; $classname = $prefix.'_'.$modele; @@ -1080,7 +1083,9 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided $object = $this; - $classname = $modele; + if (!preg_match("/^doc_/", $classname)) { + $classname = $modele; + } $obj = new $classname($this->db); // We save charset_output to restore it because write_file can change it if needed for