dolibarr 18.0.6
modules_fichinter.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2019 Philippe Grand <philippe.grand@atoo-net.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
29require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
30
31
36{
40 public $error = '';
41
42
43 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
51 public static function liste_modeles($db, $maxfilenamelength = 0)
52 {
53 // phpcs:enable
54 $type = 'ficheinter';
55 $list = array();
56
57 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
58 $list = getListOfModels($db, $type, $maxfilenamelength);
59
60 return $list;
61 }
62}
63
64
69{
73 public $error = '';
74
75 public $version;
76
77
83 public function isEnabled()
84 {
85 return true;
86 }
87
93 public function info()
94 {
95 global $langs;
96 $langs->load("ficheinter");
97 return $langs->trans("NoDescription");
98 }
99
105 public function getExample()
106 {
107 global $langs;
108 $langs->load("ficheinter");
109 return $langs->trans("NoExample");
110 }
111
118 public function canBeActivated()
119 {
120 return true;
121 }
122
130 public function getNextValue($objsoc = 0, $object = '')
131 {
132 global $langs;
133 return $langs->trans("NotAvailable");
134 }
135
141 public function getVersion()
142 {
143 global $langs;
144 $langs->load("admin");
145
146 if ($this->version == 'development') {
147 return $langs->trans("VersionDevelopment");
148 } elseif ($this->version == 'experimental') {
149 return $langs->trans("VersionExperimental");
150 } elseif ($this->version == 'dolibarr') {
151 return DOL_VERSION;
152 } elseif ($this->version) {
153 return $this->version;
154 } else {
155 return $langs->trans("NotAvailable");
156 }
157 }
158}
159
160
161// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
174function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
175{
176 // phpcs:enable
177 global $conf, $langs, $user;
178 $langs->load("ficheinter");
179
180 $error = 0;
181
182 $srctemplatepath = '';
183
184 // Positionne modele sur le nom du modele de fichinter a utiliser
185 if (!dol_strlen($modele)) {
186 if (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
187 $modele = $conf->global->FICHEINTER_ADDON_PDF;
188 } else {
189 $modele = 'soleil';
190 }
191 }
192
193 // If selected modele is a filename template (then $modele="modelname:filename")
194 $tmp = explode(':', $modele, 2);
195 if (!empty($tmp[1])) {
196 $modele = $tmp[0];
197 $srctemplatepath = $tmp[1];
198 }
199
200 // Search template files
201 $file = '';
202 $classname = '';
203 $filefound = 0;
204 $dirmodels = array('/');
205 if (is_array($conf->modules_parts['models'])) {
206 $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
207 }
208 foreach ($dirmodels as $reldir) {
209 foreach (array('doc', 'pdf') as $prefix) {
210 $file = $prefix."_".$modele.".modules.php";
211
212 // On verifie l'emplacement du modele
213 $file = dol_buildpath($reldir."core/modules/fichinter/doc/".$file, 0);
214 if (file_exists($file)) {
215 $filefound = 1;
216 $classname = $prefix.'_'.$modele;
217 break;
218 }
219 }
220 if ($filefound) {
221 break;
222 }
223 }
224
225 // Charge le modele
226 if ($filefound) {
227 require_once $file;
228
229 $obj = new $classname($db);
230
231 // We save charset_output to restore it because write_file can change it if needed for
232 // output format that does not support UTF8.
233 $sav_charset_output = $outputlangs->charset_output;
234 if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
235 $outputlangs->charset_output = $sav_charset_output;
236
237 // We delete old preview
238 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
239 dol_delete_preview($object);
240
241 return 1;
242 } else {
243 $outputlangs->charset_output = $sav_charset_output;
244 dol_print_error($db, "fichinter_pdf_create Error: ".$obj->error);
245 return 0;
246 }
247 } else {
248 print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
249 return 0;
250 }
251}
Parent class for documents generators.
Parent class numbering models of intervention sheet references.
getExample()
Return a numbering example.
info()
Returns the default description of the numbering template.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getVersion()
Return the version of the numbering module.
isEnabled()
Return if a module can be used or not.
getNextValue($objsoc=0, $object='')
Return the next assigned value.
Parent class to manage intervention document templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_delete_preview($object)
Delete all preview files linked to object instance.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into FICHEINTER_ADDON_PDF.