dolibarr  7.0.0-beta
modules_don.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005 Regis Houssin <regis.houssin@capnetworks.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 
27 require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
29 
30 
31 
35 abstract class ModeleDon extends CommonDocGenerator
36 {
37  var $error='';
38 
46  static function liste_modeles($db,$maxfilenamelength=0)
47  {
48  global $conf;
49 
50  $type='donation';
51  $liste=array();
52 
53  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
54  $liste=getListOfModels($db,$type,$maxfilenamelength);
55 
56  return $liste;
57  }
58 }
59 
60 
64 abstract class ModeleNumRefDons
65 {
66  var $error='';
67 
73  function isEnabled()
74  {
75  return true;
76  }
77 
83  function info()
84  {
85  global $langs;
86  $langs->load("bills");
87  return $langs->trans("NoDescription");
88  }
89 
95  function getExample()
96  {
97  global $langs;
98  $langs->load("bills");
99  return $langs->trans("NoExample");
100  }
101 
108  function canBeActivated()
109  {
110  return true;
111  }
112 
118  function getNextValue()
119  {
120  global $langs;
121  return $langs->trans("NotAvailable");
122  }
123 
129  function getVersion()
130  {
131  global $langs;
132  $langs->load("admin");
133 
134  if ($this->version == 'development') return $langs->trans("VersionDevelopment");
135  if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
136  if ($this->version == 'dolibarr') return DOL_VERSION;
137  if ($this->version) return $this->version;
138  return $langs->trans("NotAvailable");
139  }
140 }
141 
142 
156 function don_create($db, $id, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
157 {
158  global $conf, $langs;
159  $langs->load("bills");
160 
161  $eror=0;
162 
163  // Increase limit for PDF build
164  $err=error_reporting();
165  error_reporting(0);
166  @set_time_limit(120);
167  error_reporting($err);
168 
169  $srctemplatepath='';
170 
171  // Set template to use
172  if (! dol_strlen($modele))
173  {
174  if (! empty($conf->global->DON_ADDON_MODEL))
175  {
176  $modele = $conf->global->DON_ADDON_MODEL;
177  }
178  else
179  {
180  print $langs->trans("Error")." ".$langs->trans("Error_DON_ADDON_MODEL_NotDefined");
181  return 0;
182  }
183  }
184 
185  // If selected modele is a filename template (then $modele="modelname:filename")
186  $tmp=explode(':',$modele,2);
187  if (! empty($tmp[1]))
188  {
189  $modele=$tmp[0];
190  $srctemplatepath=$tmp[1];
191  }
192 
193  // Search template files
194  $file=''; $classname=''; $filefound=0;
195  $dirmodels=array('/');
196  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
197  foreach($dirmodels as $reldir)
198  {
199  foreach(array('html','doc','pdf') as $prefix)
200  {
201  $file = $prefix."_".preg_replace('/^html_/','',$modele).".modules.php";
202 
203  // On verifie l'emplacement du modele
204  $file=dol_buildpath($reldir."core/modules/dons/".$file,0);
205  if (file_exists($file))
206  {
207  $filefound=1;
208  $classname=$prefix.'_'.$modele;
209  break;
210  }
211  }
212  if ($filefound) break;
213  }
214 
215  // Charge le modele
216  if ($filefound)
217  {
218  require_once $file;
219 
220  $object=new Don($db);
221  $object->fetch($id);
222 
223  $classname = $modele;
224  $obj = new $classname($db);
225 
226  // We save charset_output to restore it because write_file can change it if needed for
227  // output format that does not support UTF8.
228  $sav_charset_output=$outputlangs->charset_output;
229  if ($obj->write_file($object,$outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
230  {
231  $outputlangs->charset_output=$sav_charset_output;
232 
233  // we delete preview files
234  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
235  dol_delete_preview($object);
236  return 1;
237  }
238  else
239  {
240  $outputlangs->charset_output=$sav_charset_output;
241  dol_syslog("Erreur dans don_create");
242  dol_print_error($db,$obj->error);
243  return 0;
244  }
245  }
246  else
247  {
248  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
249  return 0;
250  }
251 }
252 
getExample()
Renvoi un exemple de numerotation.
Definition: modules_don.php:95
getVersion()
Renvoi version du module numerotation.
info()
Renvoi la description par defaut du modele de numerotation.
Definition: modules_don.php:83
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1283
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.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_don.php:46
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas d de conflits qui empechera cette ...
Parent class of donation numbering templates.
Definition: modules_don.php:64
print
Draft customers invoices.
Definition: index.php:91
Class to manage donations.
Definition: don.class.php:35
Parent class of subscription templates.
Definition: modules_don.php:35
Parent class for documents generators.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
getNextValue()
Renvoi prochaine valeur attribuee.
don_create($db, $id, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Cree un don sur disque en fonction du modele de DON_ADDON_PDF.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
isEnabled()
Return if a module can be used or not.
Definition: modules_don.php:73