dolibarr 19.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 *
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';
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php';
31
32
37{
38 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
46 public static function liste_modeles($db, $maxfilenamelength = 0)
47 {
48 // phpcs:enable
49 $type = 'ficheinter';
50 $list = array();
51
52 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
53 $list = getListOfModels($db, $type, $maxfilenamelength);
54
55 return $list;
56 }
57}
58
59
64{
65 // No overload code
66}
67
68
69// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
82function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
83{
84 // phpcs:enable
85 global $conf, $langs;
86 $langs->load("ficheinter");
87
88 $error = 0;
89
90 $srctemplatepath = '';
91
92 // Positionne modele sur le nom du modele de fichinter a utiliser
93 if (!dol_strlen($modele)) {
94 if (getDolGlobalString('FICHEINTER_ADDON_PDF')) {
95 $modele = $conf->global->FICHEINTER_ADDON_PDF;
96 } else {
97 $modele = 'soleil';
98 }
99 }
100
101 // If selected modele is a filename template (then $modele="modelname:filename")
102 $tmp = explode(':', $modele, 2);
103 if (!empty($tmp[1])) {
104 $modele = $tmp[0];
105 $srctemplatepath = $tmp[1];
106 }
107
108 // Search template files
109 $file = '';
110 $classname = '';
111 $filefound = 0;
112 $dirmodels = array('/');
113 if (is_array($conf->modules_parts['models'])) {
114 $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
115 }
116 foreach ($dirmodels as $reldir) {
117 foreach (array('doc', 'pdf') as $prefix) {
118 $file = $prefix."_".$modele.".modules.php";
119
120 // On verifie l'emplacement du modele
121 $file = dol_buildpath($reldir."core/modules/fichinter/doc/".$file, 0);
122 if (file_exists($file)) {
123 $filefound = 1;
124 $classname = $prefix.'_'.$modele;
125 break;
126 }
127 }
128 if ($filefound) {
129 break;
130 }
131 }
132
133 // Charge le modele
134 if ($filefound) {
135 require_once $file;
136
137 $obj = new $classname($db);
138
139 // We save charset_output to restore it because write_file can change it if needed for
140 // output format that does not support UTF8.
141 $sav_charset_output = $outputlangs->charset_output;
142 if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
143 $outputlangs->charset_output = $sav_charset_output;
144
145 // We delete old preview
146 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
147 dol_delete_preview($object);
148
149 return 1;
150 } else {
151 $outputlangs->charset_output = $sav_charset_output;
152 dol_print_error($db, "fichinter_pdf_create Error: ".$obj->error);
153 return 0;
154 }
155 } else {
156 print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
157 return 0;
158 }
159}
Parent class for documents (PDF, ODT, ...) generators.
Parent class for number ref generators.
Parent class numbering models of intervention sheet references.
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.
getDolGlobalString($key, $default='')
Return 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.