99 public function info($langs)
104 $langs->loadLangs(array(
'companies',
'errors'));
106 $form =
new Form($this->db);
108 $odtChosen =
getDolGlobalInt(
'MAIN_SUPPLIER_PROPOSAL_CHOOSE_ODT_DOCUMENT') > 0;
112 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
113 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
114 $texte .=
'<input type="hidden" name="page_y" value="">';
115 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
116 $texte .=
'<input type="hidden" name="param1" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH">';
118 $texte .=
'<input type="hidden" name="param2" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT">';
119 $texte .=
'<input type="hidden" name="param3" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL">';
120 $texte .=
'<input type="hidden" name="param4" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED">';
122 $texte .=
'<table class="nobordernopadding" width="100%">';
125 $texte .=
'<tr><td>';
126 $texttitle = $langs->trans(
"ListOfDirectories");
127 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
128 $listoffiles = array();
129 foreach ($listofdir as $key => $tmpdir) {
130 $tmpdir = trim($tmpdir);
131 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
133 unset($listofdir[$key]);
136 if (!is_dir($tmpdir)) {
137 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
139 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
140 if (count($tmpfiles)) {
141 $listoffiles = array_merge($listoffiles, $tmpfiles);
145 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
146 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
148 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
149 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
151 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
152 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
153 $texte .=
'<textarea class="flat" cols="60" name="value1">';
155 $texte .=
'</textarea>';
156 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
157 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
158 $texte .=
'<br></div></div>';
161 $nbofiles = count($listoffiles);
162 if (!empty($odtPath)) {
163 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
165 $texte .= count($listoffiles);
171 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
173 foreach ($listoffiles as $file) {
174 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=supplier_proposal/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
175 $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>';
183 $texte .=
'<table width="50%;">';
185 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelSupplierProposalCreate").
'</td>';
186 $texte .=
'<td colspan="">';
187 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT'));
188 $texte .=
"</td></tr>";
191 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelSupplierProposalToBill").
'</td>';
192 $texte .=
'<td colspan="">';
193 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL'));
194 $texte .=
"</td></tr>";
197 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelSupplierProposalClosed").
'</td>';
198 $texte .=
'<td colspan="">';
199 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED'));
200 $texte .=
"</td></tr>";
201 $texte .=
'</table>';
209 $texte .=
'</table>';
227 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
230 global $user, $langs, $conf, $mysoc, $hookmanager;
232 if (empty($srctemplatepath)) {
233 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
238 if (!is_object($hookmanager)) {
239 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
242 $hookmanager->initHooks(array(
'odtgeneration'));
245 if (!is_object($outputlangs)) {
246 $outputlangs = $langs;
248 $sav_charset_output = $outputlangs->charset_output;
249 $outputlangs->charset_output =
'UTF-8';
252 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
254 if ($conf->supplier_proposal->dir_output) {
268 $dir = $conf->supplier_proposal->dir_output;
270 if (!preg_match(
'/specimen/i', $objectref)) {
271 $dir .=
"/".$objectref;
273 $file = $dir.
"/".$objectref.
".odt";
275 if (!file_exists($dir)) {
277 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
282 if (file_exists($dir)) {
284 $newfile = basename($srctemplatepath);
285 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
286 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
287 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
289 $newfiletmp = $objectref .
'_' . $newfiletmp;
292 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
295 if ($format ==
'1') {
296 $format =
'%Y%m%d%H%M%S';
300 $filename = $newfiletmp .
'.' . $newfileformat;
302 $file = $dir .
'/' . $filename;
308 dol_mkdir($conf->supplier_proposal->dir_temp);
309 if (!is_writable($conf->supplier_proposal->dir_temp)) {
310 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->supplier_proposal->dir_temp);
311 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
317 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
318 if (count($arrayidcontact) > 0) {
320 $result =
$object->fetch_contact($arrayidcontact[0]);
324 $contactobject =
null;
325 if (!empty($usecontact)) {
327 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
328 $object->contact->fetch_thirdparty();
329 $socobject =
$object->contact->thirdparty;
330 $contactobject =
$object->contact;
332 $socobject =
$object->thirdparty;
334 $contactobject =
$object->contact;
337 $socobject =
$object->thirdparty;
341 $substitutionarray = array(
342 '__FROM_NAME__' => $this->emetteur->name,
343 '__FROM_EMAIL__' => $this->emetteur->email,
344 '__TOTAL_TTC__' =>
$object->total_ttc,
345 '__TOTAL_HT__' =>
$object->total_ht,
346 '__TOTAL_VAT__' =>
$object->total_tva
350 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
351 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
355 $paramfreetext =
'SUPPLIER_PROPOSAL_FREE_TEXT';
356 if (!empty($conf->global->$paramfreetext)) {
361 require_once ODTPHP_PATH.
'odf.php';
363 $odfHandler =
new Odf(
366 'PATH_TO_TMP' => $conf->supplier_proposal->dir_temp,
367 'ZIP_PROXY' =>
'PclZipProxy',
368 'DELIMITER_LEFT' =>
'{',
369 'DELIMITER_RIGHT' =>
'}'
373 $this->error = $e->getMessage();
386 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
387 }
catch (OdfException $e) {
393 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
399 $array_thirdparty_contact = array();
400 if ($usecontact && is_object($contactobject)) {
404 $tmparray = array_merge($substitutionarray, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
408 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
409 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
411 foreach ($tmparray as $key => $value) {
413 if (preg_match(
'/logo$/', $key)) {
414 if (file_exists($value)) {
415 $odfHandler->setImage($key, $value);
417 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
420 $odfHandler->setVars($key, $value,
true,
'UTF-8');
422 }
catch (OdfException $e) {
427 $foundtagforlines = 1;
429 $listlines = $odfHandler->setSegment(
'lines');
430 }
catch (OdfExceptionSegmentNotFound $e) {
432 $foundtagforlines = 0;
435 if ($foundtagforlines) {
437 foreach (
$object->lines as $line) {
442 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray,
'line'=>$line);
443 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
444 foreach ($tmparray as $key => $val) {
446 $listlines->setVars($key, $val,
true,
'UTF-8');
447 }
catch (SegmentException $e) {
454 $odfHandler->mergeSegment($listlines);
455 }
catch (OdfException $e) {
456 $this->error = $e->getMessage();
463 $tmparray = $outputlangs->get_translations_for_substitutions();
464 foreach ($tmparray as $key => $value) {
466 $odfHandler->setVars($key, $value,
true,
'UTF-8');
467 }
catch (OdfException $e) {
473 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
474 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
479 $odfHandler->exportAsAttachedPDF($file);
481 $this->error = $e->getMessage();
487 $odfHandler->saveToDisk($file);
489 $this->error = $e->getMessage();
494 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
495 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
501 $this->result = array(
'fullpath'=>$file);
505 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);