99 public function info($langs)
101 global $conf, $langs;
104 $langs->loadLangs(array(
"errors",
"companies"));
106 $form =
new Form($this->db);
109 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
110 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
111 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
112 $texte .=
'<input type="hidden" name="param1" value="ASSET_ASSET_ADDON_PDF_ODT_PATH">';
113 $texte .=
'<table class="nobordernopadding" width="100%">';
116 $texte .=
'<tr><td>';
117 $texttitle = $langs->trans(
"ListOfDirectories");
118 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->ASSET_ASSET_ADDON_PDF_ODT_PATH)));
119 $listoffiles = array();
120 foreach ($listofdir as $key => $tmpdir) {
121 $tmpdir = trim($tmpdir);
122 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
124 unset($listofdir[$key]);
127 if (!is_dir($tmpdir)) {
128 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
130 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
131 if (count($tmpfiles)) {
132 $listoffiles = array_merge($listoffiles, $tmpfiles);
136 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
137 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
139 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
140 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
143 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
144 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
145 $texte .=
'<textarea class="flat" cols="60" name="value1">';
147 $texte .=
'</textarea>';
148 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
149 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="'.$langs->trans(
"Modify").
'">';
150 $texte .=
'<br></div></div>';
153 $texte .=
'<input type="hidden" name="value1" value="ASSET_ASSET_ADDON_PDF_ODT_PATH">';
157 $nbofiles = count($listoffiles);
159 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
161 $texte .= count($listoffiles);
167 $texte .=
'<div id="div_'.get_class($this).
'" class="hidden">';
168 foreach ($listoffiles as $file) {
169 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=asset_asset/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
170 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=ASSET_ASSET_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
180 $texte .=
'</table>';
198 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
201 global $user, $langs, $conf, $mysoc, $hookmanager;
203 if (empty($srctemplatepath)) {
204 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
209 if (!is_object($hookmanager)) {
210 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
213 $hookmanager->initHooks(array(
'odtgeneration'));
216 if (!is_object($outputlangs)) {
217 $outputlangs = $langs;
219 $sav_charset_output = $outputlangs->charset_output;
220 $outputlangs->charset_output =
'UTF-8';
222 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
224 if ($conf->asset->dir_output) {
238 $dir = $conf->asset->multidir_output[isset(
$object->entity) ?
$object->entity : 1];
240 if (!preg_match(
'/specimen/i', $objectref)) {
241 $dir .=
"/".$objectref;
243 $file = $dir.
"/".$objectref.
".odt";
245 if (!file_exists($dir)) {
247 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
252 if (file_exists($dir)) {
254 $newfile = basename($srctemplatepath);
255 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
256 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
257 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
258 $newfiletmp = $objectref.
'_'.$newfiletmp;
261 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
264 if ($format ==
'1') {
265 $format =
'%Y%m%d%H%M%S';
269 $filename = $newfiletmp.
'.'.$newfileformat;
271 $file = $dir.
'/'.$filename;
278 if (!is_writable($conf->asset->dir_temp)) {
279 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->asset->dir_temp);
280 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
286 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
287 if (count($arrayidcontact) > 0) {
289 $result =
$object->fetch_contact($arrayidcontact[0]);
293 $contactobject =
null;
294 if (!empty($usecontact)) {
296 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
297 $object->contact->fetch_thirdparty();
298 $socobject =
$object->contact->thirdparty;
299 $contactobject =
$object->contact;
301 $socobject =
$object->thirdparty;
303 $contactobject =
$object->contact;
306 $socobject =
$object->thirdparty;
310 $substitutionarray = array(
311 '__FROM_NAME__' => $this->emetteur->name,
312 '__FROM_EMAIL__' => $this->emetteur->email,
313 '__TOTAL_TTC__' =>
$object->total_ttc,
314 '__TOTAL_HT__' =>
$object->total_ht,
315 '__TOTAL_VAT__' =>
$object->total_tva
319 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
320 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
324 $paramfreetext =
'ORDER_FREE_TEXT';
325 if (!empty($conf->global->$paramfreetext)) {
330 require_once ODTPHP_PATH.
'odf.php';
332 $odfHandler =
new Odf(
335 'PATH_TO_TMP' => $conf->asset->dir_temp,
337 'DELIMITER_LEFT' =>
'{',
338 'DELIMITER_RIGHT' =>
'}'
342 $this->error = $e->getMessage();
352 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
353 }
catch (OdfException $e) {
360 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
366 $array_thirdparty_contact = array();
367 if ($usecontact && is_object($contactobject)) {
371 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
375 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
376 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
378 foreach ($tmparray as $key => $value) {
380 if (preg_match(
'/logo$/', $key)) {
382 if (file_exists($value)) {
383 $odfHandler->setImage($key, $value);
385 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
389 $odfHandler->setVars($key, $value,
true,
'UTF-8');
391 }
catch (OdfException $e) {
433 $tmparray = $outputlangs->get_translations_for_substitutions();
434 foreach ($tmparray as $key => $value) {
436 $odfHandler->setVars($key, $value,
true,
'UTF-8');
437 }
catch (OdfException $e) {
444 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
445 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
450 $odfHandler->exportAsAttachedPDF($file);
452 $this->error = $e->getMessage();
458 $odfHandler->saveToDisk($file);
460 $this->error = $e->getMessage();
466 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
467 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
473 $this->result = array(
'fullpath'=>$file);
477 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);