carte.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. /**
  20. * \file htdocs/adherents/cartes/carte.php
  21. * \ingroup member
  22. * \brief Page to output members business cards
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/modules/printsheet/modules_labels.php';
  30. $langs->loadLangs(array("members", "errors"));
  31. // Choice of printing year or current year.
  32. $now = dol_now();
  33. $year = dol_print_date($now, '%Y');
  34. $month = dol_print_date($now, '%m');
  35. $day = dol_print_date($now, '%d');
  36. $foruserid = GETPOST('foruserid', 'alphanohtml');
  37. $foruserlogin = GETPOST('foruserlogin', 'alphanohtml');
  38. $mode = GETPOST('mode', 'aZ09');
  39. $model = GETPOST("model", 'aZ09'); // Doc template to use for business cards
  40. $modellabel = GETPOST("modellabel", 'aZ09'); // Doc template to use for address sheet
  41. $mesg = '';
  42. $adherentstatic = new Adherent($db);
  43. $object = new Adherent($db);
  44. $extrafields = new ExtraFields($db);
  45. // Fetch optionals attributes and labels
  46. $extrafields->fetch_name_optionals_label($object->table_element);
  47. /*
  48. * Actions
  49. */
  50. if ($mode == 'cardlogin' && empty($foruserlogin))
  51. {
  52. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"));
  53. }
  54. if ((!empty($foruserid) || !empty($foruserlogin) || !empty($mode)) && !$mesg)
  55. {
  56. $arrayofmembers = array();
  57. // request taking into account member with up to date subscriptions
  58. $sql = "SELECT d.rowid, d.firstname, d.lastname, d.login, d.societe as company, d.datefin,";
  59. $sql .= " d.address, d.zip, d.town, d.country, d.birth, d.email, d.photo,";
  60. $sql .= " t.libelle as type,";
  61. $sql .= " c.code as country_code, c.label as country";
  62. // Add fields from extrafields
  63. if (!empty($extrafields->attributes[$object->table_element]['label']))
  64. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
  65. $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
  66. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
  67. 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)";
  68. $sql .= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
  69. $sql .= " AND d.entity IN (".getEntity('adherent').")";
  70. if (is_numeric($foruserid)) $sql .= " AND d.rowid=".$foruserid;
  71. if ($foruserlogin) $sql .= " AND d.login='".$db->escape($foruserlogin)."'";
  72. $sql .= " ORDER BY d.rowid ASC";
  73. dol_syslog("Search members", LOG_DEBUG);
  74. $result = $db->query($sql);
  75. if ($result)
  76. {
  77. $num = $db->num_rows($result);
  78. $i = 0;
  79. while ($i < $num)
  80. {
  81. $objp = $db->fetch_object($result);
  82. if ($objp->country == '-') $objp->country = '';
  83. $adherentstatic->id = $objp->rowid;
  84. $adherentstatic->lastname = $objp->lastname;
  85. $adherentstatic->firstname = $objp->firstname;
  86. // Format extrafield so they can be parsed in function complete_substitutions_array
  87. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']))
  88. {
  89. $adherentstatic->array_options = array();
  90. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
  91. {
  92. $tmpkey = 'options_'.$key;
  93. if (!empty($objp->$tmpkey))
  94. {
  95. $adherentstatic->array_options[$tmpkey] = $objp->$tmpkey;
  96. }
  97. //if (!empty($objp->$key))
  98. // $objp->array_options[$tmpkey] = $objp->$key;
  99. //$objp->array_options[$tmpkey] = $extrafields->showOutputField($key, $objp->$tmpkey, '', 1); //$objp->$tmpkey;
  100. }
  101. }
  102. // List of values to scan for a replacement
  103. $substitutionarray = array(
  104. '__ID__'=>$objp->rowid,
  105. '__LOGIN__'=>$objp->login,
  106. '__FIRSTNAME__'=>$objp->firstname,
  107. '__LASTNAME__'=>$objp->lastname,
  108. '__FULLNAME__'=>$adherentstatic->getFullName($langs),
  109. '__COMPANY__'=>$objp->company,
  110. '__ADDRESS__'=>$objp->address,
  111. '__ZIP__'=>$objp->zip,
  112. '__TOWN__'=>$objp->town,
  113. '__COUNTRY__'=>$objp->country,
  114. '__COUNTRY_CODE__'=>$objp->country_code,
  115. '__EMAIL__'=>$objp->email,
  116. '__BIRTH__'=>dol_print_date($objp->birth, 'day'),
  117. '__TYPE__'=>$objp->type,
  118. '__YEAR__'=>$year,
  119. '__MONTH__'=>$month,
  120. '__DAY__'=>$day,
  121. '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
  122. '__SERVER__'=>"http://".$_SERVER["SERVER_NAME"]."/"
  123. );
  124. complete_substitutions_array($substitutionarray, $langs, $adherentstatic);
  125. // For business cards
  126. if (empty($mode) || $mode == 'card' || $mode == 'cardlogin')
  127. {
  128. $textleft = make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
  129. $textheader = make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
  130. $textfooter = make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
  131. $textright = make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
  132. if (is_numeric($foruserid) || $foruserlogin)
  133. {
  134. $nb = $_Avery_Labels[$model]['NX'] * $_Avery_Labels[$model]['NY'];
  135. if ($nb <= 0) $nb = 1; // Protection to avoid empty page
  136. for ($j = 0; $j < $nb; $j++)
  137. {
  138. $arrayofmembers[] = array(
  139. 'textleft'=>$textleft,
  140. 'textheader'=>$textheader,
  141. 'textfooter'=>$textfooter,
  142. 'textright'=>$textright,
  143. 'id'=>$objp->rowid,
  144. 'photo'=>$objp->photo
  145. );
  146. }
  147. }
  148. else
  149. {
  150. $arrayofmembers[] = array(
  151. 'textleft'=>$textleft,
  152. 'textheader'=>$textheader,
  153. 'textfooter'=>$textfooter,
  154. 'textright'=>$textright,
  155. 'id'=>$objp->rowid,
  156. 'photo'=>$objp->photo
  157. );
  158. }
  159. }
  160. // For labels
  161. if ($mode == 'label')
  162. {
  163. if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT = "__FULLNAME__\n__ADDRESS__\n__ZIP__ __TOWN__\n__COUNTRY__";
  164. $textleft = make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
  165. $textheader = '';
  166. $textfooter = '';
  167. $textright = '';
  168. $arrayofmembers[] = array('textleft'=>$textleft,
  169. 'textheader'=>$textheader,
  170. 'textfooter'=>$textfooter,
  171. 'textright'=>$textright,
  172. 'id'=>$objp->rowid,
  173. 'photo'=>$objp->photo);
  174. }
  175. $i++;
  176. }
  177. // Build and output PDF
  178. if (empty($mode) || $mode == 'card' || $mode == 'cardlogin')
  179. {
  180. if (!count($arrayofmembers))
  181. {
  182. $mesg = $langs->trans("ErrorRecordNotFound");
  183. }
  184. if (empty($model) || $model == '-1')
  185. {
  186. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
  187. }
  188. if (!$mesg) $result = members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs);
  189. }
  190. elseif ($mode == 'label')
  191. {
  192. if (!count($arrayofmembers))
  193. {
  194. $mesg = $langs->trans("ErrorRecordNotFound");
  195. }
  196. if (empty($modellabel) || $modellabel == '-1')
  197. {
  198. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
  199. }
  200. if (!$mesg) $result = doc_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
  201. }
  202. if ($result <= 0)
  203. {
  204. dol_print_error('', $result);
  205. }
  206. }
  207. else
  208. {
  209. dol_print_error($db);
  210. }
  211. if (!$mesg)
  212. {
  213. $db->close();
  214. exit;
  215. }
  216. }
  217. /*
  218. * View
  219. */
  220. $form = new Form($db);
  221. llxHeader('', $langs->trans("MembersCards"));
  222. print load_fiche_titre($langs->trans("LinkToGeneratedPages"), '', 'members');
  223. print '<span class="opacitymedium">'.$langs->trans("LinkToGeneratedPagesDesc").'</span><br>';
  224. print '<br>';
  225. dol_htmloutput_errors($mesg);
  226. print '<br>';
  227. print img_picto('', 'puce').' '.$langs->trans("DocForAllMembersCards", ($conf->global->ADHERENT_CARD_TYPE ? $conf->global->ADHERENT_CARD_TYPE : $langs->transnoentitiesnoconv("None"))).' ';
  228. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  229. print '<input type="hidden" name="token" value="'.newToken().'">';
  230. print '<input type="hidden" name="foruserid" value="all">';
  231. print '<input type="hidden" name="mode" value="card">';
  232. print '<input type="hidden" name="action" value="builddoc">';
  233. print $langs->trans("DescADHERENT_CARD_TYPE").' ';
  234. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  235. $arrayoflabels = array();
  236. foreach (array_keys($_Avery_Labels) as $codecards)
  237. {
  238. $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
  239. }
  240. asort($arrayoflabels);
  241. print $form->selectarray('model', $arrayoflabels, (GETPOST('model') ?GETPOST('model') : $conf->global->ADHERENT_CARD_TYPE), 1, 0, 0, '', 0, 0, 0, '', '', 1);
  242. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  243. print '</form>';
  244. print '<br><br>';
  245. print img_picto('', 'puce').' '.$langs->trans("DocForOneMemberCards", ($conf->global->ADHERENT_CARD_TYPE ? $conf->global->ADHERENT_CARD_TYPE : $langs->transnoentitiesnoconv("None"))).' ';
  246. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  247. print '<input type="hidden" name="token" value="'.newToken().'">';
  248. print '<input type="hidden" name="mode" value="cardlogin">';
  249. print '<input type="hidden" name="action" value="builddoc">';
  250. print $langs->trans("DescADHERENT_CARD_TYPE").' ';
  251. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  252. $arrayoflabels = array();
  253. foreach (array_keys($_Avery_Labels) as $codecards)
  254. {
  255. $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
  256. }
  257. asort($arrayoflabels);
  258. print $form->selectarray('model', $arrayoflabels, (GETPOST('model') ?GETPOST('model') : $conf->global->ADHERENT_CARD_TYPE), 1, 0, 0, '', 0, 0, 0, '', '', 1);
  259. print '<br>'.$langs->trans("Login").': <input size="10" type="text" name="foruserlogin" value="'.GETPOST('foruserlogin').'">';
  260. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  261. print '</form>';
  262. print '<br><br>';
  263. print img_picto('', 'puce').' '.$langs->trans("DocForLabels", $conf->global->ADHERENT_ETIQUETTE_TYPE).' ';
  264. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  265. print '<input type="hidden" name="token" value="'.newToken().'">';
  266. print '<input type="hidden" name="mode" value="label">';
  267. print '<input type="hidden" name="action" value="builddoc">';
  268. print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
  269. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  270. $arrayoflabels = array();
  271. foreach (array_keys($_Avery_Labels) as $codecards)
  272. {
  273. $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
  274. }
  275. asort($arrayoflabels);
  276. print $form->selectarray('modellabel', $arrayoflabels, (GETPOST('modellabel') ?GETPOST('modellabel') : $conf->global->ADHERENT_ETIQUETTE_TYPE), 1, 0, 0, '', 0, 0, 0, '', '', 1);
  277. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  278. print '</form>';
  279. // End of page
  280. llxFooter();
  281. $db->close();