dolibarr  7.0.0-beta
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@capnetworks.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 {
37  var $error='';
38 
39 
47  static function liste_modeles($db,$maxfilenamelength=0)
48  {
49  global $conf;
50 
51  $type='ficheinter';
52  $liste=array();
53 
54  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55  $liste=getListOfModels($db,$type,$maxfilenamelength);
56 
57  return $liste;
58  }
59 }
60 
61 
65 abstract class ModeleNumRefFicheinter
66 {
67  var $error='';
68 
74  function isEnabled()
75  {
76  return true;
77  }
78 
84  function info()
85  {
86  global $langs;
87  $langs->load("ficheinter");
88  return $langs->trans("NoDescription");
89  }
90 
96  function getExample()
97  {
98  global $langs;
99  $langs->load("ficheinter");
100  return $langs->trans("NoExample");
101  }
102 
109  function canBeActivated()
110  {
111  return true;
112  }
113 
119  function getNextValue()
120  {
121  global $langs;
122  return $langs->trans("NotAvailable");
123  }
124 
130  function getVersion()
131  {
132  global $langs;
133  $langs->load("admin");
134 
135  if ($this->version == 'development') return $langs->trans("VersionDevelopment");
136  if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
137  if ($this->version == 'dolibarr') return DOL_VERSION;
138  if ($this->version) return $this->version;
139  return $langs->trans("NotAvailable");
140  }
141 }
142 
143 
156 function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
157 {
158  global $conf,$langs,$user;
159  $langs->load("ficheinter");
160 
161  $error=0;
162 
163  $srctemplatepath='';
164 
165  // Positionne modele sur le nom du modele de fichinter a utiliser
166  if (! dol_strlen($modele))
167  {
168  if (! empty($conf->global->FICHEINTER_ADDON_PDF))
169  {
170  $modele = $conf->global->FICHEINTER_ADDON_PDF;
171  }
172  else
173  {
174  $modele = 'soleil';
175  }
176  }
177 
178  // If selected modele is a filename template (then $modele="modelname:filename")
179  $tmp=explode(':',$modele,2);
180  if (! empty($tmp[1]))
181  {
182  $modele=$tmp[0];
183  $srctemplatepath=$tmp[1];
184  }
185 
186  // Search template files
187  $file=''; $classname=''; $filefound=0;
188  $dirmodels=array('/');
189  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
190  foreach($dirmodels as $reldir)
191  {
192  foreach(array('doc','pdf') as $prefix)
193  {
194  $file = $prefix."_".$modele.".modules.php";
195 
196  // On verifie l'emplacement du modele
197  $file=dol_buildpath($reldir."core/modules/fichinter/doc/".$file,0);
198  if (file_exists($file))
199  {
200  $filefound=1;
201  $classname=$prefix.'_'.$modele;
202  break;
203  }
204  }
205  if ($filefound) break;
206  }
207 
208  // Charge le modele
209  if ($filefound)
210  {
211  require_once $file;
212 
213  $obj = new $classname($db);
214 
215  // We save charset_output to restore it because write_file can change it if needed for
216  // output format that does not support UTF8.
217  $sav_charset_output=$outputlangs->charset_output;
218  if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
219  {
220  $outputlangs->charset_output=$sav_charset_output;
221 
222  // We delete old preview
223  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
224  dol_delete_preview($object);
225 
226  return 1;
227  }
228  else
229  {
230  $outputlangs->charset_output=$sav_charset_output;
231  dol_print_error($db,"fichinter_pdf_create Error: ".$obj->error);
232  return 0;
233  }
234  }
235  else
236  {
237  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
238  return 0;
239  }
240 }
241 
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:1283
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'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.
print
Draft customers invoices.
Definition: index.php:91
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.