54 global $conf, $langs, $mysoc;
57 $langs->loadLangs(array(
"main",
"companies"));
60 $this->
name =
"ODT templates";
61 $this->
description = $langs->trans(
"DocumentModelOdt");
62 $this->scandir =
'MEMBER_ADDON_PDF_ODT_PATH';
66 $this->page_largeur = 0;
67 $this->page_hauteur = 0;
68 $this->format = array($this->page_largeur, $this->page_hauteur);
69 $this->marge_gauche = 0;
70 $this->marge_droite = 0;
71 $this->marge_haute = 0;
72 $this->marge_basse = 0;
74 $this->option_logo = 1;
75 $this->option_tva = 0;
76 $this->option_modereg = 0;
77 $this->option_condreg = 0;
78 $this->option_multilang = 1;
79 $this->option_escompte = 0;
80 $this->option_credit_note = 0;
81 $this->option_freetext = 1;
82 $this->option_draft_watermark = 0;
85 $this->emetteur = $mysoc;
86 if (!$this->emetteur->country_code) {
87 $this->emetteur->country_code = substr($langs->defaultlang, -2);
98 public function info($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="MEMBER_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(
getDolGlobalString(
'MEMBER_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 if (count($listofdir)) {
153 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
155 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
157 foreach ($listoffiles as $file) {
158 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=members/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
159 $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>';
165 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
167 $maxmin = $maxfilesizearray[
'maxmin'];
169 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
171 $texte .=
' <input type="file" name="uploadfile">';
172 $texte .=
'<input type="hidden" value="MEMBER_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
173 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
179 $texte .=
'</table>';
197 public function write_file(
$object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
200 global $user, $langs, $conf, $mysoc, $hookmanager;
202 if (empty($srctemplatepath)) {
203 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
208 if (!is_object($hookmanager)) {
209 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
212 $hookmanager->initHooks(array(
'odtgeneration'));
215 if (!is_object($outputlangs)) {
216 $outputlangs = $langs;
218 $sav_charset_output = $outputlangs->charset_output;
219 $outputlangs->charset_output =
'UTF-8';
222 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
224 if ($conf->adherent->dir_output) {
238 $dir = $conf->adherent->dir_output;
240 if (!preg_match(
'/specimen/i', $objectref)) {
241 $dir .=
"/".$objectref;
243 $file = $dir.
"/".$objectref.
".odt";
245 if (!file_exists($dir)) {
247 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
252 if (file_exists($dir)) {
254 $newfile = basename($srctemplatepath);
255 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
256 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
257 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
259 $newfiletmp = $objectref .
'_' . $newfiletmp;
262 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
265 if ($format ==
'1') {
266 $format =
'%Y%m%d%H%M%S';
270 $filename = $newfiletmp .
'.' . $newfileformat;
272 $file = $dir .
'/' . $filename;
279 if (!is_writable($conf->adherent->dir_temp)) {
280 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->adherent->dir_temp);
281 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
287 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
288 if (count($arrayidcontact) > 0) {
290 $result =
$object->fetch_contact($arrayidcontact[0]);
294 if (!empty($usecontact)) {
296 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
297 $object->contact->fetch_thirdparty();
298 $socobject =
$object->contact->thirdparty;
299 $contactobject =
$object->contact;
301 $socobject =
$object->thirdparty;
303 $contactobject =
$object->contact;
306 $socobject =
$object->thirdparty;
310 require_once ODTPHP_PATH.
'odf.php';
312 $odfHandler =
new Odf(
315 'PATH_TO_TMP' => $conf->adherent->dir_temp,
316 'ZIP_PROXY' =>
'PclZipProxy',
317 'DELIMITER_LEFT' =>
'{',
318 'DELIMITER_RIGHT' =>
'}'
322 $this->error = $e->getMessage();
333 $array_thirdparty_contact = array();
334 if ($usecontact && is_object($contactobject)) {
338 $tmparray = array_merge($array_member, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
344 'outputlangs'=>$outputlangs,
345 'substitutionarray'=>&$tmparray
347 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
348 foreach ($tmparray as $key => $value) {
350 if (preg_match(
'/logo$/', $key)) {
352 if (file_exists($value)) {
353 $odfHandler->setImage($key, $value);
355 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
359 $odfHandler->setVars($key, $value,
true,
'UTF-8');
361 }
catch (OdfException $e) {
367 $tmparray = $outputlangs->get_translations_for_substitutions();
368 foreach ($tmparray as $key => $value) {
370 $odfHandler->setVars($key, $value,
true,
'UTF-8');
371 }
catch (OdfException $e) {
377 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs);
378 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
383 $odfHandler->exportAsAttachedPDF($file);
385 $this->error = $e->getMessage();
391 $odfHandler->saveToDisk($file);
393 $this->error = $e->getMessage();
399 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
405 $this->result = array(
'fullpath'=>$file);
409 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);