dolibarr 21.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@inodbox.com>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
30require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32
33
38{
42 public $error = '';
43
44
45 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
53 public static function liste_modeles($db, $maxfilenamelength = 0)
54 {
55 // phpcs:enable
56 $type = 'member';
57 $list = array();
58
59 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
60 $list = getListOfModels($db, $type, $maxfilenamelength);
61
62 return $list;
63 }
64}
65
66
67// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
80function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir = '', $template = 'standard', $filename = 'tmp_cards')
81{
82 // phpcs:enable
83 global $conf, $langs;
84 $langs->load("members");
85
86 $error = 0;
87
88 // Increase limit for PDF build
89 $err = error_reporting();
90 error_reporting(0);
91 @set_time_limit(120);
92 error_reporting($err);
93
94 $code = '';
95 $srctemplatepath = '';
96
97 // Positionne le modele sur le nom du modele a utiliser
98 if (!dol_strlen($modele)) {
99 if (getDolGlobalString('ADHERENT_CARDS_ADDON_PDF')) {
100 $code = getDolGlobalString('ADHERENT_CARDS_ADDON_PDF');
101 } else {
102 $code = $modele;
103 }
104 } else {
105 $code = $modele;
106 }
107
108 // If selected modele is a filename template (then $modele="modelname:filename")
109 $tmp = explode(':', $template, 2);
110 if (!empty($tmp[1])) {
111 $template = $tmp[0];
112 $srctemplatepath = $tmp[1];
113 } else {
114 $srctemplatepath = $code;
115 }
116
117 // Search template files
118 $file = '';
119 $classname = '';
120 $dirmodels = array('/');
121 if (is_array($conf->modules_parts['models'])) {
122 $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
123 }
124 foreach ($dirmodels as $reldir) {
125 foreach (array('doc', 'pdf') as $prefix) {
126 $file = $prefix."_".$template.".class.php";
127
128 // We check that file of doc generaotr exists
129 $file = dol_buildpath($reldir."core/modules/member/doc/".$file, 0);
130 if (file_exists($file)) {
131 $classname = $prefix.'_'.$template;
132 break;
133 }
134 }
135 if ($classname !== '') {
136 break;
137 }
138 }
139
140
141 // Charge le modele
142 if ($classname !== '') {
143 require_once $file;
144
145 $obj = new $classname($db);
146
147 '@phan-var-force ModelePDFMember $obj';
148
149 // We save charset_output to restore it because write_file can change it if needed for
150 // output format that does not support UTF8.
151 $sav_charset_output = $outputlangs->charset_output;
152 if ($obj->write_file($arrayofmembers, $outputlangs, $srctemplatepath, 'member', 0, $filename) > 0) {
153 $outputlangs->charset_output = $sav_charset_output;
154 return 1;
155 } else {
156 $outputlangs->charset_output = $sav_charset_output;
157 dol_print_error($db, "members_card_pdf_create Error: ".$obj->error);
158 return -1;
159 }
160 } else {
161 dol_print_error(null, $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file));
162 return -1;
163 }
164}
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 a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.