98 public function info($langs)
100 global $conf, $langs;
103 $langs->loadLangs(array(
"errors",
"companies"));
105 $form =
new Form($this->db);
108 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
109 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
110 $texte .=
'<input type="hidden" name="page_y" value="">';
111 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
112 $texte .=
'<input type="hidden" name="param1" value="PRODUCT_ADDON_PDF_ODT_PATH">';
113 $texte .=
'<table class="nobordernopadding" width="100%">';
116 $texte .=
'<tr><td>';
117 $texttitle = $langs->trans(
"ListOfDirectories");
118 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->PRODUCT_ADDON_PDF_ODT_PATH)));
119 $listoffiles = array();
120 foreach ($listofdir as $key => $tmpdir) {
121 $tmpdir = trim($tmpdir);
122 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
124 unset($listofdir[$key]);
127 if (!is_dir($tmpdir)) {
128 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
130 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
131 if (count($tmpfiles)) {
132 $listoffiles = array_merge($listoffiles, $tmpfiles);
136 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
137 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
139 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
140 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
142 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
143 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
144 $texte .=
'<textarea class="flat" cols="60" name="value1">';
146 $texte .=
'</textarea>';
147 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
148 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
149 $texte .=
'<br></div></div>';
152 $nbofiles = count($listoffiles);
154 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
158 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
160 foreach ($listoffiles as $file) {
161 $texte .=
'- '.$file[
'name'];
162 $texte .=
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=products/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
163 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=PRODUCT_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
169 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
171 $maxmin = $maxfilesizearray[
'maxmin'];
173 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
175 $texte .=
' <input type="file" name="uploadfile">';
176 $texte .=
'<input type="hidden" value="PRODUCT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
177 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
184 $texte .=
'</table>';
202 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
205 global $product, $langs, $conf, $mysoc, $hookmanager, $user;
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';
227 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
229 if ($conf->product->dir_output) {
241 $supplierprices = $productFournisseur->list_product_fournisseur_price(
$object->id);
242 $object->supplierprices = $supplierprices;
244 $dir = $conf->product->dir_output;
246 if (!preg_match(
'/specimen/i', $objectref)) {
247 $dir .=
"/".$objectref;
249 $file = $dir.
"/".$objectref.
".odt";
251 if (!file_exists($dir)) {
253 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
258 if (file_exists($dir)) {
260 $newfile = basename($srctemplatepath);
261 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
262 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
263 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
265 $newfiletmp = $objectref .
'_' . $newfiletmp;
268 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
271 if ($format ==
'1') {
272 $format =
'%Y%m%d%H%M%S';
276 $filename = $newfiletmp .
'.' . $newfileformat;
278 $file = $dir .
'/' . $filename;
285 if (!is_writable($conf->product->dir_temp)) {
286 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->product->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)) {
303 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
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;
316 $substitutionarray = array(
317 '__FROM_NAME__' => $this->emetteur->name,
318 '__FROM_EMAIL__' => $this->emetteur->email,
319 '__TOTAL_TTC__' =>
$object->total_ttc,
320 '__TOTAL_HT__' =>
$object->total_ht,
321 '__TOTAL_VAT__' =>
$object->total_tva
325 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
326 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
330 $paramfreetext =
'PRODUCT_FREE_TEXT';
336 require_once ODTPHP_PATH.
'odf.php';
338 $odfHandler =
new Odf(
341 'PATH_TO_TMP' => $conf->product->dir_temp,
342 'ZIP_PROXY' =>
'PclZipProxy',
343 'DELIMITER_LEFT' =>
'{',
344 'DELIMITER_RIGHT' =>
'}'
348 $this->error = $e->getMessage();
361 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
362 }
catch (OdfException $e) {
375 $array_thirdparty_contact = array();
376 if ($usecontact && is_object($contactobject)) {
380 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
384 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
385 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
387 foreach ($tmparray as $key => $value) {
389 if (preg_match(
'/logo$/', $key)) {
390 if (file_exists($value)) {
391 $odfHandler->setImage($key, $value);
393 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
396 $odfHandler->setVars($key, $value,
true,
'UTF-8');
398 }
catch (OdfException $e) {
404 $listlines = $odfHandler->setSegment(
'supplierprices');
405 if (!empty(
$object->supplierprices)) {
406 foreach (
$object->supplierprices as $supplierprice) {
410 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$array_lines,
'line'=>$supplierprice);
411 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
412 foreach ($array_lines as $key => $val) {
414 $listlines->setVars($key, $val,
true,
'UTF-8');
415 }
catch (SegmentException $e) {
422 $odfHandler->mergeSegment($listlines);
423 }
catch (OdfException $e) {
424 $this->error = $e->getMessage();
430 $tmparray = $outputlangs->get_translations_for_substitutions();
431 foreach ($tmparray as $key => $value) {
433 $odfHandler->setVars($key, $value,
true,
'UTF-8');
434 }
catch (OdfException $e) {
440 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs);
441 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
446 $odfHandler->exportAsAttachedPDF($file);
448 $this->error = $e->getMessage();
454 $odfHandler->saveToDisk($file);
456 $this->error = $e->getMessage();
462 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
463 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
469 $this->result = array(
'fullpath'=>$file);
473 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);