--- /tmp/dsg/dolibarr/htdocs/core/modules/user/doc/github_19.0.3_doc_generic_user_odt.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/user/doc/client_doc_generic_user_odt.modules.php @@ -4 +4 @@ - * Copyright (C) 2018-2021 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -40,2 +40 @@ - * Dolibarr version of the loaded document - * @var string + * @var Societe Issuer @@ -42,0 +42,12 @@ + public $emetteur; + + /** + * @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 + */ @@ -51 +62 @@ - public function __construct($db) + public function __construct($db) @@ -53 +64 @@ - global $langs, $mysoc; + global $conf, $langs, $mysoc; @@ -56 +67 @@ - $langs->loadLangs(array("main", "companies")); + $langs->loadLangs(array("main", "companies")); @@ -73,6 +84,7 @@ - $this->option_logo = 1; // Display logo - $this->option_tva = 0; // Manage the vat option USER_TVAOPTION - $this->option_modereg = 0; // Display payment mode - $this->option_condreg = 0; // Display payment terms - $this->option_multilang = 1; // Available in several languages - $this->option_escompte = 0; // Displays if there has been a discount + $this->option_logo = 1; // Affiche logo + $this->option_tva = 0; // Gere option tva USER_TVAOPTION + $this->option_modereg = 0; // Affiche mode reglement + $this->option_condreg = 0; // Affiche conditions reglement + $this->option_codeproduitservice = 0; // Affiche code produit-service + $this->option_multilang = 1; // Dispo en plusieurs langues + $this->option_escompte = 0; // Affiche si il y a eu escompte @@ -83 +95 @@ - // Get source company + // Recupere emetteur @@ -85,3 +97 @@ - if (!$this->emetteur->country_code) { - $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined - } + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined @@ -97 +107 @@ - public function info($langs) + public function info($langs) @@ -102 +112 @@ - $langs->loadLangs(array('companies', 'errors')); + $langs->loadLangs(array('companies', 'errors')); @@ -106,3 +115,0 @@ - $odtChosen = getDolGlobalInt('MAIN_PROPAL_CHOOSE_ODT_DOCUMENT') > 0; - $odtPath = trim(getDolGlobalString('USER_ADDON_PDF_ODT_PATH')); - @@ -110 +117 @@ - $texte .= '
'; + $texte .= ''; @@ -112 +118,0 @@ - $texte .= ''; @@ -115 +121,2 @@ - if ($odtChosen) { + if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) + { @@ -125 +132 @@ - $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', $odtPath)); + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->USER_ADDON_PDF_ODT_PATH))); @@ -127 +134,2 @@ - foreach ($listofdir as $key => $tmpdir) { + foreach ($listofdir as $key=>$tmpdir) + { @@ -131,6 +139,5 @@ - unset($listofdir[$key]); - continue; - } - if (!is_dir($tmpdir)) { - $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); - } else { + unset($listofdir[$key]); continue; + } + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); + else + { @@ -138,3 +145 @@ - if (count($tmpfiles)) { - $listoffiles = array_merge($listoffiles, $tmpfiles); - } + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); @@ -144 +148,0 @@ - $texthelp .= '

