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';
32 $langs->loadLangs(array(
"members",
"errors"));
39 $foruserid =
GETPOST(
'foruserid',
'alphanohtml');
40 $foruserlogin =
GETPOST(
'foruserlogin',
'alphanohtml');
41 $mode =
GETPOST(
'mode',
'aZ09');
42 $modelcard =
GETPOST(
"modelcard",
'aZ09');
43 $model =
GETPOST(
"model",
'aZ09');
44 $modellabel =
GETPOST(
"modellabel",
'aZ09');
52 $extrafields->fetch_name_optionals_label($object->table_element);
62 if ($mode ==
'cardlogin' && empty($foruserlogin)) {
63 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
66 if ((!empty($foruserid) || !empty($foruserlogin) || !empty($mode)) && !$mesg) {
67 $arrayofmembers = array();
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";
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 :
'');
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)";
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;
91 $sql .=
" AND d.login = '".$db->escape($foruserlogin).
"'";
93 $sql .=
" ORDER BY d.rowid ASC";
96 $result = $db->query(
$sql);
98 $num = $db->num_rows($result);
101 $objp = $db->fetch_object($result);
103 if ($objp->country ==
'-') {
107 $adherentstatic->id = $objp->rowid;
108 $adherentstatic->ref = $objp->ref;
109 $adherentstatic->lastname = $objp->lastname;
110 $adherentstatic->firstname = $objp->firstname;
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;
127 $substitutionarray = array(
128 '__ID__'=>$objp->rowid,
129 '__REF__'=>$objp->ref,
130 '__LOGIN__'=>$objp->login,
131 '__FIRSTNAME__'=>$objp->firstname,
132 '__LASTNAME__'=>$objp->lastname,
133 '__FULLNAME__'=>$adherentstatic->getFullName($langs),
134 '__COMPANY__'=>$objp->company,
135 '__ADDRESS__'=>$objp->address,
136 '__ZIP__'=>$objp->zip,
137 '__TOWN__'=>$objp->town,
138 '__COUNTRY__'=>$objp->country,
139 '__COUNTRY_CODE__'=>$objp->country_code,
140 '__EMAIL__'=>$objp->email,
142 '__TYPE__'=>$objp->type,
146 '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
147 '__SERVER__'=>
"https://".$_SERVER[
"SERVER_NAME"].
"/"
152 if (empty($mode) || $mode ==
'card' || $mode ==
'cardlogin') {
153 $textleft =
make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
154 $textheader =
make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
155 $textfooter =
make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
156 $textright =
make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
158 if (is_numeric($foruserid) || $foruserlogin) {
159 $nb = $_Avery_Labels[$model][
'NX'] * $_Avery_Labels[$model][
'NY'];
164 for ($j = 0; $j < $nb; $j++) {
165 $arrayofmembers[] = array(
166 'textleft'=>$textleft,
167 'textheader'=>$textheader,
168 'textfooter'=>$textfooter,
169 'textright'=>$textright,
172 'photo'=>$objp->photo
176 $arrayofmembers[] = array(
177 'textleft'=>$textleft,
178 'textheader'=>$textheader,
179 'textfooter'=>$textfooter,
180 'textright'=>$textright,
183 'photo'=>$objp->photo
189 if ($mode ==
'label') {
190 if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) {
191 $conf->global->ADHERENT_ETIQUETTE_TEXT =
"__FULLNAME__\n__ADDRESS__\n__ZIP__ __TOWN__\n__COUNTRY__";
193 $textleft =
make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
198 $arrayofmembers[] = array(
199 'textleft'=>$textleft,
200 'textheader'=>$textheader,
201 'textfooter'=>$textfooter,
202 'textright'=>$textright,
205 'photo'=>$objp->photo,
213 $outputlangs = $langs;
215 if (empty($mode) || $mode ==
'card') {
216 if (!count($arrayofmembers)) {
217 $mesg = $langs->trans(
"ErrorRecordNotFound");
219 if (empty($modelcard) || $modelcard ==
'-1') {
220 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_CARD_TYPE"));
223 $result =
members_card_pdf_create($db, $arrayofmembers, $modelcard, $outputlangs,
'',
'standard',
'tmp_cards');
225 } elseif ($mode ==
'cardlogin') {
226 if (!count($arrayofmembers)) {
227 $mesg = $langs->trans(
"ErrorRecordNotFound");
229 if (empty($model) || $model ==
'-1') {
230 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_CARD_TYPE"));
233 $result =
members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs,
'',
'standard',
'tmp_cards_login');
235 } elseif ($mode ==
'label') {
236 if (!count($arrayofmembers)) {
237 $mesg = $langs->trans(
"ErrorRecordNotFound");
239 if (empty($modellabel) || $modellabel ==
'-1') {
240 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_ETIQUETTE_TYPE"));
267 llxHeader(
'', $langs->trans(
"MembersCards"));
269 print
load_fiche_titre($langs->trans(
"LinkToGeneratedPages"),
'', $adherentstatic->picto);
271 print
'<span class="opacitymedium">'.$langs->trans(
"LinkToGeneratedPagesDesc").
'</span><br>';
278 print
img_picto(
'',
'card').
' '.$langs->trans(
"DocForAllMembersCards", (!empty($conf->global->ADHERENT_CARD_TYPE) ? $conf->global->ADHERENT_CARD_TYPE : $langs->transnoentitiesnoconv(
"None"))).
' ';
279 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
280 print
'<input type="hidden" name="token" value="'.newToken().
'">';
281 print
'<input type="hidden" name="foruserid" value="all">';
282 print
'<input type="hidden" name="mode" value="card">';
283 print
'<input type="hidden" name="action" value="builddoc">';
284 print $langs->trans(
"DescADHERENT_CARD_TYPE").
' ';
286 $arrayoflabels = array();
287 foreach (array_keys($_Avery_Labels) as $codecards) {
288 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards][
'name'];
290 asort($arrayoflabels);
291 print
$form->selectarray(
'modelcard', $arrayoflabels, (
GETPOST(
'modelcard') ?
GETPOST(
'modelcard') : (empty($conf->global->ADHERENT_CARD_TYPE) ?
'' : $conf->global->ADHERENT_CARD_TYPE)), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
292 print
'<br><input type="submit" class="button small" value="'.$langs->trans(
"BuildDoc").
'">';
297 print
img_picto(
'',
'card').
' '.$langs->trans(
"DocForOneMemberCards", (!empty($conf->global->ADHERENT_CARD_TYPE) ? $conf->global->ADHERENT_CARD_TYPE : $langs->transnoentitiesnoconv(
"None"))).
' ';
298 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
299 print
'<input type="hidden" name="token" value="'.newToken().
'">';
300 print
'<input type="hidden" name="mode" value="cardlogin">';
301 print
'<input type="hidden" name="action" value="builddoc">';
302 print $langs->trans(
"DescADHERENT_CARD_TYPE").
' ';
304 $arrayoflabels = array();
305 foreach (array_keys($_Avery_Labels) as $codecards) {
306 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards][
'name'];
308 asort($arrayoflabels);
309 print
$form->selectarray(
'model', $arrayoflabels, (
GETPOST(
'model') ?
GETPOST(
'model') : (empty($conf->global->ADHERENT_CARD_TYPE) ?
'' : $conf->global->ADHERENT_CARD_TYPE)), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
310 print
'<br>'.$langs->trans(
"Login").
': <input class="with100" type="text" name="foruserlogin" value="'.
GETPOST(
'foruserlogin').
'">';
311 print
'<br><input type="submit" class="button small" value="'.$langs->trans(
"BuildDoc").
'">';
316 print
img_picto(
'',
'card').
' '.$langs->trans(
"DocForLabels", (empty($conf->global->ADHERENT_ETIQUETTE_TYPE) ?
'' : $conf->global->ADHERENT_ETIQUETTE_TYPE)).
' ';
317 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
318 print
'<input type="hidden" name="token" value="'.newToken().
'">';
319 print
'<input type="hidden" name="mode" value="label">';
320 print
'<input type="hidden" name="action" value="builddoc">';
321 print $langs->trans(
"DescADHERENT_ETIQUETTE_TYPE").
' ';
323 $arrayoflabels = array();
324 foreach (array_keys($_Avery_Labels) as $codecards) {
325 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards][
'name'];
327 asort($arrayoflabels);
328 print
$form->selectarray(
'modellabel', $arrayoflabels, (
GETPOST(
'modellabel') ?
GETPOST(
'modellabel') : (empty($conf->global->ADHERENT_ETIQUETTE_TYPE) ?
'' : $conf->global->ADHERENT_ETIQUETTE_TYPE)), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
329 print
'<br><input type="submit" class="button small" value="'.$langs->trans(
"BuildDoc").
'">';