98 public function info($langs)
100 global $conf, $langs;
103 $langs->loadLangs(array(
'companies',
'errors'));
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="CONTRACT_ADDON_PDF_ODT_PATH">';
113 $texte .=
'<table class="nobordernopadding centpercent">';
116 $texte .=
'<tr><td>';
117 $texttitle = $langs->trans(
"ListOfDirectories");
118 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->CONTRACT_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 reposition smallpaddingimp" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
149 $texte .=
'<br></div></div>';
152 $nbofiles = count($listoffiles);
154 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
156 $texte .= count($listoffiles);
162 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
164 foreach ($listoffiles as $file) {
165 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=contracts/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
166 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=CONTRACT_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
172 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
174 $maxmin = $maxfilesizearray[
'maxmin'];
176 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
178 $texte .=
' <input type="file" name="uploadfile">';
179 $texte .=
'<input type="hidden" value="CONTRACT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
180 $texte .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
187 $texte .=
'</table>';
205 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
208 global $user, $langs, $conf, $mysoc, $hookmanager;
210 if (empty($srctemplatepath)) {
211 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
216 if (!is_object($hookmanager)) {
217 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
220 $hookmanager->initHooks(array(
'odtgeneration'));
223 if (!is_object($outputlangs)) {
224 $outputlangs = $langs;
226 $sav_charset_output = $outputlangs->charset_output;
227 $outputlangs->charset_output =
'UTF-8';
230 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
232 if ($conf->contract->multidir_output[
$object->entity]) {
246 $dir = $conf->contract->multidir_output[
$object->entity];
248 if (!preg_match(
'/specimen/i', $objectref)) {
249 $dir .=
"/".$objectref;
251 $file = $dir.
"/".$objectref.
".odt";
253 if (!file_exists($dir)) {
255 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
260 if (file_exists($dir)) {
262 $newfile = basename($srctemplatepath);
263 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
264 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
265 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
267 $newfiletmp = $objectref .
'_' . $newfiletmp;
270 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
273 if ($format ==
'1') {
274 $format =
'%Y%m%d%H%M%S';
278 $filename = $newfiletmp .
'.' . $newfileformat;
280 $file = $dir .
'/' . $filename;
287 if (!is_writable($conf->contract->dir_temp)) {
288 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->contrat->dir_temp);
289 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
295 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
296 if (count($arrayidcontact) > 0) {
298 $result =
$object->fetch_contact($arrayidcontact[0]);
302 $contactobject =
null;
303 if (!empty($usecontact)) {
305 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
306 $object->contact->fetch_thirdparty();
307 $socobject =
$object->contact->thirdparty;
308 $contactobject =
$object->contact;
310 $socobject =
$object->thirdparty;
312 $contactobject =
$object->contact;
315 $socobject =
$object->thirdparty;
324 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
330 $array_thirdparty_contact = array();
331 if ($usecontact && is_object($contactobject)) {
335 $substitutionarray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
338 $tmparray = $substitutionarray;
341 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
342 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
346 $paramfreetext =
'CONTRACT_FREE_TEXT';
347 if (!empty($conf->global->$paramfreetext)) {
353 require_once ODTPHP_PATH.
'odf.php';
355 $odfHandler =
new Odf(
358 'PATH_TO_TMP' => $conf->contrat->dir_temp,
359 'ZIP_PROXY' =>
'PclZipProxy',
360 'DELIMITER_LEFT' =>
'{',
361 'DELIMITER_RIGHT' =>
'}'
365 $this->error = $e->getMessage();
378 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
379 }
catch (OdfException $e) {
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)) {
391 if (file_exists($value)) {
392 $odfHandler->setImage($key, $value);
394 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
398 $odfHandler->setVars($key, $value,
true,
'UTF-8');
400 }
catch (OdfException $e) {
406 $foundtagforlines = 1;
408 $listlines = $odfHandler->setSegment(
'lines');
409 }
catch (OdfExceptionSegmentNotFound $e) {
411 $foundtagforlines = 0;
414 if ($foundtagforlines) {
416 foreach (
$object->lines as $line) {
421 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray,
'line'=>$line);
422 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
423 foreach ($tmparray as $key => $val) {
425 $listlines->setVars($key, $val,
true,
'UTF-8');
426 }
catch (SegmentException $e) {
433 $odfHandler->mergeSegment($listlines);
434 }
catch (OdfException $e) {
435 $this->error = $e->getMessage();
442 $tmparray = $outputlangs->get_translations_for_substitutions();
443 foreach ($tmparray as $key => $value) {
445 $odfHandler->setVars($key, $value,
true,
'UTF-8');
446 }
catch (OdfException $e) {
452 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
453 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
458 $odfHandler->exportAsAttachedPDF($file);
460 $this->error = $e->getMessage();
466 $odfHandler->saveToDisk($file);
468 $this->error = $e->getMessage();
474 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
475 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
481 $this->result = array(
'fullpath'=>$file);
485 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);