90 public function info($langs)
95 $langs->loadLangs(array(
"companies",
"errors"));
97 $form =
new Form($this->db);
100 $texte .=
'<!-- form for option of ODT templates -->';
101 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
102 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
103 $texte .=
'<input type="hidden" name="page_y" value="">';
104 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
105 $texte .=
'<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">';
106 $texte .=
'<table class="nobordernopadding centpercent">';
109 $texte .=
'<tr><td>';
110 $texttitle = $langs->trans(
"ListOfDirectories");
111 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'COMPANY_ADDON_PDF_ODT_PATH'))));
112 $listoffiles = array();
113 foreach ($listofdir as $key => $tmpdir) {
114 $tmpdir = trim($tmpdir);
115 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
117 unset($listofdir[$key]);
120 if (!is_dir($tmpdir)) {
121 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
123 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0,
true);
124 if (count($tmpfiles)) {
125 $listoffiles = array_merge($listoffiles, $tmpfiles);
129 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
130 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
132 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
133 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
136 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
137 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
139 $texte .=
'<textarea class="flat" cols="60" name="value1">';
141 $texte .=
'</textarea>';
144 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
145 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
149 $texte .=
'</div></div>';
152 $texte .=
'<input type="hidden" name="value1" value="COMPANY_ADDON_PDF_ODT_PATH">';
156 $nbofiles = count($listoffiles);
158 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
166 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
168 foreach ($listoffiles as $file) {
169 $texte .=
'- '.$file[
'name'].
' <a class="reposition" href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=thirdparties/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
170 $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>';
176 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
178 $maxmin = $maxfilesizearray[
'maxmin'];
180 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
182 $texte .=
' <input type="file" name="uploadfile">';
183 $texte .=
'<input type="hidden" value="COMPANY_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
184 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
190 $texte .=
'</table>';
208 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
211 global $user, $langs, $conf, $mysoc, $hookmanager;
214 if (empty($srctemplatepath)) {
215 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
220 if (!is_object($hookmanager)) {
221 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
224 $hookmanager->initHooks(array(
'odtgeneration'));
226 if (!is_object($outputlangs)) {
227 $outputlangs = $langs;
229 $sav_charset_output = $outputlangs->charset_output;
230 $outputlangs->charset_output =
'UTF-8';
233 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
235 if ($conf->societe->multidir_output[
$object->entity]) {
236 $dir = $conf->societe->multidir_output[
$object->entity];
238 if (!preg_match(
'/specimen/i', $objectref)) {
239 $dir .=
"/".$objectref;
242 if (!file_exists($dir)) {
244 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
249 if (file_exists($dir)) {
251 $newfile = basename($srctemplatepath);
252 $newfiletmp = preg_replace(
'/\.od(s|t)/i',
'', $newfile);
253 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
254 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
256 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
259 $newfiletmp = preg_replace(
'/__+/',
'_', $newfiletmp);
263 if ($format ==
'1') {
264 $format =
'%Y%m%d%H%M%S';
268 $filename = $newfiletmp .
'.' . $newfileformat;
270 $file = $dir .
'/' . $filename;
271 $object->builddoc_filename = $filename;
272 $object->context[
'builddoc_filename'] = $filename;
281 if (!is_writable($conf->societe->multidir_temp[
$object->entity])) {
282 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->societe->multidir_temp[
$object->entity]);
283 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
288 require_once ODTPHP_PATH.
'odf.php';
290 $odfHandler =
new Odf(
293 'PATH_TO_TMP' => $conf->societe->multidir_temp[
$object->entity],
294 'ZIP_PROXY' =>
'PclZipProxy',
295 'DELIMITER_LEFT' =>
'{',
296 'DELIMITER_RIGHT' =>
'}'
300 $this->error = $e->getMessage();
307 $contact_arrray = array();
309 $sql =
"SELECT p.rowid";
310 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as p";
311 $sql .=
" WHERE p.fk_soc = ".((int)
$object->id);
313 $result = $this->db->query($sql);
314 $num = $this->db->num_rows($result);
317 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
320 $contactstatic =
new Contact($this->db);
323 $obj = $this->db->fetch_object($result);
325 $contact_arrray[$i] = $obj->rowid;
329 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
330 $foundtagforlines = 1;
332 $listlines = $odfHandler->setSegment(
'companycontacts');
333 }
catch (OdfExceptionSegmentNotFound $e) {
335 $foundtagforlines = 0;
338 if ($foundtagforlines) {
339 foreach ($contact_arrray as $array_key => $contact_id) {
340 $res_contact = $contactstatic->fetch($contact_id);
341 if ((
int) $res_contact > 0) {
343 foreach ($tmparray as $key => $val) {
345 $listlines->setVars($key, $val,
true,
'UTF-8');
346 }
catch (SegmentException $e) {
352 $this->error = $contactstatic->error;
357 $odfHandler->mergeSegment($listlines);
358 }
catch (OdfException $e) {
359 $this->error = $e->getMessage();
372 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other);
377 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
378 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
381 foreach ($tmparray as $key => $value) {
383 if (preg_match(
'/logo$/', $key)) {
384 if (file_exists($value)) {
385 $odfHandler->setImage($key, $value);
387 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
390 $odfHandler->setVars($key, $value,
true,
'UTF-8');
392 }
catch (OdfException $e) {
399 $tmparray = $outputlangs->get_translations_for_substitutions();
400 foreach ($tmparray as $key => $value) {
402 $odfHandler->setVars($key, $value,
true,
'UTF-8');
403 }
catch (OdfException $e) {
409 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
410 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
415 $odfHandler->exportAsAttachedPDF($file);
417 $this->error = $e->getMessage();
423 $odfHandler->creator = $user->getFullName($outputlangs);
424 $odfHandler->title =
$object->builddoc_filename;
425 $odfHandler->subject =
$object->builddoc_filename;
428 $odfHandler->userdefined[
'dol_id'] =
$object->id;
429 $odfHandler->userdefined[
'dol_element'] =
$object->element;
432 $odfHandler->saveToDisk($file);
434 $this->error = $e->getMessage();
439 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
440 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
446 $this->result = array(
'fullpath'=>$file);
450 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
455 $this->error =
'UnknownError';