88 public function info($langs)
93 $langs->loadLangs(array(
"companies",
"errors"));
95 $form =
new Form($this->db);
98 $texte .=
'<!-- form for option of ODT templates -->';
99 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
100 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
101 $texte .=
'<input type="hidden" name="page_y" value="">';
102 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
103 $texte .=
'<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">';
104 $texte .=
'<table class="nobordernopadding centpercent">';
107 $texte .=
'<tr><td>';
108 $texttitle = $langs->trans(
"ListOfDirectories");
109 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->COMPANY_ADDON_PDF_ODT_PATH)));
110 $listoffiles = array();
111 foreach ($listofdir as $key => $tmpdir) {
112 $tmpdir = trim($tmpdir);
113 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
115 unset($listofdir[$key]);
118 if (!is_dir($tmpdir)) {
119 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
121 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0,
true);
122 if (count($tmpfiles)) {
123 $listoffiles = array_merge($listoffiles, $tmpfiles);
127 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
128 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
130 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
131 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
133 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
134 $texte .=
'<table><tr><td>';
135 $texte .=
'<textarea class="flat" cols="60" name="value1">';
137 $texte .=
'</textarea>';
139 $texte .=
'<td class="center"> ';
140 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
143 $texte .=
'</table>';
146 $nbofiles = count($listoffiles);
148 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
156 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
158 foreach ($listoffiles as $file) {
159 $texte .=
'- '.$file[
'name'].
' <a class="reposition" href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=thirdparties/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
160 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=COMPANY_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
166 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
168 $maxmin = $maxfilesizearray[
'maxmin'];
170 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
172 $texte .=
' <input type="file" name="uploadfile">';
173 $texte .=
'<input type="hidden" value="COMPANY_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
174 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
180 $texte .=
'</table>';
198 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
201 global $user, $langs, $conf, $mysoc, $hookmanager;
204 if (empty($srctemplatepath)) {
205 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
210 if (!is_object($hookmanager)) {
211 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
214 $hookmanager->initHooks(array(
'odtgeneration'));
217 if (!is_object($outputlangs)) {
218 $outputlangs = $langs;
220 $sav_charset_output = $outputlangs->charset_output;
221 $outputlangs->charset_output =
'UTF-8';
224 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
226 if ($conf->societe->multidir_output[$object->entity]) {
227 $dir = $conf->societe->multidir_output[$object->entity];
229 if (!preg_match(
'/specimen/i', $objectref)) {
230 $dir .=
"/".$objectref;
233 if (!file_exists($dir)) {
235 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
240 if (file_exists($dir)) {
242 $newfile = basename($srctemplatepath);
243 $newfiletmp = preg_replace(
'/\.od(s|t)/i',
'', $newfile);
244 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
245 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
247 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
250 $newfiletmp = preg_replace(
'/__+/',
'_', $newfiletmp);
254 if ($format ==
'1') {
255 $format =
'%Y%m%d%H%M%S';
259 $filename = $newfiletmp .
'.' . $newfileformat;
261 $file = $dir .
'/' . $filename;
262 $object->builddoc_filename = $filename;
270 dol_mkdir($conf->societe->multidir_temp[$object->entity]);
271 if (!is_writable($conf->societe->multidir_temp[$object->entity])) {
272 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->societe->multidir_temp[$object->entity]);
273 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
278 require_once ODTPHP_PATH.
'odf.php';
280 $odfHandler =
new Odf(
283 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity],
285 'DELIMITER_LEFT' =>
'{',
286 'DELIMITER_RIGHT' =>
'}'
290 $this->error = $e->getMessage();
297 $contact_arrray = array();
299 $sql =
"SELECT p.rowid";
300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as p";
301 $sql .=
" WHERE p.fk_soc = ".((int) $object->id);
303 $result = $this->db->query($sql);
304 $num = $this->db->num_rows($result);
307 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
310 $contactstatic =
new Contact($this->db);
313 $obj = $this->db->fetch_object($result);
315 $contact_arrray[$i] = $obj->rowid;
319 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
321 $listlines = $odfHandler->setSegment(
'companycontacts');
323 foreach ($contact_arrray as $array_key => $contact_id) {
324 $res_contact = $contactstatic->fetch($contact_id);
325 if ((
int) $res_contact > 0) {
327 foreach ($tmparray as $key => $val) {
329 $listlines->setVars($key, $val,
true,
'UTF-8');
330 }
catch (OdfException $e) {
332 }
catch (SegmentException $e) {
338 $this->error = $contactstatic->error;
342 $odfHandler->mergeSegment($listlines);
343 }
catch (OdfException $e) {
344 $this->error = $e->getMessage();
356 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other);
361 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
362 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
365 foreach ($tmparray as $key => $value) {
367 if (preg_match(
'/logo$/', $key)) {
368 if (file_exists($value)) {
369 $odfHandler->setImage($key, $value);
371 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
374 $odfHandler->setVars($key, $value,
true,
'UTF-8');
376 }
catch (OdfException $e) {
383 $tmparray = $outputlangs->get_translations_for_substitutions();
384 foreach ($tmparray as $key => $value) {
386 $odfHandler->setVars($key, $value,
true,
'UTF-8');
387 }
catch (OdfException $e) {
393 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
394 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
399 $odfHandler->exportAsAttachedPDF($file);
401 $this->error = $e->getMessage();
407 $odfHandler->creator = $user->getFullName($outputlangs);
408 $odfHandler->title = $object->builddoc_filename;
409 $odfHandler->subject = $object->builddoc_filename;
412 $odfHandler->userdefined[
'dol_id'] = $object->id;
413 $odfHandler->userdefined[
'dol_element'] = $object->element;
416 $odfHandler->saveToDisk($file);
418 $this->error = $e->getMessage();
423 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
424 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
430 $this->result = array(
'fullpath'=>$file);
434 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
439 $this->error =
'UnknownError';