97 public function info($langs)
102 $langs->loadLangs(array(
'companies',
'errors'));
104 $form =
new Form($this->db);
107 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
108 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
109 $texte .=
'<input type="hidden" name="page_y" value="">';
110 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
111 $texte .=
'<input type="hidden" name="param1" value="MEMBER_ADDON_PDF_ODT_PATH">';
112 $texte .=
'<table class="nobordernopadding" width="100%">';
115 $texte .=
'<tr><td>';
116 $texttitle = $langs->trans(
"ListOfDirectories");
117 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'MEMBER_ADDON_PDF_ODT_PATH'))));
118 $listoffiles = array();
119 foreach ($listofdir as $key => $tmpdir) {
120 $tmpdir = trim($tmpdir);
121 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
123 unset($listofdir[$key]);
126 if (!is_dir($tmpdir)) {
127 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
129 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
130 if (count($tmpfiles)) {
131 $listoffiles = array_merge($listoffiles, $tmpfiles);
135 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
136 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
138 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
139 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
141 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
142 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
143 $texte .=
'<textarea class="flat" cols="60" name="value1">';
145 $texte .=
'</textarea>';
146 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
147 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
148 $texte .=
'<br></div></div>';
151 if (count($listofdir)) {
152 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
154 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
156 foreach ($listoffiles as $file) {
157 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=members/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
158 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=MEMBER_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
164 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
166 $maxmin = $maxfilesizearray[
'maxmin'];
168 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
170 $texte .=
' <input type="file" name="uploadfile">';
171 $texte .=
'<input type="hidden" value="MEMBER_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
172 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
178 $texte .=
'</table>';
196 public function write_file($object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
199 global $user, $langs, $conf, $mysoc, $hookmanager;
201 if (empty($srctemplatepath)) {
202 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
207 if (!is_object($hookmanager)) {
208 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
211 $hookmanager->initHooks(array(
'odtgeneration'));
214 if (!is_object($outputlangs)) {
215 $outputlangs = $langs;
217 $sav_charset_output = $outputlangs->charset_output;
218 $outputlangs->charset_output =
'UTF-8';
221 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
223 if ($conf->adherent->dir_output) {
225 if (!is_object($object)) {
227 $object =
new User($this->db);
228 $result = $object->fetch($id);
235 $object->fetch_thirdparty();
237 $dir = $conf->adherent->dir_output;
239 if (!preg_match(
'/specimen/i', $objectref)) {
240 $dir .=
"/".$objectref;
242 $file = $dir.
"/".$objectref.
".odt";
244 if (!file_exists($dir)) {
246 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
251 if (file_exists($dir)) {
253 $newfile = basename($srctemplatepath);
254 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
255 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
256 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
258 $newfiletmp = $objectref .
'_' . $newfiletmp;
261 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
264 if ($format ==
'1') {
265 $format =
'%Y%m%d%H%M%S';
269 $filename = $newfiletmp .
'.' . $newfileformat;
271 $file = $dir .
'/' . $filename;
278 if (!is_writable($conf->adherent->dir_temp)) {
279 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->adherent->dir_temp);
280 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
286 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
287 if (count($arrayidcontact) > 0) {
289 $result = $object->fetch_contact($arrayidcontact[0]);
293 if (!empty($usecontact)) {
295 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
296 $object->contact->fetch_thirdparty();
297 $socobject = $object->contact->thirdparty;
298 $contactobject = $object->contact;
300 $socobject = $object->thirdparty;
302 $contactobject = $object->contact;
305 $socobject = $object->thirdparty;
309 require_once ODTPHP_PATH.
'odf.php';
311 $odfHandler =
new Odf(
314 'PATH_TO_TMP' => $conf->adherent->dir_temp,
316 'DELIMITER_LEFT' =>
'{',
317 'DELIMITER_RIGHT' =>
'}'
321 $this->error = $e->getMessage();
332 $array_thirdparty_contact = array();
333 if ($usecontact && is_object($contactobject)) {
337 $tmparray = array_merge($array_member, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
343 'outputlangs'=>$outputlangs,
344 'substitutionarray'=>&$tmparray
346 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
347 foreach ($tmparray as $key => $value) {
349 if (preg_match(
'/logo$/', $key)) {
351 if (file_exists($value)) {
352 $odfHandler->setImage($key, $value);
354 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
358 $odfHandler->setVars($key, $value,
true,
'UTF-8');
360 }
catch (OdfException $e) {
366 $tmparray = $outputlangs->get_translations_for_substitutions();
367 foreach ($tmparray as $key => $value) {
369 $odfHandler->setVars($key, $value,
true,
'UTF-8');
370 }
catch (OdfException $e) {
376 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
377 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
382 $odfHandler->exportAsAttachedPDF($file);
384 $this->error = $e->getMessage();
390 $odfHandler->saveToDisk($file);
392 $this->error = $e->getMessage();
398 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
404 $this->result = array(
'fullpath'=>$file);
408 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);