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");
129 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
130 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
132 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
133 $texte .=
'<table><tr><td>';
134 $texte .=
'<textarea class="flat" cols="60" name="value1">';
135 $texte .= $conf->global->COMPANY_ADDON_PDF_ODT_PATH;
136 $texte .=
'</textarea>';
138 $texte .=
'<td class="center"> ';
139 $texte .=
'<input type="submit" class="button small reposition" name="modify" value="'.$langs->trans(
"Modify").
'">';
142 $texte .=
'</table>';
145 $nbofiles = count($listoffiles);
146 if (!empty($conf->global->COMPANY_ADDON_PDF_ODT_PATH)) {
147 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
155 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
157 foreach ($listoffiles as $file) {
158 $texte .=
'- '.$file[
'name'].
' <a class="reposition" href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=thirdparties/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
159 $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>';
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="COMPANY_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
173 $texte .=
'<input type="submit" class="button small reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
177 $texte .=
'<td rowspan="2" class="tdtop hideonsmartphone">';
178 $texte .=
'<span class="opacitymedium">';
179 $texte .= $langs->trans(
"ExampleOfDirectoriesForModelGen");
184 $texte .=
'</table>';
202 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
205 global $user, $langs, $conf, $mysoc, $hookmanager;
208 if (empty($srctemplatepath)) {
209 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
214 if (!is_object($hookmanager)) {
215 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
218 $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",
"dict",
"companies",
"projects"));
229 if ($conf->societe->multidir_output[$object->entity]) {
230 $dir = $conf->societe->multidir_output[$object->entity];
232 if (!preg_match(
'/specimen/i', $objectref)) {
233 $dir .=
"/".$objectref;
236 if (!file_exists($dir)) {
238 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
243 if (file_exists($dir)) {
245 $newfile = basename($srctemplatepath);
246 $newfiletmp = preg_replace(
'/\.od(s|t)/i',
'', $newfile);
247 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
248 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
250 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
251 if (!empty($conf->global->MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME)) {
253 $newfiletmp = preg_replace(
'/__+/',
'_', $newfiletmp);
257 if ($format ==
'1') {
258 $format =
'%Y%m%d%H%M%S';
262 $filename = $newfiletmp .
'.' . $newfileformat;
264 $file = $dir .
'/' . $filename;
265 $object->builddoc_filename = $filename;
273 dol_mkdir($conf->societe->multidir_temp[$object->entity]);
274 if (!is_writable($conf->societe->multidir_temp[$object->entity])) {
275 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->societe->multidir_temp[$object->entity]);
276 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
281 require_once ODTPHP_PATH.
'odf.php';
283 $odfHandler =
new Odf(
286 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity],
287 'ZIP_PROXY' =>
'PclZipProxy',
288 'DELIMITER_LEFT' =>
'{',
289 'DELIMITER_RIGHT' =>
'}'
293 $this->error = $e->getMessage();
300 $contact_arrray = array();
302 $sql =
"SELECT p.rowid";
303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as p";
304 $sql .=
" WHERE p.fk_soc = ".((int) $object->id);
306 $result = $this->db->query($sql);
307 $num = $this->db->num_rows($result);
310 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
313 $contactstatic =
new Contact($this->db);
316 $obj = $this->db->fetch_object($result);
318 $contact_arrray[$i] = $obj->rowid;
322 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
324 $listlines = $odfHandler->setSegment(
'companycontacts');
326 foreach ($contact_arrray as $array_key => $contact_id) {
327 $res_contact = $contactstatic->fetch($contact_id);
328 if ((
int) $res_contact > 0) {
330 foreach ($tmparray as $key => $val) {
332 $listlines->setVars($key, $val,
true,
'UTF-8');
333 }
catch (OdfException $e) {
335 }
catch (SegmentException $e) {
341 $this->error = $contactstatic->error;
345 $odfHandler->mergeSegment($listlines);
346 }
catch (OdfException $e) {
347 $this->error = $e->getMessage();
359 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other);
364 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
365 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
368 foreach ($tmparray as $key => $value) {
370 if (preg_match(
'/logo$/', $key)) {
371 if (file_exists($value)) {
372 $odfHandler->setImage($key, $value);
374 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
378 $odfHandler->setVars($key, $value,
true,
'UTF-8');
380 }
catch (OdfException $e) {
387 $tmparray = $outputlangs->get_translations_for_substitutions();
388 foreach ($tmparray as $key => $value) {
390 $odfHandler->setVars($key, $value,
true,
'UTF-8');
391 }
catch (OdfException $e) {
397 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
398 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
401 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
403 $odfHandler->exportAsAttachedPDF($file);
405 $this->error = $e->getMessage();
411 $odfHandler->creator = $user->getFullName($outputlangs);
412 $odfHandler->title = $object->builddoc_filename;
413 $odfHandler->subject = $object->builddoc_filename;
415 if (!empty($conf->global->ODT_ADD_DOLIBARR_ID)) {
416 $odfHandler->userdefined[
'dol_id'] = $object->id;
417 $odfHandler->userdefined[
'dol_element'] = $object->element;
420 $odfHandler->saveToDisk($file);
422 $this->error = $e->getMessage();
427 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
428 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
434 $this->result = array(
'fullpath'=>$file);
438 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
443 $this->error =
'UnknownError';