121 $langs->loadLangs(array(
"errors",
"companies"));
123 $form =
new Form($this->db);
126 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
127 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
128 $texte .=
'<input type="hidden" name="page_y" value="">';
129 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
130 $texte .=
'<input type="hidden" name="param1" value="ASSET_ASSET_ADDON_PDF_ODT_PATH">';
131 $texte .=
'<table class="nobordernopadding centpercent">';
134 $texte .=
'<tr><td>';
135 $texttitle = $langs->trans(
"ListOfDirectories");
136 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'ASSET_ASSET_ADDON_PDF_ODT_PATH'))));
137 $listoffiles = array();
138 foreach ($listofdir as $key => $tmpdir) {
139 $tmpdir = trim($tmpdir);
140 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
142 unset($listofdir[$key]);
145 if (!is_dir($tmpdir)) {
146 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
148 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
149 if (count($tmpfiles)) {
150 $listoffiles = array_merge($listoffiles, $tmpfiles);
154 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
155 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
157 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
158 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
161 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
162 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
163 $texte .=
'<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
165 $texte .=
'</textarea>';
166 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
167 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dolPrintHTMLForAttribute($langs->trans(
"Modify")).
'">';
168 $texte .=
'<br></div></div>';
171 $texte .=
'<input type="hidden" name="value1" value="ASSET_ASSET_ADDON_PDF_ODT_PATH">';
175 $nbofiles = count($listoffiles);
177 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
179 $texte .= count($listoffiles);
185 $texte .=
'<div id="div_'.get_class($this).
'" class="hidden">';
187 foreach ($listoffiles as $file) {
188 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=asset_asset/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
189 $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>';
196 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
198 $maxmin = $maxfilesizearray[
'maxmin'];
200 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
202 $texte .=
' <input type="file" name="uploadfile">';
203 $texte .=
'<input type="hidden" value="MYMODULE_MYOBJECT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
204 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
211 $texte .=
'</table>';
229 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
232 global $user, $langs, $conf,
$mysoc, $hookmanager;
235 if (empty($srctemplatepath)) {
236 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
241 if (!is_object($hookmanager)) {
242 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
245 $hookmanager->initHooks(array(
'odtgeneration'));
248 if (!is_object($outputlangs)) {
249 $outputlangs = $langs;
251 $sav_charset_output = $outputlangs->charset_output;
252 $outputlangs->charset_output =
'UTF-8';
254 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
256 if ($conf->asset->dir_output) {
270 $dir = $conf->asset->multidir_output[isset(
$object->entity) ?
$object->entity : 1];
272 if (!preg_match(
'/specimen/i', $objectref)) {
273 $dir .=
"/".$objectref;
275 $file = $dir.
"/".$objectref.
".odt";
277 if (!file_exists($dir)) {
279 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
284 if (file_exists($dir)) {
286 $newfile = basename($srctemplatepath);
287 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
288 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
289 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
290 $newfiletmp = $objectref.
'_'.$newfiletmp;
293 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
296 if ($format ==
'1') {
297 $format =
'%Y%m%d%H%M%S';
301 $filename = $newfiletmp.
'.'.$newfileformat;
303 $file = $dir.
'/'.$filename;
310 if (!is_writable($conf->asset->dir_temp)) {
311 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->asset->dir_temp);
312 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
318 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
319 if (count($arrayidcontact) > 0) {
321 $result =
$object->fetch_contact($arrayidcontact[0]);
325 $contactobject =
null;
326 if (!empty($usecontact)) {
328 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
329 $object->contact->fetch_thirdparty();
330 $socobject =
$object->contact->thirdparty;
331 $contactobject =
$object->contact;
333 $socobject =
$object->thirdparty;
335 $contactobject =
$object->contact;
338 $socobject =
$object->thirdparty;
342 $substitutionarray = array(
343 '__FROM_NAME__' => $this->emetteur->name,
344 '__FROM_EMAIL__' => $this->emetteur->email,
345 '__TOTAL_TTC__' =>
$object->total_ttc,
346 '__TOTAL_HT__' =>
$object->total_ht,
347 '__TOTAL_VAT__' =>
$object->total_tva
351 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
352 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
356 $paramfreetext =
'ORDER_FREE_TEXT';
362 require_once ODTPHP_PATH.
'odf.php';
364 $odfHandler =
new Odf(
367 'PATH_TO_TMP' => $conf->asset->dir_temp,
369 'DELIMITER_LEFT' =>
'{',
370 'DELIMITER_RIGHT' =>
'}'
374 $this->error = $e->getMessage();
384 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
385 }
catch (OdfException $e) {
390 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null,
$object);
392 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
398 $array_thirdparty_contact = array();
399 if ($usecontact && is_object($contactobject)) {
403 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
407 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
408 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
417 foreach ($tmparray as $key => $value) {
419 if (preg_match(
'/logo$/', $key)) {
421 if (file_exists($value)) {
422 $odfHandler->setImage($key, $value, $ratio);
424 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
428 $odfHandler->setVars($key, $value,
true,
'UTF-8');
430 }
catch (OdfException $e) {
472 $tmparray = $outputlangs->get_translations_for_substitutions();
473 foreach ($tmparray as $key => $value) {
475 $odfHandler->setVars($key, $value,
true,
'UTF-8');
476 }
catch (OdfException $e) {
483 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
484 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
489 $odfHandler->exportAsAttachedPDF($file);
491 $this->error = $e->getMessage();
497 $odfHandler->saveToDisk($file);
499 $this->error = $e->getMessage();
505 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
506 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
512 $this->result = array(
'fullpath' => $file);
516 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);