dolibarr  7.0.0-beta
modules_cards.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2009 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 
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
30 
31 
36 {
37  var $error='';
38 
39 
47  function liste_modeles($db,$maxfilenamelength=0)
48  {
49  global $conf;
50 
51  $type='member';
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 
73 function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir='', $template='standard')
74 {
75  global $conf,$langs;
76  $langs->load("members");
77 
78  $error=0;
79 
80  // Increase limit for PDF build
81  $err=error_reporting();
82  error_reporting(0);
83  @set_time_limit(120);
84  error_reporting($err);
85 
86  $code='';
87  $srctemplatepath='';
88 
89  // Positionne le modele sur le nom du modele a utiliser
90  if (! dol_strlen($modele))
91  {
92  if (! empty($conf->global->ADHERENT_CARDS_ADDON_PDF))
93  {
94  $code = $conf->global->ADHERENT_CARDS_ADDON_PDF;
95  }
96  else
97  {
98  $code = $modele;
99  }
100  }
101  else $code=$modele;
102 
103  // If selected modele is a filename template (then $modele="modelname:filename")
104  $tmp=explode(':',$template,2);
105  if (! empty($tmp[1]))
106  {
107  $template=$tmp[0];
108  $srctemplatepath=$tmp[1];
109  }
110  else $srctemplatepath=$code;
111 
112  // Search template files
113  $file=''; $classname=''; $filefound=0;
114  $dirmodels=array('/');
115  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
116  foreach($dirmodels as $reldir)
117  {
118  foreach(array('doc','pdf') as $prefix)
119  {
120  $file = $prefix."_".$template.".class.php";
121 
122  // On verifie l'emplacement du modele
123  $file=dol_buildpath($reldir."core/modules/member/doc/".$file,0);
124  if (file_exists($file))
125  {
126  $filefound=1;
127  $classname=$prefix.'_'.$template;
128  break;
129  }
130  }
131  if ($filefound) break;
132  }
133 
134 
135  // Charge le modele
136  if ($filefound)
137  {
138  require_once $file;
139 
140  $obj = new $classname($db);
141 
142  // We save charset_output to restore it because write_file can change it if needed for
143  // output format that does not support UTF8.
144  $sav_charset_output=$outputlangs->charset_output;
145  if ($obj->write_file($arrayofmembers, $outputlangs, $srctemplatepath) > 0)
146  {
147  $outputlangs->charset_output=$sav_charset_output;
148  return 1;
149  }
150  else
151  {
152  $outputlangs->charset_output=$sav_charset_output;
153  dol_print_error($db,"members_card_pdf_create Error: ".$obj->error);
154  return -1;
155  }
156  }
157 
158  else
159  {
160  dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
161  return -1;
162  }
163 
164 
165 }
166 
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir='', $template='standard')
Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Parent class of document generator for members cards.
liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.