--- /tmp/dsg/dolibarr/htdocs/core/modules/societe/doc/github_19.0.3_doc_generic_odt.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/societe/doc/client_doc_generic_odt.modules.php @@ -40 +40,2 @@ - * @var string Dolibarr version of the loaded document + * Issuer + * @var Societe @@ -42 +43,7 @@ - public $version = 'dolibarr'; + public $emetteur; + + /** + * @var array Minimum version of PHP required by module. + * e.g.: PHP ≥ 5.5 = array(5, 5) + */ + public $phpmin = array(5, 5); @@ -52 +59 @@ - global $langs, $mysoc; + global $conf, $langs, $mysoc; @@ -55 +62 @@ - $langs->loadLangs(array("main", "companies")); + $langs->loadLangs(array("main", "companies")); @@ -72 +79 @@ - $this->option_logo = 1; // Display logo + $this->option_logo = 1; // Affiche logo @@ -76,3 +83 @@ - if (!$this->emetteur->country_code) { - $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined - } + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // Par defaut, si n'etait pas defini @@ -98 +102,0 @@ - $texte .= ''; @@ -101 +104,0 @@ - $texte .= ''; @@ -104 +107 @@ - $texte .= ''; + $texte .= '
'; @@ -111 +114,2 @@ - foreach ($listofdir as $key => $tmpdir) { + foreach ($listofdir as $key=>$tmpdir) + { @@ -114,7 +118,4 @@ - if (!$tmpdir) { - unset($listofdir[$key]); - continue; - } - if (!is_dir($tmpdir)) { - $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); - } else { + if (!$tmpdir) { unset($listofdir[$key]); continue; } + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); + else + { @@ -122,3 +123 @@ - if (count($tmpfiles)) { - $listoffiles = array_merge($listoffiles, $tmpfiles); - } + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); @@ -128 +126,0 @@ - $texthelp .= '

'.$langs->trans("ExampleOfDirectoriesForModelGen").''; @@ -133,2 +131,2 @@ - $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1, 3, $this->name); - $texte .= '
'; + $texte .= ''; + $texte .= ''; + $texte .= '
'; + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); + $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= '
'; @@ -136 +134 @@ - $texte .= getDolGlobalString('COMPANY_ADDON_PDF_ODT_PATH'); + $texte .= $conf->global->COMPANY_ADDON_PDF_ODT_PATH; @@ -138,6 +136,6 @@ - $texte .= '  '; - $texte .= ''; - $texte .= '
'; + $texte .= '
  '; + $texte .= ''; + $texte .= '
