31require_once DOL_DOCUMENT_ROOT .
'/core/modules/asset/modules_asset.php';
32require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/doc.lib.php';
54 public $phpmin = array(7, 0);
59 public $version =
'dolibarr';
71 $langs->loadLangs(array(
"main",
"companies"));
74 $this->
name =
"ODT templates";
75 $this->
description = $langs->trans(
"DocumentModelOdt");
76 $this->scandir =
'ASSET_ASSET_ADDON_PDF_ODT_PATH';
80 $this->page_largeur = 0;
81 $this->page_hauteur = 0;
82 $this->format = array($this->page_largeur, $this->page_hauteur);
83 $this->marge_gauche = 0;
84 $this->marge_droite = 0;
85 $this->marge_haute = 0;
86 $this->marge_basse = 0;
88 $this->option_logo = 1;
89 $this->option_tva = 0;
90 $this->option_modereg = 0;
91 $this->option_condreg = 0;
92 $this->option_multilang = 1;
93 $this->option_escompte = 0;
94 $this->option_credit_note = 0;
95 $this->option_freetext = 1;
96 $this->option_draft_watermark = 0;
104 if (!$this->emetteur->country_code) {
105 $this->emetteur->country_code = substr($langs->defaultlang, -2);
121 $langs->loadLangs(array(
"errors",
"companies"));
123 $form =
new Form($this->db);
126 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
127 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
128 $texte .=
'<input type="hidden" name="page_y" value="">';
129 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
130 $texte .=
'<input type="hidden" name="param1" value="ASSET_ASSET_ADDON_PDF_ODT_PATH">';
131 $texte .=
'<table class="nobordernopadding centpercent">';
134 $texte .=
'<tr><td>';
135 $texttitle = $langs->trans(
"ListOfDirectories");
136 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'ASSET_ASSET_ADDON_PDF_ODT_PATH'))));
137 $listoffiles = array();
138 foreach ($listofdir as $key => $tmpdir) {
139 $tmpdir = trim($tmpdir);
140 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
142 unset($listofdir[$key]);
145 if (!is_dir($tmpdir)) {
146 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
148 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
149 if (count($tmpfiles)) {
150 $listoffiles = array_merge($listoffiles, $tmpfiles);
154 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
155 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
157 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
158 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
161 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
162 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
163 $texte .=
'<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
165 $texte .=
'</textarea>';
166 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
167 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dolPrintHTMLForAttribute($langs->trans(
"Modify")).
'">';
168 $texte .=
'<br></div></div>';
171 $texte .=
'<input type="hidden" name="value1" value="ASSET_ASSET_ADDON_PDF_ODT_PATH">';
175 $nbofiles = count($listoffiles);
177 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
179 $texte .= count($listoffiles);
185 $texte .=
'<div id="div_'.get_class($this).
'" class="hidden">';
187 foreach ($listoffiles as $file) {
188 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=asset_asset/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
189 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=ASSET_ASSET_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
196 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
198 $maxmin = $maxfilesizearray[
'maxmin'];
200 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
202 $texte .=
' <input type="file" name="uploadfile">';
203 $texte .=
'<input type="hidden" value="MYMODULE_MYOBJECT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
204 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
211 $texte .=
'</table>';
229 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
235 if (empty($srctemplatepath)) {
236 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
241 if (!is_object($hookmanager)) {
242 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
245 $hookmanager->initHooks(array(
'odtgeneration'));
248 if (!is_object($outputlangs)) {
249 $outputlangs = $langs;
251 $sav_charset_output = $outputlangs->charset_output;
252 $outputlangs->charset_output =
'UTF-8';
254 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
256 if (
$conf->asset->dir_output) {
272 if (!preg_match(
'/specimen/i', $objectref)) {
273 $dir .=
"/".$objectref;
275 $file = $dir.
"/".$objectref.
".odt";
277 if (!file_exists($dir)) {
279 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
284 if (file_exists($dir)) {
286 $newfile = basename($srctemplatepath);
287 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
288 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
289 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
290 $newfiletmp = $objectref.
'_'.$newfiletmp;
293 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
296 if ($format ==
'1') {
297 $format =
'%Y%m%d%H%M%S';
301 $filename = $newfiletmp.
'.'.$newfileformat;
303 $file = $dir.
'/'.$filename;
310 if (!is_writable(
$conf->asset->dir_temp)) {
311 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->asset->dir_temp);
312 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
318 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
319 if (count($arrayidcontact) > 0) {
321 $result =
$object->fetch_contact($arrayidcontact[0]);
325 $contactobject =
null;
326 if (!empty($usecontact)) {
329 $object->contact->fetch_thirdparty();
330 $socobject =
$object->contact->thirdparty;
331 $contactobject =
$object->contact;
333 $socobject =
$object->thirdparty;
335 $contactobject =
$object->contact;
338 $socobject =
$object->thirdparty;
342 $substitutionarray = array(
343 '__FROM_NAME__' => $this->emetteur->name,
344 '__FROM_EMAIL__' => $this->emetteur->email,
345 '__TOTAL_TTC__' =>
$object->total_ttc,
346 '__TOTAL_HT__' =>
$object->total_ht,
347 '__TOTAL_VAT__' =>
$object->total_tva
351 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
352 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
356 $paramfreetext =
'ORDER_FREE_TEXT';
362 require_once ODTPHP_PATH.
'odf.php';
364 $odfHandler =
new Odf(
367 'PATH_TO_TMP' =>
$conf->asset->dir_temp,
369 'DELIMITER_LEFT' =>
'{',
370 'DELIMITER_RIGHT' =>
'}'
374 $this->error = $e->getMessage();
384 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
385 }
catch (OdfException $e) {
390 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null,
$object);
392 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
398 $array_thirdparty_contact = array();
399 if ($usecontact && is_object($contactobject)) {
403 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
407 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
408 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
417 foreach ($tmparray as $key => $value) {
419 if (preg_match(
'/logo$/', $key)) {
421 if (file_exists($value)) {
422 $odfHandler->setImage($key, $value, $ratio);
424 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
428 $odfHandler->setVars($key, $value,
true,
'UTF-8');
430 }
catch (OdfException $e) {
472 $tmparray = $outputlangs->get_translations_for_substitutions();
473 foreach ($tmparray as $key => $value) {
475 $odfHandler->setVars($key, $value,
true,
'UTF-8');
476 }
catch (OdfException $e) {
483 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
484 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
489 $odfHandler->exportAsAttachedPDF($file);
491 $this->error = $e->getMessage();
497 $odfHandler->saveToDisk($file);
499 $this->error = $e->getMessage();
505 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
506 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
512 $this->result = array(
'fullpath' => $file);
516 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive=1)
Define array with couple substitution key => substitution value @phpstan-template T.
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_contact($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
get_substitutionarray_other($outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_thirdparty($object, $outputlangs, $array_key='company')
Define array with couple substitution key => substitution value For example {company_name}...
get_substitutionarray_user($user, $outputlangs)
Define array with couple substitution key => substitution value.
Parent class for documents models.
Class to build documents using ODF templates generator.
info($langs)
Return description of a module.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.
getMaxFileSizeArray()
Return the max allowed for file upload.