dolibarr  9.0.0
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-2012 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 <http://www.gnu.org/licenses/>.
19  * or see http://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.NotCamelCaps
51  static function liste_modeles($db,$maxfilenamelength=0)
52  {
53  // phpcs:enable
54  global $conf;
55 
56  $type='ficheinter';
57  $liste=array();
58 
59  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
60  $liste=getListOfModels($db,$type,$maxfilenamelength);
61 
62  return $liste;
63  }
64 }
65 
66 
70 abstract class ModeleNumRefFicheinter
71 {
75  public $error='';
76 
82  function isEnabled()
83  {
84  return true;
85  }
86 
92  function info()
93  {
94  global $langs;
95  $langs->load("ficheinter");
96  return $langs->trans("NoDescription");
97  }
98 
104  function getExample()
105  {
106  global $langs;
107  $langs->load("ficheinter");
108  return $langs->trans("NoExample");
109  }
110 
117  function canBeActivated()
118  {
119  return true;
120  }
121 
127  function getNextValue()
128  {
129  global $langs;
130  return $langs->trans("NotAvailable");
131  }
132 
138  function getVersion()
139  {
140  global $langs;
141  $langs->load("admin");
142 
143  if ($this->version == 'development') return $langs->trans("VersionDevelopment");
144  if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
145  if ($this->version == 'dolibarr') return DOL_VERSION;
146  if ($this->version) return $this->version;
147  return $langs->trans("NotAvailable");
148  }
149 }
150 
151 
152 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
165 function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
166 {
167  // phpcs:enable
168  global $conf,$langs,$user;
169  $langs->load("ficheinter");
170 
171  $error=0;
172 
173  $srctemplatepath='';
174 
175  // Positionne modele sur le nom du modele de fichinter a utiliser
176  if (! dol_strlen($modele))
177  {
178  if (! empty($conf->global->FICHEINTER_ADDON_PDF))
179  {
180  $modele = $conf->global->FICHEINTER_ADDON_PDF;
181  }
182  else
183  {
184  $modele = 'soleil';
185  }
186  }
187 
188  // If selected modele is a filename template (then $modele="modelname:filename")
189  $tmp=explode(':',$modele,2);
190  if (! empty($tmp[1]))
191  {
192  $modele=$tmp[0];
193  $srctemplatepath=$tmp[1];
194  }
195 
196  // Search template files
197  $file=''; $classname=''; $filefound=0;
198  $dirmodels=array('/');
199  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
200  foreach($dirmodels as $reldir)
201  {
202  foreach(array('doc','pdf') as $prefix)
203  {
204  $file = $prefix."_".$modele.".modules.php";
205 
206  // On verifie l'emplacement du modele
207  $file=dol_buildpath($reldir."core/modules/fichinter/doc/".$file,0);
208  if (file_exists($file))
209  {
210  $filefound=1;
211  $classname=$prefix.'_'.$modele;
212  break;
213  }
214  }
215  if ($filefound) break;
216  }
217 
218  // Charge le modele
219  if ($filefound)
220  {
221  require_once $file;
222 
223  $obj = new $classname($db);
224 
225  // We save charset_output to restore it because write_file can change it if needed for
226  // output format that does not support UTF8.
227  $sav_charset_output=$outputlangs->charset_output;
228  if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
229  {
230  $outputlangs->charset_output=$sav_charset_output;
231 
232  // We delete old preview
233  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
234  dol_delete_preview($object);
235 
236  return 1;
237  }
238  else
239  {
240  $outputlangs->charset_output=$sav_charset_output;
241  dol_print_error($db,"fichinter_pdf_create Error: ".$obj->error);
242  return 0;
243  }
244  }
245  else
246  {
247  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
248  return 0;
249  }
250 }
print
Draft customers invoices.
Definition: index.php:91
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
getNextValue()
Renvoi prochaine valeur attribuee.
getExample()
Renvoi un exemple de numerotation.
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1324
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
isEnabled()
Return if a module can be used or not.
Classe mere des modeles de numerotation des references de fiches d&#39;intervention.
Parent class to manage intervention document templates.
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...
getVersion()
Renvoi version du module numerotation.
info()
Renvoi la description par defaut du modele de numerotation.
Parent class for documents generators.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.