dolibarr  17.0.4
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 
29 require_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  global $conf;
55 
56  $type = 'ficheinter';
57  $list = array();
58 
59  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
60  $list = getListOfModels($db, $type, $maxfilenamelength);
61 
62  return $list;
63  }
64 }
65 
66 
70 abstract class ModeleNumRefFicheinter
71 {
75  public $error = '';
76 
82  public function isEnabled()
83  {
84  return true;
85  }
86 
92  public function info()
93  {
94  global $langs;
95  $langs->load("ficheinter");
96  return $langs->trans("NoDescription");
97  }
98 
104  public function getExample()
105  {
106  global $langs;
107  $langs->load("ficheinter");
108  return $langs->trans("NoExample");
109  }
110 
117  public function canBeActivated()
118  {
119  return true;
120  }
121 
129  public function getNextValue($objsoc = 0, $object = '')
130  {
131  global $langs;
132  return $langs->trans("NotAvailable");
133  }
134 
140  public function getVersion()
141  {
142  global $langs;
143  $langs->load("admin");
144 
145  if ($this->version == 'development') {
146  return $langs->trans("VersionDevelopment");
147  } elseif ($this->version == 'experimental') {
148  return $langs->trans("VersionExperimental");
149  } elseif ($this->version == 'dolibarr') {
150  return DOL_VERSION;
151  } elseif ($this->version) {
152  return $this->version;
153  } else {
154  return $langs->trans("NotAvailable");
155  }
156  }
157 }
158 
159 
160 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
173 function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
174 {
175  // phpcs:enable
176  global $conf, $langs, $user;
177  $langs->load("ficheinter");
178 
179  $error = 0;
180 
181  $srctemplatepath = '';
182 
183  // Positionne modele sur le nom du modele de fichinter a utiliser
184  if (!dol_strlen($modele)) {
185  if (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
186  $modele = $conf->global->FICHEINTER_ADDON_PDF;
187  } else {
188  $modele = 'soleil';
189  }
190  }
191 
192  // If selected modele is a filename template (then $modele="modelname:filename")
193  $tmp = explode(':', $modele, 2);
194  if (!empty($tmp[1])) {
195  $modele = $tmp[0];
196  $srctemplatepath = $tmp[1];
197  }
198 
199  // Search template files
200  $file = '';
201  $classname = '';
202  $filefound = 0;
203  $dirmodels = array('/');
204  if (is_array($conf->modules_parts['models'])) {
205  $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
206  }
207  foreach ($dirmodels as $reldir) {
208  foreach (array('doc', 'pdf') as $prefix) {
209  $file = $prefix."_".$modele.".modules.php";
210 
211  // On verifie l'emplacement du modele
212  $file = dol_buildpath($reldir."core/modules/fichinter/doc/".$file, 0);
213  if (file_exists($file)) {
214  $filefound = 1;
215  $classname = $prefix.'_'.$modele;
216  break;
217  }
218  }
219  if ($filefound) {
220  break;
221  }
222  }
223 
224  // Charge le modele
225  if ($filefound) {
226  require_once $file;
227 
228  $obj = new $classname($db);
229 
230  // We save charset_output to restore it because write_file can change it if needed for
231  // output format that does not support UTF8.
232  $sav_charset_output = $outputlangs->charset_output;
233  if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
234  $outputlangs->charset_output = $sav_charset_output;
235 
236  // We delete old preview
237  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
238  dol_delete_preview($object);
239 
240  return 1;
241  } else {
242  $outputlangs->charset_output = $sav_charset_output;
243  dol_print_error($db, "fichinter_pdf_create Error: ".$obj->error);
244  return 0;
245  }
246  } else {
247  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
248  return 0;
249  }
250 }
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.
Definition: files.lib.php:1454
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.