110 $langs->loadLangs(array(
'companies',
'errors'));
112 $form =
new Form($this->db);
114 $odtChosen =
getDolGlobalInt(
'MAIN_SUPPLIER_PROPOSAL_CHOOSE_ODT_DOCUMENT') > 0;
118 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
119 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
120 $texte .=
'<input type="hidden" name="page_y" value="">';
121 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
122 $texte .=
'<input type="hidden" name="param1" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH">';
124 $texte .=
'<input type="hidden" name="param2" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT">';
125 $texte .=
'<input type="hidden" name="param3" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL">';
126 $texte .=
'<input type="hidden" name="param4" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED">';
128 $texte .=
'<table class="nobordernopadding" width="100%">';
131 $texte .=
'<tr><td>';
132 $texttitle = $langs->trans(
"ListOfDirectories");
133 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
134 $listoffiles = array();
135 foreach ($listofdir as $key => $tmpdir) {
136 $tmpdir = trim($tmpdir);
137 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
139 unset($listofdir[$key]);
142 if (!is_dir($tmpdir)) {
143 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
145 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
146 if (count($tmpfiles)) {
147 $listoffiles = array_merge($listoffiles, $tmpfiles);
151 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
152 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
154 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
155 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
157 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
158 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
159 $texte .=
'<textarea class="flat" cols="60" name="value1">';
161 $texte .=
'</textarea>';
162 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
163 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
164 $texte .=
'<br></div></div>';
167 $nbofiles = count($listoffiles);
168 if (!empty($odtPath)) {
169 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
171 $texte .= count($listoffiles);
177 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
179 foreach ($listoffiles as $file) {
180 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=supplier_proposal/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
181 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
189 $texte .=
'<table width="50%;">';
191 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelSupplierProposalCreate").
'</td>';
192 $texte .=
'<td colspan="">';
193 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT'));
194 $texte .=
"</td></tr>";
197 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelSupplierProposalToBill").
'</td>';
198 $texte .=
'<td colspan="">';
199 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL'));
200 $texte .=
"</td></tr>";
203 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelSupplierProposalClosed").
'</td>';
204 $texte .=
'<td colspan="">';
205 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED'));
206 $texte .=
"</td></tr>";
207 $texte .=
'</table>';
215 $texte .=
'</table>';
233 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
236 global $user, $langs, $conf, $mysoc, $hookmanager;
238 if (empty($srctemplatepath)) {
239 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
244 if (!is_object($hookmanager)) {
245 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
248 $hookmanager->initHooks(array(
'odtgeneration'));
251 if (!is_object($outputlangs)) {
252 $outputlangs = $langs;
254 $sav_charset_output = $outputlangs->charset_output;
255 $outputlangs->charset_output =
'UTF-8';
258 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
260 if ($conf->supplier_proposal->dir_output) {
274 $dir = $conf->supplier_proposal->dir_output;
276 if (!preg_match(
'/specimen/i', $objectref)) {
277 $dir .=
"/".$objectref;
279 $file = $dir.
"/".$objectref.
".odt";
281 if (!file_exists($dir)) {
283 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
288 if (file_exists($dir)) {
290 $newfile = basename($srctemplatepath);
291 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
292 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
293 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
295 $newfiletmp = $objectref .
'_' . $newfiletmp;
298 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
301 if ($format ==
'1') {
302 $format =
'%Y%m%d%H%M%S';
306 $filename = $newfiletmp .
'.' . $newfileformat;
308 $file = $dir .
'/' . $filename;
314 dol_mkdir($conf->supplier_proposal->dir_temp);
315 if (!is_writable($conf->supplier_proposal->dir_temp)) {
316 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->supplier_proposal->dir_temp);
317 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
323 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
324 if (count($arrayidcontact) > 0) {
326 $result =
$object->fetch_contact($arrayidcontact[0]);
330 $contactobject =
null;
331 if (!empty($usecontact)) {
333 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
334 $object->contact->fetch_thirdparty();
335 $socobject =
$object->contact->thirdparty;
336 $contactobject =
$object->contact;
338 $socobject =
$object->thirdparty;
340 $contactobject =
$object->contact;
343 $socobject =
$object->thirdparty;
347 $substitutionarray = array(
348 '__FROM_NAME__' => $this->emetteur->name,
349 '__FROM_EMAIL__' => $this->emetteur->email,
350 '__TOTAL_TTC__' =>
$object->total_ttc,
351 '__TOTAL_HT__' =>
$object->total_ht,
352 '__TOTAL_VAT__' =>
$object->total_tva
356 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
357 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
361 $paramfreetext =
'SUPPLIER_PROPOSAL_FREE_TEXT';
367 require_once ODTPHP_PATH.
'odf.php';
369 $odfHandler =
new Odf(
372 'PATH_TO_TMP' => $conf->supplier_proposal->dir_temp,
374 'DELIMITER_LEFT' =>
'{',
375 'DELIMITER_RIGHT' =>
'}'
379 $this->error = $e->getMessage();
392 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
393 }
catch (OdfException $e) {
399 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
405 $array_thirdparty_contact = array();
406 if ($usecontact && is_object($contactobject)) {
410 $tmparray = array_merge($substitutionarray, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
414 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
415 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
417 foreach ($tmparray as $key => $value) {
419 if (preg_match(
'/logo$/', $key)) {
420 if (file_exists($value)) {
421 $odfHandler->setImage($key, $value);
423 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
426 $odfHandler->setVars($key, $value,
true,
'UTF-8');
428 }
catch (OdfException $e) {
433 $foundtagforlines = 1;
435 $listlines = $odfHandler->setSegment(
'lines');
436 }
catch (OdfExceptionSegmentNotFound $e) {
438 $foundtagforlines = 0;
441 if ($foundtagforlines) {
443 foreach (
$object->lines as $line) {
448 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
449 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
450 foreach ($tmparray as $key => $val) {
452 $listlines->setVars($key, $val,
true,
'UTF-8');
453 }
catch (SegmentException $e) {
460 $odfHandler->mergeSegment($listlines);
461 }
catch (OdfException $e) {
462 $this->error = $e->getMessage();
469 $tmparray = $outputlangs->get_translations_for_substitutions();
470 foreach ($tmparray as $key => $value) {
472 $odfHandler->setVars($key, $value,
true,
'UTF-8');
473 }
catch (OdfException $e) {
479 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
480 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
485 $odfHandler->exportAsAttachedPDF($file);
487 $this->error = $e->getMessage();
493 $odfHandler->saveToDisk($file);
495 $this->error = $e->getMessage();
500 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
501 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
507 $this->result = array(
'fullpath' => $file);
511 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);