dolibarr 23.0.3
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
31require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php';
33
34
39{
40 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
48 public static function liste_modeles($db, $maxfilenamelength = 0)
49 {
50 // phpcs:enable
51 $type = 'ficheinter';
52 $list = array();
53
54 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55 $list = getListOfModels($db, $type, $maxfilenamelength);
56
57 return $list;
58 }
59
60
61 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
73 abstract public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
74}
75
76
81{
89 abstract public function getNextValue($objsoc = '', $object = '');
90
96 abstract public function getExample();
97}
98
99
100// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
113function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
114{
115 // phpcs:enable
116 global $conf, $langs;
117 $langs->load("ficheinter");
118
119 $error = 0;
120
121 $srctemplatepath = '';
122
123 // Positionne modele sur le nom du modele de fichinter a utiliser
124 if (!dol_strlen($modele)) {
125 if (getDolGlobalString('FICHEINTER_ADDON_PDF')) {
126 $modele = getDolGlobalString('FICHEINTER_ADDON_PDF');
127 } else {
128 $modele = 'soleil';
129 }
130 }
131
132 // If selected modele is a filename template (then $modele="modelname:filename")
133 $tmp = explode(':', $modele, 2);
134 if (!empty($tmp[1])) {
135 $modele = $tmp[0];
136 $srctemplatepath = $tmp[1];
137 }
138
139 // Search template files
140 $file = '';
141 $classname = '';
142 $dirmodels = array_merge(['/'], (array) $conf->modules_parts['models']);
143 foreach ($dirmodels as $reldir) {
144 foreach (array('doc', 'pdf') as $prefix) {
145 $file = $prefix."_".$modele.".modules.php";
146
147 // Get the location of the module and verify it exists
148 $file = dol_buildpath($reldir."core/modules/fichinter/doc/".$file, 0);
149 if (file_exists($file)) {
150 $classname = $prefix.'_'.$modele;
151 break;
152 }
153 }
154 if ($classname !== '') {
155 break;
156 }
157 }
158
159 // Charge le modele
160 if ($classname !== '') {
161 require_once $file;
162
163 $obj = new $classname($db);
164
165 '@phan-var-force ModelePDFFicheinter $obj';
166
167 // We save charset_output to restore it because write_file can change it if needed for
168 // output format that does not support UTF8.
169 $sav_charset_output = $outputlangs->charset_output;
170 if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
171 $outputlangs->charset_output = $sav_charset_output;
172
173 // We delete old preview
174 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
176
177 return 1;
178 } else {
179 $outputlangs->charset_output = $sav_charset_output;
180 dol_print_error($db, "fichinter_pdf_create Error: ".$obj->error);
181 return 0;
182 }
183 } else {
184 print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
185 return 0;
186 }
187}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent class for documents (PDF, ODT, ...) generators.
Parent class for number ref generators.
Parent class numbering models of intervention sheet references.
getNextValue($objsoc='', $object='')
Return next free value.
getExample()
Return an example of numbering.
Parent class to manage intervention document templates.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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, $showempty=0)
Return list of activated modules usable for document generation.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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.