111 $langs->loadLangs(array(
"errors",
"companies"));
113 $form =
new Form($this->db);
119 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
120 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
121 $texte .=
'<input type="hidden" name="page_y" value="">';
122 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
123 $texte .=
'<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">';
125 $texte .=
'<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">';
126 $texte .=
'<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">';
127 $texte .=
'<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">';
129 $texte .=
'<table class="nobordernopadding centpercent">';
132 $texte .=
'<tr><td>';
133 $texttitle = $langs->trans(
"ListOfDirectories");
134 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
135 $listoffiles = array();
136 foreach ($listofdir as $key => $tmpdir) {
137 $tmpdir = trim($tmpdir);
138 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
140 unset($listofdir[$key]);
143 if (!is_dir($tmpdir)) {
144 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
146 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
147 if (count($tmpfiles)) {
148 $listoffiles = array_merge($listoffiles, $tmpfiles);
152 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
153 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
155 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
156 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
158 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
159 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
160 $texte .=
'<textarea class="flat" cols="60" name="value1">';
162 $texte .=
'</textarea>';
163 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
164 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
165 $texte .=
'<br></div></div>';
168 $nbofiles = count($listoffiles);
169 if (!empty($odtPath)) {
170 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
172 $texte .= count($listoffiles);
178 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
180 foreach ($listoffiles as $file) {
181 $texte .=
'- '.$file[
'name'];
182 $texte .=
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=proposals/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
183 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=PROPALE_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
192 $texte .=
'<table width="50%">';
194 $texte .=
'<td width="60%">'.$langs->trans(
"DefaultModelPropalCreate").
'</td>';
195 $texte .=
'<td colspan="">';
196 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_DEFAULT'));
197 $texte .=
"</td></tr>";
200 $texte .=
'<td width="60%">'.$langs->trans(
"DefaultModelPropalToBill").
'</td>';
201 $texte .=
'<td colspan="">';
202 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_TOBILL'));
203 $texte .=
"</td></tr>";
206 $texte .=
'<td width="60%">'.$langs->trans(
"DefaultModelPropalClosed").
'</td>';
207 $texte .=
'<td colspan="">';
208 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_CLOSED'));
209 $texte .=
"</td></tr>";
210 $texte .=
'</table>';
214 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
216 $maxmin = $maxfilesizearray[
'maxmin'];
218 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
220 $texte .=
' <input type="file" name="uploadfile">';
221 $texte .=
'<input type="hidden" value="PROPALE_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
222 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
228 $texte .=
'</table>';
246 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
249 global $user, $langs,
$conf, $mysoc, $hookmanager;
251 if (empty($srctemplatepath)) {
252 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
257 if (!is_object($hookmanager)) {
258 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
261 $hookmanager->initHooks(array(
'odtgeneration'));
264 if (!is_object($outputlangs)) {
265 $outputlangs = $langs;
267 $sav_charset_output = $outputlangs->charset_output;
268 $outputlangs->charset_output =
'UTF-8';
271 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
273 if (
$conf->propal->multidir_output[
$conf->entity]) {
289 if (!preg_match(
'/specimen/i', $objectref)) {
290 $dir .=
"/".$objectref;
292 $file = $dir.
"/".$objectref.
".odt";
294 if (!file_exists($dir)) {
296 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
301 if (file_exists($dir)) {
303 $newfile = basename($srctemplatepath);
304 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
305 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
306 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
308 $newfiletmp = $objectref .
'_' . $newfiletmp;
311 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
314 if ($format ==
'1') {
315 $format =
'%Y%m%d%H%M%S';
319 $filename = $newfiletmp .
'.' . $newfileformat;
321 $file = $dir .
'/' . $filename;
328 if (!is_writable(
$conf->propal->dir_temp)) {
329 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->propal->dir_temp);
330 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
336 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
337 if (count($arrayidcontact) > 0) {
339 $result =
$object->fetch_contact($arrayidcontact[0]);
343 $contactobject =
null;
344 if (!empty($usecontact)) {
347 $object->contact->fetch_thirdparty();
348 $socobject =
$object->contact->thirdparty;
349 $contactobject =
$object->contact;
351 $socobject =
$object->thirdparty;
353 $contactobject =
$object->contact;
356 $socobject =
$object->thirdparty;
359 $substitutionarray = array(
360 '__FROM_NAME__' => $this->emetteur->name,
361 '__FROM_EMAIL__' => $this->emetteur->email,
362 '__TOTAL_TTC__' =>
$object->total_ttc,
363 '__TOTAL_HT__' =>
$object->total_ht,
364 '__TOTAL_VAT__' =>
$object->total_tva
368 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
369 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
373 $paramfreetext =
'PROPOSAL_FREE_TEXT';
379 require_once ODTPHP_PATH.
'odf.php';
381 $odfHandler =
new Odf(
384 'PATH_TO_TMP' =>
$conf->propal->multidir_temp[
$object->entity],
386 'DELIMITER_LEFT' =>
'{',
387 'DELIMITER_RIGHT' =>
'}'
391 $this->error = $e->getMessage();
405 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
406 }
catch (OdfException $e) {
413 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
419 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
422 $companybankaccount->fetch(0,
'',
$object->thirdparty->id);
423 $array_objet[
'company_default_bank_iban'] = $companybankaccount->iban;
424 $array_objet[
'company_default_bank_bic'] = $companybankaccount->bic;
427 $array_thirdparty_contact = array();
428 if ($usecontact && is_object($contactobject)) {
432 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
436 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
437 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
439 foreach ($tmparray as $key => $value) {
441 if (preg_match(
'/logo$/', $key)) {
442 if (file_exists($value)) {
443 $odfHandler->setImage($key, $value);
445 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
448 $odfHandler->setVars($key, $value,
true,
'UTF-8');
450 }
catch (OdfException $e) {
455 $foundtagforlines = 1;
457 $listlines = $odfHandler->setSegment(
'lines');
458 }
catch (OdfExceptionSegmentNotFound $e) {
460 $foundtagforlines = 0;
463 if ($foundtagforlines) {
465 foreach (
$object->lines as $line) {
470 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
471 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
472 foreach ($tmparray as $key => $val) {
474 $listlines->setVars($key, $val,
true,
'UTF-8');
475 }
catch (SegmentException $e) {
482 $odfHandler->mergeSegment($listlines);
483 }
catch (OdfException $e) {
484 $this->error = $e->getMessage();
491 $tmparray = $outputlangs->get_translations_for_substitutions();
492 foreach ($tmparray as $key => $value) {
494 $odfHandler->setVars($key, $value,
true,
'UTF-8');
495 }
catch (OdfException $e) {
501 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
502 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
507 $odfHandler->exportAsAttachedPDF($file);
509 $this->error = $e->getMessage();
515 $odfHandler->saveToDisk($file);
517 $this->error = $e->getMessage();
522 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
523 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
529 $this->result = array(
'fullpath' => $file);
533 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);