108 $langs->loadLangs(array(
'companies',
'errors'));
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="MEMBER_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(
'MEMBER_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 if (count($listofdir)) {
158 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
160 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
162 foreach ($listoffiles as $file) {
163 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=members/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
164 $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>';
170 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
172 $maxmin = $maxfilesizearray[
'maxmin'];
174 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
176 $texte .=
' <input type="file" name="uploadfile">';
177 $texte .=
'<input type="hidden" value="MEMBER_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
178 $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 =
'', $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
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';
227 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
229 if ($conf->adherent->dir_output) {
243 $dir = $conf->adherent->dir_output;
245 if (!preg_match(
'/specimen/i', $objectref)) {
246 $dir .=
"/".$objectref;
248 $file = $dir.
"/".$objectref.
".odt";
250 if (!file_exists($dir)) {
252 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
257 if (file_exists($dir)) {
259 $newfile = basename($srctemplatepath);
260 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
261 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
262 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
264 $newfiletmp = $objectref .
'_' . $newfiletmp;
267 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
270 if ($format ==
'1') {
271 $format =
'%Y%m%d%H%M%S';
275 $filename = $newfiletmp .
'.' . $newfileformat;
277 $file = $dir .
'/' . $filename;
284 if (!is_writable($conf->adherent->dir_temp)) {
285 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->adherent->dir_temp);
286 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
292 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
293 if (count($arrayidcontact) > 0) {
295 $result =
$object->fetch_contact($arrayidcontact[0]);
299 if (!empty($usecontact)) {
301 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
302 $object->contact->fetch_thirdparty();
303 $socobject =
$object->contact->thirdparty;
304 $contactobject =
$object->contact;
306 $socobject =
$object->thirdparty;
308 $contactobject =
$object->contact;
311 $socobject =
$object->thirdparty;
315 require_once ODTPHP_PATH.
'odf.php';
317 $odfHandler =
new Odf(
320 'PATH_TO_TMP' => $conf->adherent->dir_temp,
322 'DELIMITER_LEFT' =>
'{',
323 'DELIMITER_RIGHT' =>
'}'
327 $this->error = $e->getMessage();
338 $array_thirdparty_contact = array();
339 if ($usecontact && is_object($contactobject)) {
343 $tmparray = array_merge($array_member, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
349 'outputlangs' => $outputlangs,
350 'substitutionarray' => &$tmparray
352 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
353 foreach ($tmparray as $key => $value) {
355 if (preg_match(
'/logo$/', $key)) {
357 if (file_exists($value)) {
358 $odfHandler->setImage($key, $value);
360 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
364 $odfHandler->setVars($key, $value,
true,
'UTF-8');
366 }
catch (OdfException $e) {
372 $tmparray = $outputlangs->get_translations_for_substitutions();
373 foreach ($tmparray as $key => $value) {
375 $odfHandler->setVars($key, $value,
true,
'UTF-8');
376 }
catch (OdfException $e) {
382 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
383 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
388 $odfHandler->exportAsAttachedPDF($file);
390 $this->error = $e->getMessage();
396 $odfHandler->saveToDisk($file);
398 $this->error = $e->getMessage();
404 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
410 $this->result = array(
'fullpath' => $file);
414 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);