'.$langs->trans("ExampleOfDirectoriesForModelGen").''; @@ -149 +153 @@ - $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1, 3, $this->name); + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); @@ -152 +156 @@ - $texte .= $odtPath; + $texte .= $conf->global->USER_ADDON_PDF_ODT_PATH; @@ -155 +159 @@ - $texte .= ''; + $texte .= ''; @@ -159 +163,2 @@ - if (count($listofdir)) { + if (count($listofdir)) + { @@ -162 +167,2 @@ - if ($odtChosen) { + if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) + { @@ -164 +170 @@ - $list = ModelePDFUser::liste_modeles($this->db); + $liste = ModelePDFUser::liste_modeles($this->db); @@ -169 +175 @@ - $texte .= $form->selectarray('value2', $list, getDolGlobalString('USER_ADDON_PDF_ODT_DEFAULT')); + $texte .= $form->selectarray('value2', $liste, $conf->global->USER_ADDON_PDF_ODT_DEFAULT); @@ -175 +181 @@ - $texte .= $form->selectarray('value3', $list, getDolGlobalString('USER_ADDON_PDF_ODT_TOBILL')); + $texte .= $form->selectarray('value3', $liste, $conf->global->USER_ADDON_PDF_ODT_TOBILL); @@ -181 +187 @@ - $texte .= $form->selectarray('value4', $list, getDolGlobalString('USER_ADDON_PDF_ODT_CLOSED')); + $texte .= $form->selectarray('value4', $liste, $conf->global->USER_ADDON_PDF_ODT_CLOSED); @@ -185,20 +191 @@ - $texte .= '
'; - // Show list of found files - foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').''; - $texte .= '   '.img_picto('', 'delete').''; - $texte .= '
'; - } - $texte .= '
'; - } - // Add input to upload a new template file. - $texte .= '
'.$langs->trans("UploadNewTemplate"); - $maxfilesizearray = getMaxFileSizeArray(); - $maxmin = $maxfilesizearray['maxmin']; - if ($maxmin > 0) { - $texte .= ''; // MAX_FILE_SIZE must precede the field type=file - } - $texte .= ' '; - $texte .= ''; - $texte .= ''; - $texte .= '
'; + } @@ -207,0 +195,3 @@ + $texte .= ''; + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); + $texte .= ''; @@ -216 +206 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -228 +218 @@ - 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) @@ -230 +220 @@ - // phpcs:enable + // phpcs:enable @@ -233 +223,2 @@ - if (empty($srctemplatepath)) { + if (empty($srctemplatepath)) + { @@ -239 +230,2 @@ - if (!is_object($hookmanager)) { + if (!is_object($hookmanager)) + { @@ -246,3 +238 @@ - if (!is_object($outputlangs)) { - $outputlangs = $langs; - } + if (!is_object($outputlangs)) $outputlangs = $langs; @@ -255 +245,2 @@ - if ($conf->user->dir_output) { + if ($conf->user->dir_output) + { @@ -257 +248,2 @@ - if (!is_object($object)) { + if (!is_object($object)) + { @@ -261 +253,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -267,2 +259,0 @@ - $object->fetch_thirdparty(); - @@ -271,3 +262 @@ - if (!preg_match('/specimen/i', $objectref)) { - $dir .= "/".$objectref; - } + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; @@ -276,2 +265,4 @@ - if (!file_exists($dir)) { - if (dol_mkdir($dir) < 0) { + if (!file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { @@ -283 +274,2 @@ - if (file_exists($dir)) { + if (file_exists($dir)) + { @@ -286 +278 @@ - $newfiletmp = preg_replace('/\.od[ts]/i', '', $newfile); + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); @@ -290 +282 @@ - $newfiletmp = $objectref . '_' . $newfiletmp; + $newfiletmp = $objectref.'_'.$newfiletmp; @@ -294,10 +286,11 @@ - if (getDolGlobalString('MAIN_DOC_USE_TIMING')) { - $format = getDolGlobalString('MAIN_DOC_USE_TIMING'); - if ($format == '1') { - $format = '%Y%m%d%H%M%S'; - } - $filename = $newfiletmp . '-' . dol_print_date(dol_now(), $format) . '.' . $newfileformat; - } else { - $filename = $newfiletmp . '.' . $newfileformat; - } - $file = $dir . '/' . $filename; + 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'; + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; + } + else + { + $filename = $newfiletmp.'.'.$newfileformat; + } + $file = $dir.'/'.$filename; @@ -310,5 +303 @@ - if (!is_writable($conf->user->dir_temp)) { - $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->user->dir_temp); - dol_syslog('Error in write_file: ' . $this->error, LOG_ERR); - return -1; - } + @@ -319 +308,2 @@ - if (count($arrayidcontact) > 0) { + if (count($arrayidcontact) > 0) + { @@ -325,9 +315,12 @@ - if (!empty($usecontact)) { - if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('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 { + if (!empty($usecontact)) + { + // 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 + { @@ -340 +333 @@ - $odfHandler = new Odf( + $odfHandler = new odf( @@ -349 +342,3 @@ - } catch (Exception $e) { + } + catch (Exception $e) + { @@ -362,3 +357 @@ - if ($usecontact && is_object($contactobject)) { - $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); - } + if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); @@ -372 +365,2 @@ - foreach ($tmparray as $key => $value) { + foreach ($tmparray as $key=>$value) + { @@ -374,7 +368,7 @@ - if (preg_match('/logo$/', $key)) { // Image - if (file_exists($value)) { - $odfHandler->setImage($key, $value); - } else { - $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - } else { // Text + if (preg_match('/logo$/', $key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { @@ -383 +377,3 @@ - } catch (OdfException $e) { + } + catch (OdfException $e) + { @@ -390 +386,2 @@ - foreach ($tmparray as $key => $value) { + foreach ($tmparray as $key=>$value) + { @@ -393 +390,3 @@ - } catch (OdfException $e) { + } + catch (OdfException $e) + { @@ -403 +402 @@ - if (getDolGlobalString('MAIN_ODT_AS_PDF')) { + if (!empty($conf->global->MAIN_ODT_AS_PDF)) { @@ -411 +410,2 @@ - } else { + } + else { @@ -423 +423,2 @@ - dolChmod($file); + if (!empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); @@ -430 +431,3 @@ - } else { + } + else + { @@ -439,12 +442,12 @@ - // 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