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