'; @@ -147 +145,2 @@ - if (getDolGlobalString('COMPANY_ADDON_PDF_ODT_PATH')) { + if (!empty($conf->global->COMPANY_ADDON_PDF_ODT_PATH)) + { @@ -155,9 +154,8 @@ - if ($nbofiles) { - $texte .= '
'; - // Show list of found files - foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].'   '.img_picto('', 'listlight').''; - $texte .= '   '.img_picto('', 'delete').''; - $texte .= '
'; - } - $texte .= '
'; + if ($nbofiles) + { + $texte .= ''; @@ -165,11 +163,5 @@ - // 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 .= '
'; + // Add input to upload a new template file. + $texte .= '
'.$langs->trans("UploadNewTemplate").' '; + $texte .= ''; + $texte .= ''; + $texte .= '
'; @@ -177,0 +170,3 @@ + $texte .= ''; + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); + $texte .= ''; @@ -186 +181 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -193,3 +188,3 @@ - * @param int $hidedetails Do not show line details - * @param int $hidedesc Do not show desc - * @param int $hideref Do not show ref + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref @@ -200,5 +195,5 @@ - // phpcs:enable - global $user, $langs, $conf, $mysoc, $hookmanager; - global $action; - - if (empty($srctemplatepath)) { + // phpcs:enable + global $user, $langs, $conf, $mysoc, $hookmanager; + + if (empty($srctemplatepath)) + { @@ -209,10 +204,9 @@ - // Add odtgeneration hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('odtgeneration')); - - if (!is_object($outputlangs)) { - $outputlangs = $langs; - } + // Add odtgeneration hook + if (!is_object($hookmanager)) { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($this->db); + } + $hookmanager->initHooks(array('odtgeneration')); + global $action; + + if (!is_object($outputlangs)) $outputlangs = $langs; @@ -225 +219,2 @@ - if ($conf->societe->multidir_output[$object->entity]) { + if ($conf->societe->multidir_output[$object->entity]) + { @@ -228,6 +223,6 @@ - if (!preg_match('/specimen/i', $objectref)) { - $dir .= "/".$objectref; - } - - if (!file_exists($dir)) { - if (dol_mkdir($dir) < 0) { + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; + + if (!file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { @@ -239 +234,2 @@ - if (file_exists($dir)) { + if (file_exists($dir)) + { @@ -247,14 +243,15 @@ - if (getDolGlobalString('MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME')) { - $newfiletmp = dol_sanitizeFileName(dol_string_nospecial($object->name)) . '-' . $newfiletmp; - $newfiletmp = preg_replace('/__+/', '_', $newfiletmp); // Replace repeated _ into one _ (to avoid string with substitution syntax) - } - 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_OBJECT_THIRDPARTY_NAME)) + { + $newfiletmp = dol_sanitizeFileName(dol_string_nospecial($object->name)).'-'.$newfiletmp; + } + 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; @@ -270,5 +266,0 @@ - if (!is_writable($conf->societe->multidir_temp[$object->entity])) { - $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->societe->multidir_temp[$object->entity]); - dol_syslog('Error in write_file: ' . $this->error, LOG_ERR); - return -1; - } @@ -279,7 +271,7 @@ - $odfHandler = new Odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' @@ -288 +280,3 @@ - } catch (Exception $e) { + } + catch (Exception $e) + { @@ -295,24 +289,78 @@ - // Replace tags of lines for contacts - $contact_arrray = array(); - - $sql = "SELECT p.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; - $sql .= " WHERE p.fk_soc = ".((int) $object->id); - - $result = $this->db->query($sql); - $num = $this->db->num_rows($result); - - if ($num) { - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - - $i = 0; - $contactstatic = new Contact($this->db); - - while ($i < $num) { - $obj = $this->db->fetch_object($result); - - $contact_arrray[$i] = $obj->rowid; - $i++; - } - } - if ((is_array($contact_arrray) && count($contact_arrray) > 0)) { + // Replace tags of lines for contacts + $contact_arrray = array(); + + $sql = "SELECT p.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; + $sql .= " WHERE p.fk_soc = ".$object->id; + + $result = $this->db->query($sql); + $num = $this->db->num_rows($result); + + if ($num) + { + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + + $i = 0; + $contactstatic = new Contact($this->db); + + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + + $contact_arrray[$i] = $obj->rowid; + $i++; + } + } + if ((is_array($contact_arrray) && count($contact_arrray) > 0)) + { + try + { + $listlines = $odfHandler->setSegment('companycontacts'); + + foreach ($contact_arrray as $array_key => $contact_id) + { + $res_contact = $contactstatic->fetch($contact_id); + $tmparray = $this->get_substitutionarray_contact($contactstatic, $outputlangs, 'contact'); + foreach ($tmparray as $key => $val) + { + try + { + $listlines->setVars($key, $val, true, 'UTF-8'); + } + catch (OdfException $e) + { + dol_syslog($e->getMessage(), LOG_INFO); + } + catch (SegmentException $e) + { + dol_syslog($e->getMessage(), LOG_INFO); + } + } + $listlines->merge(); + } + $odfHandler->mergeSegment($listlines); + } + catch (OdfException $e) + { + $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + //return -1; + } + } + + // Make substitutions into odt + $array_user = $this->get_substitutionarray_user($user, $outputlangs); + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); + $array_thirdparty = $this->get_substitutionarray_thirdparty($object, $outputlangs); + $array_other = $this->get_substitutionarray_other($outputlangs); + + $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other); + complete_substitutions_array($tmparray, $outputlangs, $object); + + // Call the ODTSubstitution hook + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + + // Replace variables into document + foreach ($tmparray as $key=>$value) + { @@ -320,20 +368,4 @@ - $listlines = $odfHandler->setSegment('companycontacts'); - - foreach ($contact_arrray as $array_key => $contact_id) { - $res_contact = $contactstatic->fetch($contact_id); - if ((int) $res_contact > 0) { - $tmparray = $this->get_substitutionarray_contact($contactstatic, $outputlangs, 'contact'); - foreach ($tmparray as $key => $val) { - try { - $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } - } - $listlines->merge(); - } else { - $this->error = $contactstatic->error; - dol_syslog($this->error, LOG_WARNING); - } + if (preg_match('/logo$/', $key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); @@ -341,32 +373,2 @@ - $odfHandler->mergeSegment($listlines); - } catch (OdfException $e) { - $this->error = $e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - //return -1; - } - } - - // Make substitutions into odt - $array_user = $this->get_substitutionarray_user($user, $outputlangs); - $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); - $array_thirdparty = $this->get_substitutionarray_thirdparty($object, $outputlangs); - $array_other = $this->get_substitutionarray_other($outputlangs); - - $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other); - - complete_substitutions_array($tmparray, $outputlangs, $object); - - // Call the ODTSubstitution hook - $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); - $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - - // Replace variables into document - foreach ($tmparray as $key => $value) { - try { - if (preg_match('/logo$/', $key)) { // Image - if (file_exists($value)) { - $odfHandler->setImage($key, $value); - } else { - $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - } else { // Text + else // Text + { @@ -375 +377,3 @@ - } catch (OdfException $e) { + } + catch (OdfException $e) + { @@ -377 +381 @@ - dol_syslog($e->getMessage(), LOG_INFO); + dol_syslog($e->getMessage(), LOG_INFO); @@ -383 +387,2 @@ - foreach ($tmparray as $key => $value) { + foreach ($tmparray as $key=>$value) + { @@ -386,2 +391,4 @@ - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); + } + catch (OdfException $e) + { + dol_syslog($e->getMessage(), LOG_INFO); @@ -396 +403 @@ - if (getDolGlobalString('MAIN_ODT_AS_PDF')) { + if (!empty($conf->global->MAIN_ODT_AS_PDF)) { @@ -401 +408 @@ - dol_syslog($e->getMessage(), LOG_INFO); + dol_syslog($e->getMessage(), LOG_INFO); @@ -404,12 +411,13 @@ - } else { - try { - $odfHandler->creator = $user->getFullName($outputlangs); - $odfHandler->title = $object->builddoc_filename; - $odfHandler->subject = $object->builddoc_filename; - - if (getDolGlobalString('ODT_ADD_DOLIBARR_ID')) { - $odfHandler->userdefined['dol_id'] = $object->id; - $odfHandler->userdefined['dol_element'] = $object->element; - } - - $odfHandler->saveToDisk($file); + } + else { + try { + $odfHandler->creator = $user->getFullName($outputlangs); + $odfHandler->title = $object->builddoc_filename; + $odfHandler->subject = $object->builddoc_filename; + + if (!empty($conf->global->ODT_ADD_DOLIBARR_ID)) { + $odfHandler->userdefined['dol_id'] = $object->id; + $odfHandler->userdefined['dol_element'] = $object->element; + } + + $odfHandler->saveToDisk($file); @@ -418 +426 @@ - dol_syslog($e->getMessage(), LOG_INFO); + dol_syslog($e->getMessage(), LOG_INFO); @@ -425 +433,2 @@ - dolChmod($file); + if (!empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); @@ -432 +441,3 @@ - } else { + } + else + {