dolibarr 24.0.0-beta
carte.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024-2025 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 */
22
28require '../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
44require_once DOL_DOCUMENT_ROOT.'/core/modules/printsheet/modules_labels.php';
45
46$langs->loadLangs(array("members", "errors"));
47
48// Choice of printing year or current year.
49$now = dol_now();
50$year = dol_print_date($now, '%Y');
51$month = dol_print_date($now, '%m');
52$day = dol_print_date($now, '%d');
53$foruserid = GETPOST('foruserid', 'alphanohtml');
54$foruserlogin = GETPOST('foruserlogin', 'alphanohtml');
55$mode = GETPOST('mode', 'aZ09');
56$modelcard = GETPOST("modelcard", 'aZ09'); // Doc template to use for business cards
57$model = GETPOST("model", 'aZ09'); // Doc template to use for business cards
58$modellabel = GETPOST("modellabel", 'aZ09'); // Doc template to use for address sheet
59$mesg = '';
60
61$adherentstatic = new Adherent($db);
62$object = new Adherent($db);
63
64// Fetch optionals attributes and labels
65$extrafields->fetch_name_optionals_label($object->table_element);
66
67// Security check
68$result = restrictedArea($user, 'adherent');
69
70
71/*
72 * Actions
73 */
74
75if ($mode == 'cardlogin' && empty($foruserlogin)) {
76 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"));
77}
78
79if ((!empty($foruserid) || !empty($foruserlogin) || !empty($mode)) && !$mesg) {
80 $arrayofmembers = array();
81
82 // request taking into account member with up to date subscriptions
83 $sql = "SELECT d.rowid, d.ref, d.civility, d.firstname, d.lastname, d.login, d.societe as company, d.datefin,";
84 $sql .= " d.address, d.zip, d.town, d.country, d.birth, d.email, d.photo,";
85 $sql .= " t.libelle as type,";
86 $sql .= " c.code as country_code, c.label as country";
87 // Add fields from extrafields
88 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
89 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
90 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
91 }
92 }
93 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
94 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
95 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
96 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)";
97 }
98 $sql .= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
99 $sql .= " AND d.entity IN (".getEntity('adherent').")";
100 if (is_numeric($foruserid)) {
101 $sql .= " AND d.rowid = ".(int) $foruserid;
102 }
103 if ($foruserlogin) {
104 $sql .= " AND d.login = '".$db->escape($foruserlogin)."'";
105 }
106 $sql .= " ORDER BY d.rowid ASC";
107
108 dol_syslog("Search members", LOG_DEBUG);
109 $result = $db->query($sql);
110 if ($result) {
111 $num = $db->num_rows($result);
112 $i = 0;
113 while ($i < $num) {
114 $objp = $db->fetch_object($result);
115
116 if ($objp->country == '-') {
117 $objp->country = '';
118 }
119
120 $adherentstatic->id = $objp->rowid;
121 $adherentstatic->ref = $objp->ref;
122 $adherentstatic->lastname = $objp->lastname;
123 $adherentstatic->firstname = $objp->firstname;
124
125 // Format extrafield so they can be parsed in function complete_substitutions_array
126 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
127 $adherentstatic->array_options = array();
128 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
129 $tmpkey = 'options_'.$key;
130 if (!empty($objp->$tmpkey)) {
131 $adherentstatic->array_options[$tmpkey] = $objp->$tmpkey;
132 }
133 //if (!empty($objp->$key))
134 // $objp->array_options[$tmpkey] = $objp->$key;
135 //$objp->array_options[$tmpkey] = $extrafields->showOutputField($key, $objp->$tmpkey, '', $object->table_element); //$objp->$tmpkey;
136 }
137 }
138
139
140 $now = dol_now();
141 $year = dol_print_date($now, '%Y');
142 $month = dol_print_date($now, '%m');
143 $day = dol_print_date($now, '%d');
144
145 // List of values to scan for a replacement
146 $substitutionarray = array(
147 '__MEMBER_ID__' => $objp->rowid,
148 '__MEMBER_REF__' => $objp->ref,
149 '__MEMBER_LOGIN__' => empty($objp->login) ? '' : $objp->login,
150 '__MEMBER_TITLE__' => empty($objp->civility) ? '' : $langs->trans("Civility".$objp->civility),
151 '__MEMBER_FIRSTNAME__' => empty($objp->firstname) ? '' : $objp->firstname,
152 '__MEMBER_LASTNAME__' => empty($objp->lastname) ? '' : $objp->lastname,
153 '__MEMBER_FULLNAME__' => $adherentstatic->getFullName($langs),
154 '__MEMBER_COMPANY__' => empty($objp->company) ? '' : $objp->company,
155 '__MEMBER_ADDRESS__' => empty($objp->address) ? '' : $objp->address,
156 '__MEMBER_ZIP__' => empty($objp->zip) ? '' : $objp->zip,
157 '__MEMBER_TOWN__' => empty($objp->town) ? '' : $objp->town,
158 '__MEMBER_COUNTRY__' => empty($objp->country) ? '' : $objp->country,
159 '__MEMBER_COUNTRY_CODE__' => empty($objp->country_code) ? '' : $objp->country_code,
160 '__MEMBER_EMAIL__' => empty($objp->email) ? '' : $objp->email,
161 '__MEMBER_BIRTH__' => dol_print_date($objp->birth, 'day'),
162 '__MEMBER_TYPE__' => empty($objp->type) ? '' : $objp->type,
163 '__YEAR__' => $year,
164 '__MONTH__' => $month,
165 '__DAY__' => $day,
166 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
167 '__SERVER__' => "https://".$_SERVER["SERVER_NAME"]."/"
168 );
169 foreach ($adherentstatic->array_options as $key => $val) {
170 $substitutionarray['__'.strtoupper($key).'__'] = $val;
171 }
172
173 // Add old values for backward compatibility (need upgrade of member setup to be removed)
174 $substitutionarrayold = array(
175 '__ID__' => $objp->rowid,
176 '__REF__' => $objp->ref,
177 '__LOGIN__' => empty($objp->login) ? '' : $objp->login,
178 '__TITLE__' => empty($objp->civility) ? '' : $langs->trans("Civility".$objp->civility),
179 '__FIRSTNAME__' => empty($objp->firstname) ? '' : $objp->firstname,
180 '__LASTNAME__' => empty($objp->lastname) ? '' : $objp->lastname,
181 '__FULLNAME__' => $adherentstatic->getFullName($langs),
182 '__COMPANY__' => empty($objp->company) ? '' : $objp->company,
183 '__ADDRESS__' => empty($objp->address) ? '' : $objp->address,
184 '__ZIP__' => empty($objp->zip) ? '' : $objp->zip,
185 '__TOWN__' => empty($objp->town) ? '' : $objp->town,
186 '__COUNTRY__' => empty($objp->country) ? '' : $objp->country,
187 '__COUNTRY_CODE__' => empty($objp->country_code) ? '' : $objp->country_code,
188 '__EMAIL__' => empty($objp->email) ? '' : $objp->email,
189 '__BIRTH__' => dol_print_date($objp->birth, 'day'),
190 '__TYPE__' => empty($objp->type) ? '' : $objp->type,
191 );
192 $substitutionarray = array_merge($substitutionarray, $substitutionarrayold);
193
194 complete_substitutions_array($substitutionarray, $langs, $adherentstatic);
195
196 // For business cards
197 if (empty($mode) || $mode == 'card' || $mode == 'cardlogin') {
198 $textleft = make_substitutions(getDolGlobalString('ADHERENT_CARD_TEXT'), $substitutionarray);
199 $textheader = make_substitutions(getDolGlobalString('ADHERENT_CARD_HEADER_TEXT'), $substitutionarray);
200 $textfooter = make_substitutions(getDolGlobalString('ADHERENT_CARD_FOOTER_TEXT'), $substitutionarray);
201 $textright = make_substitutions(getDolGlobalString('ADHERENT_CARD_TEXT_RIGHT'), $substitutionarray);
202
203 if (is_numeric($foruserid) || $foruserlogin) {
204 $nb = $_Avery_Labels[$model]['NX'] * $_Avery_Labels[$model]['NY']; // $_Avery_Labels is defined into an include
205 if ($nb <= 0) {
206 $nb = 1; // Protection to avoid empty page
207 }
208
209 for ($j = 0; $j < $nb; $j++) {
210 $arrayofmembers[] = array(
211 'textleft' => $textleft,
212 'textheader' => $textheader,
213 'textfooter' => $textfooter,
214 'textright' => $textright,
215 'id' => $objp->rowid,
216 'ref' => $objp->ref,
217 'photo' => $objp->photo
218 );
219 }
220 } else {
221 $arrayofmembers[] = array(
222 'textleft' => $textleft,
223 'textheader' => $textheader,
224 'textfooter' => $textfooter,
225 'textright' => $textright,
226 'id' => $objp->rowid,
227 'ref' => $objp->ref,
228 'photo' => $objp->photo
229 );
230 }
231 }
232
233 // For labels
234 if ($mode == 'label') {
235 if (!getDolGlobalString('ADHERENT_ETIQUETTE_TEXT')) {
236 $conf->global->ADHERENT_ETIQUETTE_TEXT = "__MEMBER_TITLE__\n__MEMBER_FULLNAME__\n__MEMBER_ADDRESS__\n__MEMBER_ZIP__ __MEMBER_TOWN__\n__MEMBER_COUNTRY__";
237 }
238 $textleft = make_substitutions(getDolGlobalString('ADHERENT_ETIQUETTE_TEXT'), $substitutionarray);
239 $textheader = '';
240 $textfooter = '';
241 $textright = '';
242
243 $arrayofmembers[] = array(
244 'textleft' => $textleft,
245 'textheader' => $textheader,
246 'textfooter' => $textfooter,
247 'textright' => $textright,
248 'id' => $objp->rowid,
249 'ref' => $objp->ref,
250 'photo' => $objp->photo,
251 );
252 }
253
254 $i++;
255 }
256
257 // Build and output PDF
258 $outputlangs = $langs;
259
260 if (empty($mode) || $mode == 'card') {
261 if (!count($arrayofmembers)) {
262 $mesg = $langs->trans("ErrorRecordNotFound");
263 }
264 if (empty($modelcard) || $modelcard == '-1') {
265 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
266 }
267 if (!$mesg) {
268 $result = members_card_pdf_create($db, $arrayofmembers, $modelcard, $outputlangs, '', 'standard_member', 'tmp_cards');
269 }
270 } elseif ($mode == 'cardlogin') {
271 if (!count($arrayofmembers)) {
272 $mesg = $langs->trans("ErrorRecordNotFound");
273 }
274 if (empty($model) || $model == '-1') {
275 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
276 }
277 if (!$mesg) {
278 $result = members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs, '', 'standard_member', 'tmp_cards_login');
279 }
280 } elseif ($mode == 'label') {
281 if (!count($arrayofmembers)) {
282 $mesg = $langs->trans("ErrorRecordNotFound");
283 }
284 if (empty($modellabel) || $modellabel == '-1') {
285 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
286 }
287 if (!$mesg) {
288 $result = doc_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
289 }
290 }
291
292 if ($result <= 0) {
293 dol_print_error(null, $mesg);
294 }
295 } else {
297 }
298
299 if (!$mesg) {
300 $db->close();
301 exit;
302 }
303}
304
305
306/*
307 * View
308 */
309
310$form = new Form($db);
311
312$title = $langs->trans('MembersCards');
313$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
314
315llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-cards');
316
317print load_fiche_titre($langs->trans("LinkToGeneratedPages"), '', $adherentstatic->picto);
318
319print '<span class="opacitymedium">'.$langs->trans("LinkToGeneratedPagesDesc").'</span><br>';
320print '<br>';
321
323
324print '<br>';
325
326print img_picto('', 'card').' '.$langs->trans("DocForAllMembersCards", getDolGlobalString('ADHERENT_CARD_TYPE', $langs->transnoentitiesnoconv("None"))).' ';
327print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
328print '<input type="hidden" name="token" value="'.newToken().'">';
329print '<input type="hidden" name="foruserid" value="all">';
330print '<input type="hidden" name="mode" value="card">';
331print '<input type="hidden" name="action" value="builddoc">';
332print $langs->trans("DescADHERENT_CARD_TYPE").' ';
333// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
334$arrayoflabels = array();
335foreach (array_keys($_Avery_Labels) as $codecards) {
336 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
337}
338asort($arrayoflabels);
339print $form->selectarray('modelcard', $arrayoflabels, (GETPOST('modelcard') ? GETPOST('modelcard') : getDolGlobalString('ADHERENT_CARD_TYPE')), 1, 0, 0, '', 0, 0, 0, '', '', 1);
340print '<br><input type="submit" class="button small" value="'.$langs->trans("BuildDoc").'">';
341print '</form>';
342
343print '<br><br>';
344
345print img_picto('', 'card').' '.$langs->trans("DocForOneMemberCards", getDolGlobalString('ADHERENT_CARD_TYPE', $langs->transnoentitiesnoconv("None"))).' ';
346print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
347print '<input type="hidden" name="token" value="'.newToken().'">';
348print '<input type="hidden" name="mode" value="cardlogin">';
349print '<input type="hidden" name="action" value="builddoc">';
350print $langs->trans("DescADHERENT_CARD_TYPE").' ';
351// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
352$arrayoflabels = array();
353foreach (array_keys($_Avery_Labels) as $codecards) {
354 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
355}
356asort($arrayoflabels);
357print $form->selectarray('model', $arrayoflabels, (GETPOST('model') ? GETPOST('model') : getDolGlobalString('ADHERENT_CARD_TYPE')), 1, 0, 0, '', 0, 0, 0, '', '', 1);
358print '<br>'.$langs->trans("Login").': <input class="width100" type="text" name="foruserlogin" value="'.GETPOST('foruserlogin').'">';
359print '<br><input type="submit" class="button small" value="'.$langs->trans("BuildDoc").'">';
360print '</form>';
361
362print '<br><br>';
363
364print img_picto('', 'card').' '.$langs->trans("DocForLabels", getDolGlobalString('ADHERENT_ETIQUETTE_TYPE')).' ';
365print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
366print '<input type="hidden" name="token" value="'.newToken().'">';
367print '<input type="hidden" name="mode" value="label">';
368print '<input type="hidden" name="action" value="builddoc">';
369print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
370// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
371$arrayoflabels = array();
372foreach (array_keys($_Avery_Labels) as $codecards) {
373 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
374}
375asort($arrayoflabels);
376print $form->selectarray('modellabel', $arrayoflabels, (GETPOST('modellabel') ? GETPOST('modellabel') : getDolGlobalString('ADHERENT_ETIQUETTE_TYPE')), 1, 0, 0, '', 0, 0, 0, '', '', 1);
377print '<br><input type="submit" class="button small" value="'.$langs->trans("BuildDoc").'">';
378print '</form>';
379
380// End of page
381llxFooter();
382$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage members of a foundation.
Class to manage generation of HTML components Only common components must be here.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir='', $template='standard_member', $filename='tmp_cards')
Create a document for visit card according to template defined in ADHERENT_CARDS_ADDON_PDF.
doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir='', $template='standardlabel', $filename='tmp_address_sheet.pdf')
Create a document onto disk according to template module.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.