106 $langs->loadLangs(array(
"errors",
"companies"));
108 $form =
new Form($this->db);
114 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
115 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
116 $texte .=
'<input type="hidden" name="page_y" value="">';
117 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
118 $texte .=
'<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">';
120 $texte .=
'<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">';
121 $texte .=
'<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">';
122 $texte .=
'<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">';
124 $texte .=
'<table class="nobordernopadding centpercent">';
127 $texte .=
'<tr><td>';
128 $texttitle = $langs->trans(
"ListOfDirectories");
129 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
130 $listoffiles = array();
131 foreach ($listofdir as $key => $tmpdir) {
132 $tmpdir = trim($tmpdir);
133 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
135 unset($listofdir[$key]);
138 if (!is_dir($tmpdir)) {
139 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
141 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
142 if (count($tmpfiles)) {
143 $listoffiles = array_merge($listoffiles, $tmpfiles);
147 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
148 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
150 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
151 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
153 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
154 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
155 $texte .=
'<textarea class="flat" cols="60" name="value1">';
157 $texte .=
'</textarea>';
158 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
159 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
160 $texte .=
'<br></div></div>';
163 $nbofiles = count($listoffiles);
164 if (!empty($odtPath)) {
165 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
167 $texte .= count($listoffiles);
173 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
175 foreach ($listoffiles as $file) {
176 $texte .=
'- '.$file[
'name'];
177 $texte .=
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=proposals/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
178 $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>';
187 $texte .=
'<table width="50%">';
189 $texte .=
'<td width="60%">'.$langs->trans(
"DefaultModelPropalCreate").
'</td>';
190 $texte .=
'<td colspan="">';
191 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_DEFAULT'));
192 $texte .=
"</td></tr>";
195 $texte .=
'<td width="60%">'.$langs->trans(
"DefaultModelPropalToBill").
'</td>';
196 $texte .=
'<td colspan="">';
197 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_TOBILL'));
198 $texte .=
"</td></tr>";
201 $texte .=
'<td width="60%">'.$langs->trans(
"DefaultModelPropalClosed").
'</td>';
202 $texte .=
'<td colspan="">';
203 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_CLOSED'));
204 $texte .=
"</td></tr>";
205 $texte .=
'</table>';
209 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
211 $maxmin = $maxfilesizearray[
'maxmin'];
213 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
215 $texte .=
' <input type="file" name="uploadfile">';
216 $texte .=
'<input type="hidden" value="PROPALE_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
217 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
223 $texte .=
'</table>';
241 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
244 global $user, $langs, $conf, $mysoc, $hookmanager;
246 if (empty($srctemplatepath)) {
247 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
252 if (!is_object($hookmanager)) {
253 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
256 $hookmanager->initHooks(array(
'odtgeneration'));
259 if (!is_object($outputlangs)) {
260 $outputlangs = $langs;
262 $sav_charset_output = $outputlangs->charset_output;
263 $outputlangs->charset_output =
'UTF-8';
266 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
268 if ($conf->propal->multidir_output[$conf->entity]) {
282 $dir = $conf->propal->multidir_output[
$object->entity];
284 if (!preg_match(
'/specimen/i', $objectref)) {
285 $dir .=
"/".$objectref;
287 $file = $dir.
"/".$objectref.
".odt";
289 if (!file_exists($dir)) {
291 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
296 if (file_exists($dir)) {
298 $newfile = basename($srctemplatepath);
299 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
300 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
301 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
303 $newfiletmp = $objectref .
'_' . $newfiletmp;
306 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
309 if ($format ==
'1') {
310 $format =
'%Y%m%d%H%M%S';
314 $filename = $newfiletmp .
'.' . $newfileformat;
316 $file = $dir .
'/' . $filename;
323 if (!is_writable($conf->propal->dir_temp)) {
324 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->propal->dir_temp);
325 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
331 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
332 if (count($arrayidcontact) > 0) {
334 $result =
$object->fetch_contact($arrayidcontact[0]);
338 $contactobject =
null;
339 if (!empty($usecontact)) {
341 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
342 $object->contact->fetch_thirdparty();
343 $socobject =
$object->contact->thirdparty;
344 $contactobject =
$object->contact;
346 $socobject =
$object->thirdparty;
348 $contactobject =
$object->contact;
351 $socobject =
$object->thirdparty;
354 $substitutionarray = array(
355 '__FROM_NAME__' => $this->emetteur->name,
356 '__FROM_EMAIL__' => $this->emetteur->email,
357 '__TOTAL_TTC__' =>
$object->total_ttc,
358 '__TOTAL_HT__' =>
$object->total_ht,
359 '__TOTAL_VAT__' =>
$object->total_tva
363 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
364 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
368 $paramfreetext =
'PROPOSAL_FREE_TEXT';
374 require_once ODTPHP_PATH.
'odf.php';
376 $odfHandler =
new Odf(
379 'PATH_TO_TMP' => $conf->propal->multidir_temp[
$object->entity],
380 'ZIP_PROXY' =>
'PclZipProxy',
381 'DELIMITER_LEFT' =>
'{',
382 'DELIMITER_RIGHT' =>
'}'
386 $this->error = $e->getMessage();
400 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
401 }
catch (OdfException $e) {
408 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
414 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
417 $companybankaccount->fetch(0,
'',
$object->thirdparty->id);
418 $array_objet[
'company_default_bank_iban'] = $companybankaccount->iban;
419 $array_objet[
'company_default_bank_bic'] = $companybankaccount->bic;
422 $array_thirdparty_contact = array();
423 if ($usecontact && is_object($contactobject)) {
427 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
431 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
432 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
434 foreach ($tmparray as $key => $value) {
436 if (preg_match(
'/logo$/', $key)) {
437 if (file_exists($value)) {
438 $odfHandler->setImage($key, $value);
440 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
443 $odfHandler->setVars($key, $value,
true,
'UTF-8');
445 }
catch (OdfException $e) {
450 $foundtagforlines = 1;
452 $listlines = $odfHandler->setSegment(
'lines');
453 }
catch (OdfExceptionSegmentNotFound $e) {
455 $foundtagforlines = 0;
458 if ($foundtagforlines) {
460 foreach (
$object->lines as $line) {
465 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
466 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
467 foreach ($tmparray as $key => $val) {
469 $listlines->setVars($key, $val,
true,
'UTF-8');
470 }
catch (SegmentException $e) {
477 $odfHandler->mergeSegment($listlines);
478 }
catch (OdfException $e) {
479 $this->error = $e->getMessage();
486 $tmparray = $outputlangs->get_translations_for_substitutions();
487 foreach ($tmparray as $key => $value) {
489 $odfHandler->setVars($key, $value,
true,
'UTF-8');
490 }
catch (OdfException $e) {
496 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
497 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
502 $odfHandler->exportAsAttachedPDF($file);
504 $this->error = $e->getMessage();
510 $odfHandler->saveToDisk($file);
512 $this->error = $e->getMessage();
517 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
518 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
524 $this->result = array(
'fullpath' => $file);
528 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);