96 public function info($langs)
101 $langs->loadLangs(array(
"companies",
"errors"));
103 $form =
new Form($this->db);
106 $texte .=
'<!-- form for option of ODT templates -->';
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="COMPANY_ADDON_PDF_ODT_PATH">';
112 $texte .=
'<table class="nobordernopadding centpercent">';
115 $texte .=
'<tr><td>';
116 $texttitle = $langs->trans(
"ListOfDirectories");
117 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'COMPANY_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),
'');
129 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0, 1);
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");
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;">';
145 $texte .=
'<textarea class="flat" cols="60" name="value1">';
147 $texte .=
'</textarea>';
150 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
151 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
155 $texte .=
'</div></div>';
158 $texte .=
'<input type="hidden" name="value1" value="COMPANY_ADDON_PDF_ODT_PATH">';
162 $nbofiles = count($listoffiles);
164 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
172 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
174 foreach ($listoffiles as $file) {
175 $texte .=
'- '.$file[
'name'].
' <a class="reposition" href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=thirdparties/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
176 $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>';
182 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
184 $maxmin = $maxfilesizearray[
'maxmin'];
186 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
188 $texte .=
' <input type="file" name="uploadfile">';
189 $texte .=
'<input type="hidden" value="COMPANY_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
190 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
196 $texte .=
'</table>';
214 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
217 global $user, $langs,
$conf, $mysoc, $hookmanager;
220 if (empty($srctemplatepath)) {
221 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
226 if (!is_object($hookmanager)) {
227 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
230 $hookmanager->initHooks(array(
'odtgeneration'));
232 if (!is_object($outputlangs)) {
233 $outputlangs = $langs;
235 $sav_charset_output = $outputlangs->charset_output;
236 $outputlangs->charset_output =
'UTF-8';
239 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
242 $dir =
$conf->societe->multidir_output[
$object->entity];
244 if (!preg_match(
'/specimen/i', $objectref)) {
245 $dir .=
"/".$objectref;
248 if (!file_exists($dir)) {
250 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
255 if (file_exists($dir)) {
257 $newfile = basename($srctemplatepath);
258 $newfiletmp = preg_replace(
'/\.od(s|t)/i',
'', $newfile);
259 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
260 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
262 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
265 $newfiletmp = preg_replace(
'/__+/',
'_', $newfiletmp);
269 if ($format ==
'1') {
270 $format =
'%Y%m%d%H%M%S';
274 $filename = $newfiletmp .
'.' . $newfileformat;
276 $file = $dir .
'/' . $filename;
277 $object->builddoc_filename = $filename;
278 $object->context[
'builddoc_filename'] = $filename;
287 if (!is_writable(
$conf->societe->multidir_temp[
$object->entity])) {
288 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->societe->multidir_temp[
$object->entity]);
289 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
294 require_once ODTPHP_PATH.
'odf.php';
296 $odfHandler =
new Odf(
299 'PATH_TO_TMP' =>
$conf->societe->multidir_temp[
$object->entity],
301 'DELIMITER_LEFT' =>
'{',
302 'DELIMITER_RIGHT' =>
'}'
306 $this->error = $e->getMessage();
313 $contact_arrray = array();
315 $sql =
"SELECT p.rowid";
316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as p";
317 $sql .=
" WHERE p.fk_soc = ".((int)
$object->id);
319 $result = $this->db->query($sql);
320 $num = $this->db->num_rows($result);
323 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
326 $contactstatic =
new Contact($this->db);
329 $obj = $this->db->fetch_object($result);
331 $contact_arrray[$i] = $obj->rowid;
335 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
336 $foundtagforlines = 1;
338 $listlines = $odfHandler->setSegment(
'companycontacts');
339 }
catch (OdfExceptionSegmentNotFound $e) {
341 $foundtagforlines = 0;
344 if ($foundtagforlines) {
345 foreach ($contact_arrray as $array_key => $contact_id) {
346 $res_contact = $contactstatic->fetch($contact_id);
347 if ((
int) $res_contact > 0) {
349 foreach ($tmparray as $key => $val) {
351 $listlines->setVars($key, $val,
true,
'UTF-8');
352 }
catch (SegmentException $e) {
358 $this->error = $contactstatic->error;
363 $odfHandler->mergeSegment($listlines);
364 }
catch (OdfException $e) {
365 $this->error = $e->getMessage();
378 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other);
383 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
384 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
387 foreach ($tmparray as $key => $value) {
389 if (preg_match(
'/logo$/', $key)) {
390 if (file_exists($value)) {
391 $odfHandler->setImage($key, $value);
393 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
396 $odfHandler->setVars($key, $value,
true,
'UTF-8');
398 }
catch (OdfException $e) {
405 $tmparray = $outputlangs->get_translations_for_substitutions();
406 foreach ($tmparray as $key => $value) {
408 $odfHandler->setVars($key, $value,
true,
'UTF-8');
409 }
catch (OdfException $e) {
415 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
416 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
421 $odfHandler->exportAsAttachedPDF($file);
423 $this->error = $e->getMessage();
429 $odfHandler->creator = $user->getFullName($outputlangs);
430 $odfHandler->title =
$object->builddoc_filename;
431 $odfHandler->subject =
$object->builddoc_filename;
434 $odfHandler->userdefined[
'dol_id'] =
$object->id;
435 $odfHandler->userdefined[
'dol_element'] =
$object->element;
438 $odfHandler->saveToDisk($file);
440 $this->error = $e->getMessage();
445 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
446 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
452 $this->result = array(
'fullpath' => $file);
456 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
461 $this->error =
'UnknownError';