Skip to content

Commit

Permalink
Make odt model work
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeniamine committed Jan 2, 2025
1 parent 239ea23 commit 7d52ee1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
14 changes: 7 additions & 7 deletions htdocs/core/modules/dons/doc/doc_generic_don_odt.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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' => '}'
Expand Down
10 changes: 9 additions & 1 deletion htdocs/don/admin/donation.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
/*
* Action
*/
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';

if ($action == 'specimen') {
$modele = GETPOST('module', 'alpha');
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions htdocs/don/class/don.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 7d52ee1

Please sign in to comment.