--- /tmp/dsg/dolibarr/htdocs/core/modules/bom/doc/github_doc_generic_bom_odt.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/bom/doc/client_doc_generic_bom_odt.modules.php
@@ -47,14 +47,14 @@
public $emetteur;
/**
- * @var array Minimum version of PHP required by module.
- * e.g.: PHP ≥ 5.6 = array(5, 6)
- */
- public $phpmin = array(5, 6);
+ * @var array Minimum version of PHP required by module.
+ * e.g.: PHP ≥ 5.5 = array(5, 5)
+ */
+ public $phpmin = array(5, 5);
/**
- * @var string Dolibarr version of the loaded document
- */
+ * @var string Dolibarr version of the loaded document
+ */
public $version = 'dolibarr';
@@ -63,12 +63,12 @@
*
* @param DoliDB $db Database handler
*/
- public function __construct($db)
+ public function __construct($db)
{
global $conf, $langs, $mysoc;
// Load translation files required by the page
- $langs->loadLangs(array("main", "companies"));
+ $langs->loadLangs(array("main", "companies"));
$this->db = $db;
$this->name = "ODT templates";
@@ -101,12 +101,12 @@
* @param Translate $langs Lang object to use for output
* @return string Description
*/
- public function info($langs)
+ public function info($langs)
{
global $conf, $langs;
// Load translation files required by the page
- $langs->loadLangs(array("errors", "companies"));
+ $langs->loadLangs(array("errors", "companies"));
$form = new Form($this->db);
@@ -130,7 +130,8 @@
unset($listofdir[$key]); continue;
}
if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
- else {
+ else
+ {
$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
}
@@ -162,10 +163,10 @@
if ($nbofiles)
{
- $texte .= '
';
- // Show list of found files
- foreach ($listoffiles as $file) {
- $texte .= '- '.$file['name'].'
'.img_picto('', 'listlight').'';
+ $texte .= '
';
+ foreach ($listoffiles as $file)
+ {
+ $texte .= $file['name'].'
';
}
$texte .= '
';
}
@@ -183,7 +184,7 @@
return $texte;
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build a document on disk using the generic odt module.
*
@@ -195,9 +196,9 @@
* @param int $hideref Do not show ref
* @return int 1 if OK, <=0 if KO
*/
- public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
+ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
- // phpcs:enable
+ // phpcs:enable
global $user, $langs, $conf, $mysoc, $hookmanager;
if (empty($srctemplatepath))
@@ -235,8 +236,6 @@
return -1;
}
}
-
- $object->fetch_thirdparty();
$dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
$objectref = dol_sanitizeFileName($object->ref);
@@ -265,10 +264,12 @@
$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
if (!empty($conf->global->MAIN_DOC_USE_TIMING))
{
- $format = $conf->global->MAIN_DOC_USE_TIMING;
- if ($format == '1') $format = '%Y%m%d%H%M%S';
+ $format = $conf->global->MAIN_DOC_USE_TIMING;
+ if ($format == '1') $format = '%Y%m%d%H%M%S';
$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
- } else {
+ }
+ else
+ {
$filename = $newfiletmp.'.'.$newfileformat;
}
$file = $dir.'/'.$filename;
@@ -294,14 +295,15 @@
if (!empty($usecontact))
{
// On peut utiliser le nom de la societe du contact
- if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
- $socobject = $object->contact;
- } else {
- $socobject = $object->thirdparty;
- // if we have a CUSTOMER contact and we dont use as recipient we store the contact object for later use
- $contactobject = $object->contact;
- }
- } else {
+ if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
+ else {
+ $socobject = $object->thirdparty;
+ // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
+ $contactobject = $object->contact;
+ }
+ }
+ else
+ {
$socobject = $object->thirdparty;
}
@@ -325,7 +327,7 @@
// Open and load template
require_once ODTPHP_PATH.'odf.php';
try {
- $odfHandler = new odf(
+ $odfHandler = new odf(
$srctemplatepath,
array(
'PATH_TO_TMP' => $conf->bom->dir_temp,
@@ -334,7 +336,8 @@
'DELIMITER_RIGHT' => '}'
)
);
- } catch (Exception $e)
+ }
+ catch (Exception $e)
{
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
@@ -350,9 +353,10 @@
// Make substitutions into odt of freetext
try {
$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
- } catch (OdfException $e)
- {
- dol_syslog($e->getMessage(), LOG_INFO);
+ }
+ catch (OdfException $e)
+ {
+ dol_syslog($e->getMessage(), LOG_INFO);
}
// Define substitution array
@@ -381,21 +385,25 @@
{
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)
+ }
+ catch (OdfException $e)
{
- dol_syslog($e->getMessage(), LOG_INFO);
+ dol_syslog($e->getMessage(), LOG_INFO);
}
}
// Replace tags of lines
- try {
+ try
+ {
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
- } catch (OdfException $e)
+ }
+ catch (OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
@@ -414,21 +422,25 @@
$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach ($tmparray as $key => $val)
{
- try {
+ try
+ {
$listlines->setVars($key, $val, true, 'UTF-8');
- } catch (OdfException $e)
+ }
+ catch (OdfException $e)
{
- dol_syslog($e->getMessage(), LOG_INFO);
- } catch (SegmentException $e)
+ dol_syslog($e->getMessage(), LOG_INFO);
+ }
+ catch (SegmentException $e)
{
- dol_syslog($e->getMessage(), LOG_INFO);
+ dol_syslog($e->getMessage(), LOG_INFO);
}
}
$listlines->merge();
}
$odfHandler->mergeSegment($listlines);
}
- } catch (OdfException $e)
+ }
+ catch (OdfException $e)
{
$this->error = $e->getMessage();
dol_syslog($this->error, LOG_WARNING);
@@ -441,9 +453,10 @@
{
try {
$odfHandler->setVars($key, $value, true, 'UTF-8');
- } catch (OdfException $e)
+ }
+ catch (OdfException $e)
{
- dol_syslog($e->getMessage(), LOG_INFO);
+ dol_syslog($e->getMessage(), LOG_INFO);
}
}
@@ -457,16 +470,17 @@
try {
$odfHandler->exportAsAttachedPDF($file);
} catch (Exception $e) {
- $this->error = $e->getMessage();
- dol_syslog($e->getMessage(), LOG_INFO);
+ $this->error = $e->getMessage();
+ dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
- } else {
+ }
+ else {
try {
$odfHandler->saveToDisk($file);
} catch (Exception $e) {
- $this->error = $e->getMessage();
- dol_syslog($e->getMessage(), LOG_INFO);
+ $this->error = $e->getMessage();
+ dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
}
@@ -482,7 +496,9 @@
$this->result = array('fullpath'=>$file);
return 1; // Success
- } else {
+ }
+ else
+ {
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}