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'));
216 if (!is_object($outputlangs)) {
217 $outputlangs = $langs;
219 $sav_charset_output = $outputlangs->charset_output;
220 $outputlangs->charset_output =
'UTF-8';
223 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
225 if ($conf->societe->multidir_output[$object->entity]) {
226 $dir = $conf->societe->multidir_output[$object->entity];
228 if (!preg_match(
'/specimen/i', $objectref)) {
229 $dir .=
"/".$objectref;
232 if (!file_exists($dir)) {
234 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
239 if (file_exists($dir)) {
241 $newfile = basename($srctemplatepath);
242 $newfiletmp = preg_replace(
'/\.od(s|t)/i',
'', $newfile);
243 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
244 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
246 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
249 $newfiletmp = preg_replace(
'/__+/',
'_', $newfiletmp);
253 if ($format ==
'1') {
254 $format =
'%Y%m%d%H%M%S';
258 $filename = $newfiletmp .
'.' . $newfileformat;
260 $file = $dir .
'/' . $filename;
261 $object->builddoc_filename = $filename;
269 dol_mkdir($conf->societe->multidir_temp[$object->entity]);
270 if (!is_writable($conf->societe->multidir_temp[$object->entity])) {
271 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->societe->multidir_temp[$object->entity]);
272 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
277 require_once ODTPHP_PATH.
'odf.php';
279 $odfHandler =
new Odf(
282 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity],
284 'DELIMITER_LEFT' =>
'{',
285 'DELIMITER_RIGHT' =>
'}'
289 $this->error = $e->getMessage();
296 $contact_arrray = array();
298 $sql =
"SELECT p.rowid";
299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as p";
300 $sql .=
" WHERE p.fk_soc = ".((int) $object->id);
302 $result = $this->db->query($sql);
303 $num = $this->db->num_rows($result);
306 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
309 $contactstatic =
new Contact($this->db);
312 $obj = $this->db->fetch_object($result);
314 $contact_arrray[$i] = $obj->rowid;
318 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
320 $listlines = $odfHandler->setSegment(
'companycontacts');
322 foreach ($contact_arrray as $array_key => $contact_id) {
323 $res_contact = $contactstatic->fetch($contact_id);
324 if ((
int) $res_contact > 0) {
326 foreach ($tmparray as $key => $val) {
328 $listlines->setVars($key, $val,
true,
'UTF-8');
329 }
catch (OdfException $e) {
331 }
catch (SegmentException $e) {
337 $this->error = $contactstatic->error;
341 $odfHandler->mergeSegment($listlines);
342 }
catch (OdfException $e) {
343 $this->error = $e->getMessage();
355 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other);
360 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
361 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
364 foreach ($tmparray as $key => $value) {
366 if (preg_match(
'/logo$/', $key)) {
367 if (file_exists($value)) {
368 $odfHandler->setImage($key, $value);
370 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
373 $odfHandler->setVars($key, $value,
true,
'UTF-8');
375 }
catch (OdfException $e) {
382 $tmparray = $outputlangs->get_translations_for_substitutions();
383 foreach ($tmparray as $key => $value) {
385 $odfHandler->setVars($key, $value,
true,
'UTF-8');
386 }
catch (OdfException $e) {
392 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
393 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
398 $odfHandler->exportAsAttachedPDF($file);
400 $this->error = $e->getMessage();
406 $odfHandler->creator = $user->getFullName($outputlangs);
407 $odfHandler->title = $object->builddoc_filename;
408 $odfHandler->subject = $object->builddoc_filename;
411 $odfHandler->userdefined[
'dol_id'] = $object->id;
412 $odfHandler->userdefined[
'dol_element'] = $object->element;
415 $odfHandler->saveToDisk($file);
417 $this->error = $e->getMessage();
422 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
423 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
429 $this->result = array(
'fullpath'=>$file);
433 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
438 $this->error =
'UnknownError';