dolibarr 20.0.0
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31
32
37{
41 public $error = '';
42
43
44 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
52 public static function liste_modeles($db, $maxfilenamelength = 0)
53 {
54 // phpcs:enable
55 $type = 'member';
56 $list = array();
57
58 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
59 $list = getListOfModels($db, $type, $maxfilenamelength);
60
61 return $list;
62 }
63}
64
65
66// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
79function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir = '', $template = 'standard', $filename = 'tmp_cards')
80{
81 // phpcs:enable
82 global $conf, $langs;
83 $langs->load("members");
84
85 $error = 0;
86
87 // Increase limit for PDF build
88 $err = error_reporting();
89 error_reporting(0);
90 @set_time_limit(120);
91 error_reporting($err);
92
93 $code = '';
94 $srctemplatepath = '';
95
96 // Positionne le modele sur le nom du modele a utiliser
97 if (!dol_strlen($modele)) {
98 if (getDolGlobalString('ADHERENT_CARDS_ADDON_PDF')) {
99 $code = getDolGlobalString('ADHERENT_CARDS_ADDON_PDF');
100 } else {
101 $code = $modele;
102 }
103 } else {
104 $code = $modele;
105 }
106
107 // If selected modele is a filename template (then $modele="modelname:filename")
108 $tmp = explode(':', $template, 2);
109 if (!empty($tmp[1])) {
110 $template = $tmp[0];
111 $srctemplatepath = $tmp[1];
112 } else {
113 $srctemplatepath = $code;
114 }
115
116 // Search template files
117 $file = '';
118 $classname = '';
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 $classname = $prefix.'_'.$template;
131 break;
132 }
133 }
134 if ($classname !== '') {
135 break;
136 }
137 }
138
139
140 // Charge le modele
141 if ($classname !== '') {
142 require_once $file;
143
144 $obj = new $classname($db);
145
146 // We save charset_output to restore it because write_file can change it if needed for
147 // output format that does not support UTF8.
148 $sav_charset_output = $outputlangs->charset_output;
149 if ($obj->write_file($arrayofmembers, $outputlangs, $srctemplatepath, 'member', 0, $filename) > 0) {
150 $outputlangs->charset_output = $sav_charset_output;
151 return 1;
152 } else {
153 $outputlangs->charset_output = $sav_charset_output;
154 dol_print_error($db, "members_card_pdf_create Error: ".$obj->error);
155 return -1;
156 }
157 } else {
158 dol_print_error(null, $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file));
159 return -1;
160 }
161}
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.