105 global
$conf, $langs;
108 $langs->loadLangs(array(
"errors",
"companies"));
110 $form =
new Form($this->db);
113 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
114 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
115 $texte .=
'<input type="hidden" name="page_y" value="">';
116 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
117 $texte .=
'<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">';
118 $texte .=
'<table class="nobordernopadding" width="100%">';
121 $texte .=
'<tr><td>';
122 $texttitle = $langs->trans(
"ListOfDirectories");
123 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'STOCK_ADDON_PDF_ODT_PATH'))));
124 $listoffiles = array();
125 foreach ($listofdir as $key => $tmpdir) {
126 $tmpdir = trim($tmpdir);
127 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
129 unset($listofdir[$key]);
132 if (!is_dir($tmpdir)) {
133 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
135 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
136 if (count($tmpfiles)) {
137 $listoffiles = array_merge($listoffiles, $tmpfiles);
141 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
142 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
144 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
145 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
147 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
148 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
149 $texte .=
'<textarea class="flat" cols="60" name="value1">';
151 $texte .=
'</textarea>';
152 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
153 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
154 $texte .=
'<br></div></div>';
157 $nbofiles = count($listoffiles);
159 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
161 $texte .= count($listoffiles);
167 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
169 foreach ($listoffiles as $file) {
170 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=stocks/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
171 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=STOCK_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
177 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
179 $maxmin = $maxfilesizearray[
'maxmin'];
181 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
183 $texte .=
' <input type="file" name="uploadfile">';
184 $texte .=
'<input type="hidden" value="STOCK_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
185 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
192 $texte .=
'</table>';
210 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
213 global $stock, $langs,
$conf, $mysoc, $hookmanager, $user;
215 if (empty($srctemplatepath)) {
216 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
221 if (!is_object($hookmanager)) {
222 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
225 $hookmanager->initHooks(array(
'odtgeneration'));
228 if (!is_object($outputlangs)) {
229 $outputlangs = $langs;
231 $sav_charset_output = $outputlangs->charset_output;
232 $outputlangs->charset_output =
'UTF-8';
235 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
237 if (
$conf->product->dir_output) {
250 $supplierprices = $stockFournisseur->list_stock_fournisseur_price(
$object->id);
251 $object->supplierprices = $supplierprices;
253 $dir =
$conf->product->dir_output;
255 if (!preg_match(
'/specimen/i', $objectref)) {
256 $dir .=
"/".$objectref;
258 $file = $dir.
"/".$objectref.
".odt";
260 if (!file_exists($dir)) {
262 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
267 if (file_exists($dir)) {
269 $newfile = basename($srctemplatepath);
270 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
271 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
272 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
274 $newfiletmp = $objectref .
'_' . $newfiletmp;
277 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
280 if ($format ==
'1') {
281 $format =
'%Y%m%d%H%M%S';
285 $filename = $newfiletmp .
'.' . $newfileformat;
287 $file = $dir .
'/' . $filename;
290 if (!is_writable(
$conf->product->dir_temp)) {
291 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->product->dir_temp);
292 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
298 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
299 if (count($arrayidcontact) > 0) {
301 $result =
$object->fetch_contact($arrayidcontact[0]);
305 $contactobject =
null;
306 if (!empty($usecontact)) {
309 $object->contact->fetch_thirdparty();
310 $socobject =
$object->contact->thirdparty;
311 $contactobject =
$object->contact;
313 $socobject =
$object->thirdparty;
315 $contactobject =
$object->contact;
318 $socobject =
$object->thirdparty;
321 $substitutionarray = array(
322 '__FROM_NAME__' => $this->emetteur->name,
323 '__FROM_EMAIL__' => $this->emetteur->email,
324 '__TOTAL_TTC__' =>
$object->total_ttc,
325 '__TOTAL_HT__' =>
$object->total_ht,
326 '__TOTAL_VAT__' =>
$object->total_tva
330 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
331 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
335 $paramfreetext =
'stock_FREE_TEXT';
341 require_once ODTPHP_PATH.
'odf.php';
343 $odfHandler =
new Odf(
346 'PATH_TO_TMP' =>
$conf->product->dir_temp,
348 'DELIMITER_LEFT' =>
'{',
349 'DELIMITER_RIGHT' =>
'}'
353 $this->error = $e->getMessage();
365 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
366 }
catch (OdfException $e) {
379 $array_thirdparty_contact = array();
380 if ($usecontact && is_object($contactobject)) {
384 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
388 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
389 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
391 foreach ($tmparray as $key => $value) {
393 if (preg_match(
'/logo$/', $key)) {
394 if (file_exists($value)) {
395 $odfHandler->setImage($key, $value);
397 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
400 $odfHandler->setVars($key, $value,
true,
'UTF-8');
402 }
catch (OdfException $e) {
407 $foundtagforlines = 1;
409 $listlines = $odfHandler->setSegment(
'supplierprices');
410 }
catch (OdfExceptionSegmentNotFound $e) {
412 $foundtagforlines = 0;
415 if ($foundtagforlines && !empty(
$object->supplierprices)) {
416 foreach (
$object->supplierprices as $supplierprice) {
420 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$array_lines,
'line' => $supplierprice);
421 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
422 foreach ($array_lines as $key => $val) {
424 $listlines->setVars($key, $val,
true,
'UTF-8');
425 }
catch (SegmentException $e) {
432 $odfHandler->mergeSegment($listlines);
433 }
catch (OdfException $e) {
434 $this->error = $e->getMessage();
441 $tmparray = $outputlangs->get_translations_for_substitutions();
442 foreach ($tmparray as $key => $value) {
444 $odfHandler->setVars($key, $value,
true,
'UTF-8');
445 }
catch (OdfException $e) {
451 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
452 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
457 $odfHandler->exportAsAttachedPDF($file);
459 $this->error = $e->getMessage();
465 $odfHandler->saveToDisk($file);
467 $this->error = $e->getMessage();
473 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
479 $this->result = array(
'fullpath' => $file);
483 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);