99 public function info($langs)
101 global
$conf, $langs;
104 $langs->loadLangs(array(
"errors",
"companies"));
106 $form =
new Form($this->db);
109 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
110 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
111 $texte .=
'<input type="hidden" name="page_y" value="">';
112 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
113 $texte .=
'<input type="hidden" name="param1" value="BOM_ADDON_PDF_ODT_PATH">';
114 $texte .=
'<table class="nobordernopadding" width="100%">';
117 $texte .=
'<tr><td>';
118 $texttitle = $langs->trans(
"ListOfDirectories");
119 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
$conf->global->BOM_ADDON_PDF_ODT_PATH)));
120 $listoffiles = array();
121 foreach ($listofdir as $key => $tmpdir) {
122 $tmpdir = trim($tmpdir);
123 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
125 unset($listofdir[$key]);
128 if (!is_dir($tmpdir)) {
129 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
131 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
132 if (count($tmpfiles)) {
133 $listoffiles = array_merge($listoffiles, $tmpfiles);
137 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
138 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
140 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
141 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
143 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
144 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
145 $texte .=
'<textarea class="flat" cols="60" name="value1">';
147 $texte .=
'</textarea>';
148 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
149 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'">';
150 $texte .=
'<br></div></div>';
153 $nbofiles = count($listoffiles);
155 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
157 $texte .= count($listoffiles);
163 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
165 foreach ($listoffiles as $file) {
166 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=boms/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
167 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=BOM_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
173 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
175 $maxmin = $maxfilesizearray[
'maxmin'];
177 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
179 $texte .=
' <input type="file" name="uploadfile">';
180 $texte .=
'<input type="hidden" value="BOM_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
181 $texte .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
188 $texte .=
'</table>';
206 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
209 global $user, $langs,
$conf, $mysoc, $hookmanager;
211 if (empty($srctemplatepath)) {
212 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
217 if (!is_object($hookmanager)) {
218 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
221 $hookmanager->initHooks(array(
'odtgeneration'));
224 if (!is_object($outputlangs)) {
225 $outputlangs = $langs;
227 $sav_charset_output = $outputlangs->charset_output;
228 $outputlangs->charset_output =
'UTF-8';
231 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
233 if (
$conf->bom->dir_output) {
251 if (!preg_match(
'/specimen/i', $objectref)) {
252 $dir .=
"/".$objectref;
254 $file = $dir.
"/".$objectref.
".odt";
256 if (!file_exists($dir)) {
258 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
263 if (file_exists($dir)) {
265 $newfile = basename($srctemplatepath);
266 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
267 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
268 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
269 $newfiletmp = $objectref .
'_' . $newfiletmp;
272 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
275 if ($format ==
'1') {
276 $format =
'%Y%m%d%H%M%S';
280 $filename = $newfiletmp .
'.' . $newfileformat;
282 $file = $dir .
'/' . $filename;
285 if (!is_writable(
$conf->bom->dir_temp)) {
286 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->bom->dir_temp);
287 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
293 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
294 if (count($arrayidcontact) > 0) {
296 $result =
$object->fetch_contact($arrayidcontact[0]);
300 $contactobject =
null;
301 if (!empty($usecontact)) {
304 $object->contact->fetch_thirdparty();
305 $socobject =
$object->contact->thirdparty;
306 $contactobject =
$object->contact;
308 $socobject =
$object->thirdparty;
310 $contactobject =
$object->contact;
313 $socobject =
$object->thirdparty;
317 $substitutionarray = array(
318 '__QTY_TO_PRODUCE__' =>
$object->qty,
322 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
323 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
327 $paramfreetext =
'BOM_FREE_TEXT';
333 require_once ODTPHP_PATH.
'odf.php';
335 $odfHandler =
new Odf(
338 'PATH_TO_TMP' =>
$conf->bom->dir_temp,
340 'DELIMITER_LEFT' =>
'{',
341 'DELIMITER_RIGHT' =>
'}'
345 $this->error = $e->getMessage();
355 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
356 }
catch (OdfException $e) {
363 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
369 $array_thirdparty_contact = array();
370 if ($usecontact && is_object($contactobject)) {
374 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
378 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
379 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
381 foreach ($tmparray as $key => $value) {
383 if (preg_match(
'/logo$/', $key)) {
384 if (file_exists($value)) {
385 $odfHandler->setImage($key, $value);
387 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
390 $odfHandler->setVars($key, $value,
true,
'UTF-8');
392 }
catch (OdfException $e) {
397 $foundtagforlines = 1;
399 $listlines = $odfHandler->setSegment(
'lines');
400 }
catch (OdfExceptionSegmentNotFound $e) {
402 $foundtagforlines = 0;
405 if ($foundtagforlines) {
407 foreach (
$object->lines as $line) {
410 if ($line->fk_product > 0) {
411 $line->fetch_product();
413 $line->product_ref = $line->product->ref;
414 $line->product_desc = $line->product->description;
415 $line->product_label = $line->product->label;
416 $line->product_type = $line->product->type;
417 $line->product_barcode = $line->product->barcode;
423 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
424 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
425 foreach ($tmparray as $key => $val) {
427 $listlines->setVars($key, $val,
true,
'UTF-8');
428 }
catch (SegmentException $e) {
435 $odfHandler->mergeSegment($listlines);
436 }
catch (OdfException $e) {
437 $this->error = $e->getMessage();
444 $tmparray = $outputlangs->get_translations_for_substitutions();
445 foreach ($tmparray as $key => $value) {
447 $odfHandler->setVars($key, $value,
true,
'UTF-8');
448 }
catch (OdfException $e) {
454 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
455 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
460 $odfHandler->exportAsAttachedPDF($file);
462 $this->error = $e->getMessage();
468 $odfHandler->saveToDisk($file);
470 $this->error = $e->getMessage();
476 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
477 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
483 $this->result = array(
'fullpath' => $file);
487 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);