dolibarr  13.0.2
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 
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
30 require_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 $model = GETPOST("model", 'aZ09'); // Doc template to use for business cards
43 $modellabel = GETPOST("modellabel", 'aZ09'); // Doc template to use for address sheet
44 $mesg = '';
45 
46 $adherentstatic = new Adherent($db);
47 $object = new Adherent($db);
48 
49 $extrafields = new ExtraFields($db);
50 // Fetch optionals attributes and labels
51 $extrafields->fetch_name_optionals_label($object->table_element);
52 
53 
54 /*
55  * Actions
56  */
57 
58 if ($mode == 'cardlogin' && empty($foruserlogin)) {
59  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"));
60 }
61 
62 if ((!empty($foruserid) || !empty($foruserlogin) || !empty($mode)) && !$mesg) {
63  $arrayofmembers = array();
64 
65  // request taking into account member with up to date subscriptions
66  $sql = "SELECT d.rowid, d.firstname, d.lastname, d.login, d.societe as company, d.datefin,";
67  $sql .= " d.address, d.zip, d.town, d.country, d.birth, d.email, d.photo,";
68  $sql .= " t.libelle as type,";
69  $sql .= " c.code as country_code, c.label as country";
70  // Add fields from extrafields
71  if (!empty($extrafields->attributes[$object->table_element]['label']))
72  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
73  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
74  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
75  if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)";
76  $sql .= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
77  $sql .= " AND d.entity IN (".getEntity('adherent').")";
78  if (is_numeric($foruserid)) $sql .= " AND d.rowid=".$foruserid;
79  if ($foruserlogin) $sql .= " AND d.login='".$db->escape($foruserlogin)."'";
80  $sql .= " ORDER BY d.rowid ASC";
81 
82  dol_syslog("Search members", LOG_DEBUG);
83  $result = $db->query($sql);
84  if ($result) {
85  $num = $db->num_rows($result);
86  $i = 0;
87  while ($i < $num) {
88  $objp = $db->fetch_object($result);
89 
90  if ($objp->country == '-') $objp->country = '';
91 
92  $adherentstatic->id = $objp->rowid;
93  $adherentstatic->lastname = $objp->lastname;
94  $adherentstatic->firstname = $objp->firstname;
95 
96  // Format extrafield so they can be parsed in function complete_substitutions_array
97  if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
98  $adherentstatic->array_options = array();
99  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
100  $tmpkey = 'options_'.$key;
101  if (!empty($objp->$tmpkey)) {
102  $adherentstatic->array_options[$tmpkey] = $objp->$tmpkey;
103  }
104  //if (!empty($objp->$key))
105  // $objp->array_options[$tmpkey] = $objp->$key;
106  //$objp->array_options[$tmpkey] = $extrafields->showOutputField($key, $objp->$tmpkey, '', 1); //$objp->$tmpkey;
107  }
108  }
109 
110  // List of values to scan for a replacement
111  $substitutionarray = array(
112  '__ID__'=>$objp->rowid,
113  '__LOGIN__'=>$objp->login,
114  '__FIRSTNAME__'=>$objp->firstname,
115  '__LASTNAME__'=>$objp->lastname,
116  '__FULLNAME__'=>$adherentstatic->getFullName($langs),
117  '__COMPANY__'=>$objp->company,
118  '__ADDRESS__'=>$objp->address,
119  '__ZIP__'=>$objp->zip,
120  '__TOWN__'=>$objp->town,
121  '__COUNTRY__'=>$objp->country,
122  '__COUNTRY_CODE__'=>$objp->country_code,
123  '__EMAIL__'=>$objp->email,
124  '__BIRTH__'=>dol_print_date($objp->birth, 'day'),
125  '__TYPE__'=>$objp->type,
126  '__YEAR__'=>$year,
127  '__MONTH__'=>$month,
128  '__DAY__'=>$day,
129  '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
130  '__SERVER__'=>"http://".$_SERVER["SERVER_NAME"]."/"
131  );
132  complete_substitutions_array($substitutionarray, $langs, $adherentstatic);
133 
134  // For business cards
135  if (empty($mode) || $mode == 'card' || $mode == 'cardlogin') {
136  $textleft = make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
137  $textheader = make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
138  $textfooter = make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
139  $textright = make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
140 
141  if (is_numeric($foruserid) || $foruserlogin) {
142  $nb = $_Avery_Labels[$model]['NX'] * $_Avery_Labels[$model]['NY'];
143  if ($nb <= 0) $nb = 1; // Protection to avoid empty page
144 
145  for ($j = 0; $j < $nb; $j++) {
146  $arrayofmembers[] = array(
147  'textleft'=>$textleft,
148  'textheader'=>$textheader,
149  'textfooter'=>$textfooter,
150  'textright'=>$textright,
151  'id'=>$objp->rowid,
152  'photo'=>$objp->photo
153  );
154  }
155  } else {
156  $arrayofmembers[] = array(
157  'textleft'=>$textleft,
158  'textheader'=>$textheader,
159  'textfooter'=>$textfooter,
160  'textright'=>$textright,
161  'id'=>$objp->rowid,
162  'photo'=>$objp->photo
163  );
164  }
165  }
166 
167  // For labels
168  if ($mode == 'label') {
169  if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT = "__FULLNAME__\n__ADDRESS__\n__ZIP__ __TOWN__\n__COUNTRY__";
170  $textleft = make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
171  $textheader = '';
172  $textfooter = '';
173  $textright = '';
174 
175  $arrayofmembers[] = array('textleft'=>$textleft,
176  'textheader'=>$textheader,
177  'textfooter'=>$textfooter,
178  'textright'=>$textright,
179  'id'=>$objp->rowid,
180  'photo'=>$objp->photo);
181  }
182 
183  $i++;
184  }
185 
186  // Build and output PDF
187  if (empty($mode) || $mode == 'card' || $mode == 'cardlogin') {
188  if (!count($arrayofmembers)) {
189  $mesg = $langs->trans("ErrorRecordNotFound");
190  }
191  if (empty($model) || $model == '-1') {
192  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
193  }
194  if (!$mesg) $result = members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs);
195  } elseif ($mode == 'label') {
196  if (!count($arrayofmembers)) {
197  $mesg = $langs->trans("ErrorRecordNotFound");
198  }
199  if (empty($modellabel) || $modellabel == '-1') {
200  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
201  }
202  if (!$mesg) $result = doc_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
203  }
204 
205  if ($result <= 0) {
206  dol_print_error('', $result);
207  }
208  } else {
209  dol_print_error($db);
210  }
211 
212  if (!$mesg) {
213  $db->close();
214  exit;
215  }
216 }
217 
218 
219 /*
220  * View
221  */
222 
223 $form = new Form($db);
224 
225 llxHeader('', $langs->trans("MembersCards"));
226 
227 print load_fiche_titre($langs->trans("LinkToGeneratedPages"), '', 'members');
228 
229 print '<span class="opacitymedium">'.$langs->trans("LinkToGeneratedPagesDesc").'</span><br>';
230 print '<br>';
231 
232 dol_htmloutput_errors($mesg);
233 
234 print '<br>';
235 
236 print img_picto('', 'puce').' '.$langs->trans("DocForAllMembersCards", ($conf->global->ADHERENT_CARD_TYPE ? $conf->global->ADHERENT_CARD_TYPE : $langs->transnoentitiesnoconv("None"))).' ';
237 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
238 print '<input type="hidden" name="token" value="'.newToken().'">';
239 print '<input type="hidden" name="foruserid" value="all">';
240 print '<input type="hidden" name="mode" value="card">';
241 print '<input type="hidden" name="action" value="builddoc">';
242 print $langs->trans("DescADHERENT_CARD_TYPE").' ';
243 // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
244 $arrayoflabels = array();
245 foreach (array_keys($_Avery_Labels) as $codecards) {
246  $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
247 }
248 asort($arrayoflabels);
249 print $form->selectarray('model', $arrayoflabels, (GETPOST('model') ?GETPOST('model') : $conf->global->ADHERENT_CARD_TYPE), 1, 0, 0, '', 0, 0, 0, '', '', 1);
250 print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
251 print '</form>';
252 
253 print '<br><br>';
254 
255 print img_picto('', 'puce').' '.$langs->trans("DocForOneMemberCards", ($conf->global->ADHERENT_CARD_TYPE ? $conf->global->ADHERENT_CARD_TYPE : $langs->transnoentitiesnoconv("None"))).' ';
256 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
257 print '<input type="hidden" name="token" value="'.newToken().'">';
258 print '<input type="hidden" name="mode" value="cardlogin">';
259 print '<input type="hidden" name="action" value="builddoc">';
260 print $langs->trans("DescADHERENT_CARD_TYPE").' ';
261 // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
262 $arrayoflabels = array();
263 foreach (array_keys($_Avery_Labels) as $codecards) {
264  $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
265 }
266 asort($arrayoflabels);
267 print $form->selectarray('model', $arrayoflabels, (GETPOST('model') ?GETPOST('model') : $conf->global->ADHERENT_CARD_TYPE), 1, 0, 0, '', 0, 0, 0, '', '', 1);
268 print '<br>'.$langs->trans("Login").': <input size="10" type="text" name="foruserlogin" value="'.GETPOST('foruserlogin').'">';
269 print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
270 print '</form>';
271 
272 print '<br><br>';
273 
274 print img_picto('', 'puce').' '.$langs->trans("DocForLabels", $conf->global->ADHERENT_ETIQUETTE_TYPE).' ';
275 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
276 print '<input type="hidden" name="token" value="'.newToken().'">';
277 print '<input type="hidden" name="mode" value="label">';
278 print '<input type="hidden" name="action" value="builddoc">';
279 print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
280 // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
281 $arrayoflabels = array();
282 foreach (array_keys($_Avery_Labels) as $codecards) {
283  $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
284 }
285 asort($arrayoflabels);
286 print $form->selectarray('modellabel', $arrayoflabels, (GETPOST('modellabel') ?GETPOST('modellabel') : $conf->global->ADHERENT_ETIQUETTE_TYPE), 1, 0, 0, '', 0, 0, 0, '', '', 1);
287 print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
288 print '</form>';
289 
290 // End of page
291 llxFooter();
292 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir= '', $template= 'standard')
Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage members of a foundation.
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.
print
Draft customers invoices.
Definition: index.php:89
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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
dol_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
llxFooter()
Empty footer.
Definition: wrapper.php:59
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 &quot;subst...