dolibarr  19.0.0-dev
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@inodbox.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 
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 {
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  $type = 'member';
55  $list = array();
56 
57  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
58  $list = getListOfModels($db, $type, $maxfilenamelength);
59 
60  return $list;
61  }
62 }
63 
64 
65 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
78 function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir = '', $template = 'standard', $filename = 'tmp_cards')
79 {
80  // phpcs:enable
81  global $conf, $langs;
82  $langs->load("members");
83 
84  $error = 0;
85 
86  // Increase limit for PDF build
87  $err = error_reporting();
88  error_reporting(0);
89  @set_time_limit(120);
90  error_reporting($err);
91 
92  $code = '';
93  $srctemplatepath = '';
94 
95  // Positionne le modele sur le nom du modele a utiliser
96  if (!dol_strlen($modele)) {
97  if (!empty($conf->global->ADHERENT_CARDS_ADDON_PDF)) {
98  $code = $conf->global->ADHERENT_CARDS_ADDON_PDF;
99  } else {
100  $code = $modele;
101  }
102  } else {
103  $code = $modele;
104  }
105 
106  // If selected modele is a filename template (then $modele="modelname:filename")
107  $tmp = explode(':', $template, 2);
108  if (!empty($tmp[1])) {
109  $template = $tmp[0];
110  $srctemplatepath = $tmp[1];
111  } else {
112  $srctemplatepath = $code;
113  }
114 
115  // Search template files
116  $file = '';
117  $classname = '';
118  $filefound = 0;
119  $dirmodels = array('/');
120  if (is_array($conf->modules_parts['models'])) {
121  $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
122  }
123  foreach ($dirmodels as $reldir) {
124  foreach (array('doc', 'pdf') as $prefix) {
125  $file = $prefix."_".$template.".class.php";
126 
127  // We check that file of doc generaotr exists
128  $file = dol_buildpath($reldir."core/modules/member/doc/".$file, 0);
129  if (file_exists($file)) {
130  $filefound = 1;
131  $classname = $prefix.'_'.$template;
132  break;
133  }
134  }
135  if ($filefound) {
136  break;
137  }
138  }
139 
140 
141  // Charge le modele
142  if ($filefound) {
143  require_once $file;
144 
145  $obj = new $classname($db);
146 
147  // We save charset_output to restore it because write_file can change it if needed for
148  // output format that does not support UTF8.
149  $sav_charset_output = $outputlangs->charset_output;
150  if ($obj->write_file($arrayofmembers, $outputlangs, $srctemplatepath, 'member', 0, $filename) > 0) {
151  $outputlangs->charset_output = $sav_charset_output;
152  return 1;
153  } else {
154  $outputlangs->charset_output = $sav_charset_output;
155  dol_print_error($db, "members_card_pdf_create Error: ".$obj->error);
156  return -1;
157  }
158  } else {
159  dol_print_error('', $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file));
160  return -1;
161  }
162 }
Parent class of document generator for members cards.
static 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_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.
members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir='', $template='standard', $filename='tmp_cards')
Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF.