108 global
$conf, $langs;
111 $langs->loadLangs(array(
"errors",
"companies"));
113 $form =
new Form($this->db);
116 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
117 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
118 $texte .=
'<input type="hidden" name="page_y" value="">';
119 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
120 $texte .=
'<input type="hidden" name="param1" value="MRP_MO_ADDON_PDF_ODT_PATH">';
121 $texte .=
'<table class="nobordernopadding" width="100%">';
124 $texte .=
'<tr><td>';
125 $texttitle = $langs->trans(
"ListOfDirectories");
126 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
$conf->global->MRP_MO_ADDON_PDF_ODT_PATH)));
127 $listoffiles = array();
128 foreach ($listofdir as $key => $tmpdir) {
129 $tmpdir = trim($tmpdir);
130 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
132 unset($listofdir[$key]);
135 if (!is_dir($tmpdir)) {
136 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
138 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
139 if (count($tmpfiles)) {
140 $listoffiles = array_merge($listoffiles, $tmpfiles);
144 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
145 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
147 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
148 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
150 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
151 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
152 $texte .=
'<textarea class="flat" cols="60" name="value1">';
154 $texte .=
'</textarea>';
155 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
156 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
157 $texte .=
'<br></div></div>';
160 $nbofiles = count($listoffiles);
162 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
164 $texte .= count($listoffiles);
170 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
172 foreach ($listoffiles as $file) {
173 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=mrps/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
174 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=MRP_MO_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
184 $texte .=
'</table>';
202 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
205 global $user, $langs,
$conf, $mysoc, $hookmanager;
207 if (empty($srctemplatepath)) {
208 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
213 if (!is_object($hookmanager)) {
214 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
217 $hookmanager->initHooks(array(
'odtgeneration'));
220 if (!is_object($outputlangs)) {
221 $outputlangs = $langs;
223 $sav_charset_output = $outputlangs->charset_output;
224 $outputlangs->charset_output =
'UTF-8';
226 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
228 if (
$conf->mrp->dir_output) {
244 if (!preg_match(
'/specimen/i', $objectref)) {
245 $dir .=
"/".$objectref;
247 $file = $dir.
"/".$objectref.
".odt";
249 if (!file_exists($dir)) {
251 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
256 if (file_exists($dir)) {
258 $newfile = basename($srctemplatepath);
259 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
260 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
261 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
262 $newfiletmp = $objectref .
'_' . $newfiletmp;
265 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
268 if ($format ==
'1') {
269 $format =
'%Y%m%d%H%M%S';
273 $filename = $newfiletmp .
'.' . $newfileformat;
275 $file = $dir .
'/' . $filename;
282 if (!is_writable(
$conf->mrp->dir_temp)) {
283 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->mrp->dir_temp);
284 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
290 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
291 if (count($arrayidcontact) > 0) {
293 $result =
$object->fetch_contact($arrayidcontact[0]);
297 $contactobject =
null;
298 if (!empty($usecontact)) {
301 $object->contact->fetch_thirdparty();
302 $socobject =
$object->contact->thirdparty;
303 $contactobject =
$object->contact;
305 $socobject =
$object->thirdparty;
307 $contactobject =
$object->contact;
310 $socobject =
$object->thirdparty;
314 $substitutionarray = array(
315 '__QTY_TO_PRODUCE__' =>
$object->qty,
319 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
320 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
324 $paramfreetext =
'MRP_MO_FREE_TEXT';
330 require_once ODTPHP_PATH.
'odf.php';
332 $odfHandler =
new Odf(
335 'PATH_TO_TMP' =>
$conf->mrp->dir_temp,
337 'DELIMITER_LEFT' =>
'{',
338 'DELIMITER_RIGHT' =>
'}'
342 $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)) {
385 if (file_exists($value)) {
386 $odfHandler->setImage($key, $value);
388 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
392 $odfHandler->setVars($key, $value,
true,
'UTF-8');
394 }
catch (OdfException $e) {
400 $foundtagforlines = 1;
402 $listlines = $odfHandler->setSegment(
'lines');
403 }
catch (OdfExceptionSegmentNotFound $e) {
405 $foundtagforlines = 0;
408 if ($foundtagforlines) {
410 foreach (
$object->lines as $line) {
415 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
416 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
417 foreach ($tmparray as $key => $val) {
419 $listlines->setVars($key, $val,
true,
'UTF-8');
420 }
catch (SegmentException $e) {
427 $odfHandler->mergeSegment($listlines);
428 }
catch (OdfException $e) {
429 $this->error = $e->getMessage();
436 $tmparray = $outputlangs->get_translations_for_substitutions();
437 foreach ($tmparray as $key => $value) {
439 $odfHandler->setVars($key, $value,
true,
'UTF-8');
440 }
catch (OdfException $e) {
447 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
448 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
453 $odfHandler->exportAsAttachedPDF($file);
455 $this->error = $e->getMessage();
456 dol_syslog(
'Error in exportAsAttachedPDF: '.$e->getMessage(), LOG_INFO);
461 $odfHandler->saveToDisk($file);
463 $this->error = $e->getMessage();
464 dol_syslog(
'Error in saveToDisk: '.$e->getMessage(), LOG_INFO);
469 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
470 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
476 $this->result = array(
'fullpath' => $file);
480 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);