--- /tmp/dsg/dolibarr/htdocs/core/modules/user/doc/github_doc_generic_user_odt.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/user/doc/client_doc_generic_user_odt.modules.php @@ -1,7 +1,7 @@ * Copyright (C) 2012 Juanjo Menent - * Copyright (C) 2018-2020 Frédéric France + * Copyright (C) 2018 Frédéric France * * 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 @@ -42,15 +42,15 @@ public $emetteur; /** - * @var array Minimum version of PHP required by module. - * e.g.: PHP ≥ 5.6 = array(5, 6) - */ - public $phpmin = array(5, 6); - - /** - * Dolibarr version of the loaded document - * @var string - */ + * @var array Minimum version of PHP required by module. + * e.g.: PHP ≥ 5.5 = array(5, 5) + */ + public $phpmin = array(5, 5); + + /** + * Dolibarr version of the loaded document + * @var string + */ public $version = 'dolibarr'; @@ -59,12 +59,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"; @@ -104,17 +104,17 @@ * @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('companies', 'errors')); + $langs->loadLangs(array('companies', 'errors')); $form = new Form($this->db); $texte = $this->description.".
\n"; - $texte .= '
'; + $texte .= ''; $texte .= ''; $texte .= ''; $texte .= ''; @@ -139,7 +139,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); } @@ -187,18 +188,7 @@ $texte .= ""; $texte .= ''; } - $texte .= '
'; - // Show list of found files - foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; - } - $texte .= '
'; - } - // Add input to upload a new template file. - $texte .= '
'.$langs->trans("UploadNewTemplate").' '; - $texte .= ''; - $texte .= ''; - $texte .= '
'; + } $texte .= ''; @@ -213,7 +203,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. * @@ -225,9 +215,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)) @@ -266,8 +256,6 @@ return -1; } } - - $object->fetch_thirdparty(); $dir = $conf->user->dir_output; $objectref = dol_sanitizeFileName($object->ref); @@ -297,10 +285,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; @@ -324,21 +314,23 @@ // Recipient name if (!empty($usecontact)) { - 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 it as recipient we store the contact object for later use - $contactobject = $object->contact; - } - } else { + // On peut utiliser le nom de la societe du contact + 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; } // Open and load template require_once ODTPHP_PATH.'odf.php'; try { - $odfHandler = new odf( + $odfHandler = new odf( $srctemplatepath, array( 'PATH_TO_TMP' => $conf->user->dir_temp, @@ -347,7 +339,8 @@ 'DELIMITER_RIGHT' => '}' ) ); - } catch (Exception $e) + } + catch (Exception $e) { $this->error = $e->getMessage(); dol_syslog($e->getMessage(), LOG_WARNING); @@ -376,11 +369,13 @@ { 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_WARNING); } @@ -392,7 +387,8 @@ { try { $odfHandler->setVars($key, $value, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_WARNING); } @@ -411,7 +407,8 @@ dol_syslog($e->getMessage(), LOG_WARNING); return -1; } - } else { + } + else { try { $odfHandler->saveToDisk($file); } catch (Exception $e) { @@ -431,7 +428,9 @@ $this->result = array('fullpath'=>$file); return 1; // Success - } else { + } + else + { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return -1; } @@ -440,18 +439,18 @@ return -1; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * get substitution array for object - * - * @param User $object user - * @param Translate $outputlangs translation object - * @param string $array_key key for array - * @return array array of substitutions - */ - public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') - { - // phpcs:enable + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * get substitution array for object + * + * @param User $object user + * @param Translate $outputlangs translation object + * @param string $array_key key for array + * @return array array of substitutions + */ + public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') + { + // phpcs:enable $array_other = array(); foreach ($object as $key => $value) { if (!is_array($value) && !is_object($value)) {