dolibarr 21.0.0-alpha
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 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 */
21
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
32require_once DOL_DOCUMENT_ROOT.'/core/modules/printsheet/modules_labels.php';
33
34$langs->loadLangs(array("members", "errors"));
35
36// Choice of printing year or current year.
37$now = dol_now();
38$year = dol_print_date($now, '%Y');
39$month = dol_print_date($now, '%m');
40$day = dol_print_date($now, '%d');
41$foruserid = GETPOST('foruserid', 'alphanohtml');
42$foruserlogin = GETPOST('foruserlogin', 'alphanohtml');
43$mode = GETPOST('mode', 'aZ09');
44$modelcard = GETPOST("modelcard", 'aZ09'); // Doc template to use for business cards
45$model = GETPOST("model", 'aZ09'); // Doc template to use for business cards
46$modellabel = GETPOST("modellabel", 'aZ09'); // Doc template to use for address sheet
47$mesg = '';
48
49$adherentstatic = new Adherent($db);
50$object = new Adherent($db);
51
52$extrafields = new ExtraFields($db);
53// Fetch optionals attributes and labels
54$extrafields->fetch_name_optionals_label($object->table_element);
55
56// Security check
57$result = restrictedArea($user, 'adherent');
58
59
60/*
61 * Actions
62 */
63
64if ($mode == 'cardlogin' && empty($foruserlogin)) {
65 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"));
66}
67
68if ((!empty($foruserid) || !empty($foruserlogin) || !empty($mode)) && !$mesg) {
69 $arrayofmembers = array();
70
71 // request taking into account member with up to date subscriptions
72 $sql = "SELECT d.rowid, d.ref, d.firstname, d.lastname, d.login, d.societe as company, d.datefin,";
73 $sql .= " d.address, d.zip, d.town, d.country, d.birth, d.email, d.photo,";
74 $sql .= " t.libelle as type,";
75 $sql .= " c.code as country_code, c.label as country";
76 // Add fields from extrafields
77 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
78 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
79 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
80 }
81 }
82 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
83 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
84 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
85 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)";
86 }
87 $sql .= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
88 $sql .= " AND d.entity IN (".getEntity('adherent').")";
89 if (is_numeric($foruserid)) {
90 $sql .= " AND d.rowid = ".(int) $foruserid;
91 }
92 if ($foruserlogin) {
93 $sql .= " AND d.login = '".$db->escape($foruserlogin)."'";
94 }
95 $sql .= " ORDER BY d.rowid ASC";
96
97 dol_syslog("Search members", LOG_DEBUG);
98 $result = $db->query($sql);
99 if ($result) {
100 $num = $db->num_rows($result);
101 $i = 0;
102 while ($i < $num) {
103 $objp = $db->fetch_object($result);
104
105 if ($objp->country == '-') {
106 $objp->country = '';
107 }
108
109 $adherentstatic->id = $objp->rowid;
110 $adherentstatic->ref = $objp->ref;
111 $adherentstatic->lastname = $objp->lastname;
112 $adherentstatic->firstname = $objp->firstname;
113
114 // Format extrafield so they can be parsed in function complete_substitutions_array
115 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
116 $adherentstatic->array_options = array();
117 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
118 $tmpkey = 'options_'.$key;
119 if (!empty($objp->$tmpkey)) {
120 $adherentstatic->array_options[$tmpkey] = $objp->$tmpkey;
121 }
122 //if (!empty($objp->$key))
123 // $objp->array_options[$tmpkey] = $objp->$key;
124 //$objp->array_options[$tmpkey] = $extrafields->showOutputField($key, $objp->$tmpkey, '', $object->table_element); //$objp->$tmpkey;
125 }
126 }
127
128 // List of values to scan for a replacement
129 $substitutionarray = array(
130 '__ID__' => $objp->rowid,
131 '__REF__' => $objp->ref,
132 '__LOGIN__' => empty($objp->login) ? '' : $objp->login,
133 '__FIRSTNAME__' => empty($objp->firstname) ? '' : $objp->firstname,
134 '__LASTNAME__' => empty($objp->lastname) ? '' : $objp->lastname,
135 '__FULLNAME__' => $adherentstatic->getFullName($langs),
136 '__COMPANY__' => empty($objp->company) ? '' : $objp->company,
137 '__ADDRESS__' => empty($objp->address) ? '' : $objp->address,
138 '__ZIP__' => empty($objp->zip) ? '' : $objp->zip,
139 '__TOWN__' => empty($objp->town) ? '' : $objp->town,
140 '__COUNTRY__' => empty($objp->country) ? '' : $objp->country,
141 '__COUNTRY_CODE__' => empty($objp->country_code) ? '' : $objp->country_code,
142 '__EMAIL__' => empty($objp->email) ? '' : $objp->email,
143 '__BIRTH__' => dol_print_date($objp->birth, 'day'),
144 '__TYPE__' => empty($objp->type) ? '' : $objp->type,
145 '__YEAR__' => $year,
146 '__MONTH__' => $month,
147 '__DAY__' => $day,
148 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
149 '__SERVER__' => "https://".$_SERVER["SERVER_NAME"]."/"
150 );
151 complete_substitutions_array($substitutionarray, $langs, $adherentstatic);
152
153 // For business cards
154 if (empty($mode) || $mode == 'card' || $mode == 'cardlogin') {
155 $textleft = make_substitutions(getDolGlobalString('ADHERENT_CARD_TEXT'), $substitutionarray);
156 $textheader = make_substitutions(getDolGlobalString('ADHERENT_CARD_HEADER_TEXT'), $substitutionarray);
157 $textfooter = make_substitutions(getDolGlobalString('ADHERENT_CARD_FOOTER_TEXT'), $substitutionarray);
158 $textright = make_substitutions(getDolGlobalString('ADHERENT_CARD_TEXT_RIGHT'), $substitutionarray);
159
160 if (is_numeric($foruserid) || $foruserlogin) {
161 $nb = $_Avery_Labels[$model]['NX'] * $_Avery_Labels[$model]['NY']; // $_Avery_Labels is defined into an include
162 if ($nb <= 0) {
163 $nb = 1; // Protection to avoid empty page
164 }
165
166 for ($j = 0; $j < $nb; $j++) {
167 $arrayofmembers[] = array(
168 'textleft'=>$textleft,
169 'textheader'=>$textheader,
170 'textfooter'=>$textfooter,
171 'textright'=>$textright,
172 'id'=>$objp->rowid,
173 'ref'=>$objp->ref,
174 'photo'=>$objp->photo
175 );
176 }
177 } else {
178 $arrayofmembers[] = array(
179 'textleft'=>$textleft,
180 'textheader'=>$textheader,
181 'textfooter'=>$textfooter,
182 'textright'=>$textright,
183 'id'=>$objp->rowid,
184 'ref'=>$objp->ref,
185 'photo'=>$objp->photo
186 );
187 }
188 }
189
190 // For labels
191 if ($mode == 'label') {
192 if (!getDolGlobalString('ADHERENT_ETIQUETTE_TEXT')) {
193 $conf->global->ADHERENT_ETIQUETTE_TEXT = "__FULLNAME__\n__ADDRESS__\n__ZIP__ __TOWN__\n__COUNTRY__";
194 }
195 $textleft = make_substitutions(getDolGlobalString('ADHERENT_ETIQUETTE_TEXT'), $substitutionarray);
196 $textheader = '';
197 $textfooter = '';
198 $textright = '';
199
200 $arrayofmembers[] = array(
201 'textleft'=>$textleft,
202 'textheader'=>$textheader,
203 'textfooter'=>$textfooter,
204 'textright'=>$textright,
205 'id'=>$objp->rowid,
206 'ref'=>$objp->ref,
207 'photo'=>$objp->photo,
208 );
209 }
210
211 $i++;
212 }
213
214 // Build and output PDF
215 $outputlangs = $langs;
216
217 if (empty($mode) || $mode == 'card') {
218 if (!count($arrayofmembers)) {
219 $mesg = $langs->trans("ErrorRecordNotFound");
220 }
221 if (empty($modelcard) || $modelcard == '-1') {
222 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
223 }
224 if (!$mesg) {
225 $result = members_card_pdf_create($db, $arrayofmembers, $modelcard, $outputlangs, '', 'standard', 'tmp_cards');
226 }
227 } elseif ($mode == 'cardlogin') {
228 if (!count($arrayofmembers)) {
229 $mesg = $langs->trans("ErrorRecordNotFound");
230 }
231 if (empty($model) || $model == '-1') {
232 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
233 }
234 if (!$mesg) {
235 $result = members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs, '', 'standard', 'tmp_cards_login');
236 }
237 } elseif ($mode == 'label') {
238 if (!count($arrayofmembers)) {
239 $mesg = $langs->trans("ErrorRecordNotFound");
240 }
241 if (empty($modellabel) || $modellabel == '-1') {
242 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
243 }
244 if (!$mesg) {
245 $result = doc_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
246 }
247 }
248
249 if ($result <= 0) {
250 dol_print_error(null, $result);
251 }
252 } else {
253 dol_print_error($db);
254 }
255
256 if (!$mesg) {
257 $db->close();
258 exit;
259 }
260}
261
262
263/*
264 * View
265 */
266
267$form = new Form($db);
268
269$title = $langs->trans('MembersCards');
270$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
271
272llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-cards');
273
274print load_fiche_titre($langs->trans("LinkToGeneratedPages"), '', $adherentstatic->picto);
275
276print '<span class="opacitymedium">'.$langs->trans("LinkToGeneratedPagesDesc").'</span><br>';
277print '<br>';
278
280
281print '<br>';
282
283print img_picto('', 'card').' '.$langs->trans("DocForAllMembersCards", getDolGlobalString('ADHERENT_CARD_TYPE', $langs->transnoentitiesnoconv("None"))).' ';
284print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
285print '<input type="hidden" name="token" value="'.newToken().'">';
286print '<input type="hidden" name="foruserid" value="all">';
287print '<input type="hidden" name="mode" value="card">';
288print '<input type="hidden" name="action" value="builddoc">';
289print $langs->trans("DescADHERENT_CARD_TYPE").' ';
290// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
291$arrayoflabels = array();
292foreach (array_keys($_Avery_Labels) as $codecards) {
293 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
294}
295asort($arrayoflabels);
296print $form->selectarray('modelcard', $arrayoflabels, (GETPOST('modelcard') ? GETPOST('modelcard') : getDolGlobalString('ADHERENT_CARD_TYPE')), 1, 0, 0, '', 0, 0, 0, '', '', 1);
297print '<br><input type="submit" class="button small" value="'.$langs->trans("BuildDoc").'">';
298print '</form>';
299
300print '<br><br>';
301
302print img_picto('', 'card').' '.$langs->trans("DocForOneMemberCards", getDolGlobalString('ADHERENT_CARD_TYPE', $langs->transnoentitiesnoconv("None"))).' ';
303print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
304print '<input type="hidden" name="token" value="'.newToken().'">';
305print '<input type="hidden" name="mode" value="cardlogin">';
306print '<input type="hidden" name="action" value="builddoc">';
307print $langs->trans("DescADHERENT_CARD_TYPE").' ';
308// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
309$arrayoflabels = array();
310foreach (array_keys($_Avery_Labels) as $codecards) {
311 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
312}
313asort($arrayoflabels);
314print $form->selectarray('model', $arrayoflabels, (GETPOST('model') ? GETPOST('model') : getDolGlobalString('ADHERENT_CARD_TYPE')), 1, 0, 0, '', 0, 0, 0, '', '', 1);
315print '<br>'.$langs->trans("Login").': <input class="width100" type="text" name="foruserlogin" value="'.GETPOST('foruserlogin').'">';
316print '<br><input type="submit" class="button small" value="'.$langs->trans("BuildDoc").'">';
317print '</form>';
318
319print '<br><br>';
320
321print img_picto('', 'card').' '.$langs->trans("DocForLabels", getDolGlobalString('ADHERENT_ETIQUETTE_TYPE')).' ';
322print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
323print '<input type="hidden" name="token" value="'.newToken().'">';
324print '<input type="hidden" name="mode" value="label">';
325print '<input type="hidden" name="action" value="builddoc">';
326print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
327// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
328$arrayoflabels = array();
329foreach (array_keys($_Avery_Labels) as $codecards) {
330 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
331}
332asort($arrayoflabels);
333print $form->selectarray('modellabel', $arrayoflabels, (GETPOST('modellabel') ? GETPOST('modellabel') : getDolGlobalString('ADHERENT_ETIQUETTE_TYPE')), 1, 0, 0, '', 0, 0, 0, '', '', 1);
334print '<br><input type="submit" class="button small" value="'.$langs->trans("BuildDoc").'">';
335print '</form>';
336
337// End of page
338llxFooter();
339$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
Class to manage members of a foundation.
Class to manage standard extra fields.
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)
llxFooter()
Footer empty.
Definition document.php:107
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").
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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.
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', $filename='tmp_cards')
Cree un fichier de cartes de visites en fonction du modele de 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:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
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.