carte.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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-2010 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 2 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 <http://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."/lib/files.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/includes/modules/member/cards/modules_cards.php");
  28. require_once(DOL_DOCUMENT_ROOT."/includes/modules/member/labels/modules_labels.php");
  29. $langs->load("members");
  30. $langs->load("errors");
  31. // Choix de l'annee d'impression ou annee courante.
  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');
  37. $foruserlogin=GETPOST('foruserlogin');
  38. $mode=GETPOST('mode');
  39. $mesg='';
  40. /*
  41. * View
  42. */
  43. if ($mode == 'cardlogin' && empty($foruserlogin))
  44. {
  45. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Login"));
  46. }
  47. if ((empty($foruserid) && empty($foruserlogin) && empty($mode)) || $mesg)
  48. {
  49. llxHeader('',$langs->trans("MembersCards"));
  50. print_fiche_titre($langs->trans("LinkToGeneratedPages"));
  51. print '<br>';
  52. print $langs->trans("LinkToGeneratedPagesDesc").'<br>';
  53. print '<br>';
  54. if ($mesg) print '<div class="error">'.$mesg.'</div><br>';
  55. print $langs->trans("DocForAllMembersCards",($conf->global->ADHERENT_CARD_TYPE?$conf->global->ADHERENT_CARD_TYPE:$langs->transnoentitiesnoconv("None"))).' ';
  56. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  57. print '<input type="hidden" name="foruserid" value="all">';
  58. print '<input type="hidden" name="mode" value="card">';
  59. print ' <input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  60. print '</form>';
  61. print '<br>';
  62. print $langs->trans("DocForOneMemberCards",($conf->global->ADHERENT_CARD_TYPE?$conf->global->ADHERENT_CARD_TYPE:$langs->transnoentitiesnoconv("None"))).' ';
  63. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  64. print '<input type="hidden" name="mode" value="cardlogin">';
  65. print $langs->trans("Login").': <input size="10" type="text" name="foruserlogin" value="">';
  66. print ' <input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  67. print '</form>';
  68. print '<br>';
  69. print $langs->trans("DocForLabels",$conf->global->ADHERENT_ETIQUETTE_TYPE).' ';
  70. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  71. print '<input type="hidden" name="mode" value="label">';
  72. print ' <input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  73. print '</form>';
  74. print '<br>';
  75. llxFooter();
  76. }
  77. else
  78. {
  79. $arrayofmembers=array();
  80. // requete en prenant que les adherents a jour de cotisation
  81. $sql = "SELECT d.rowid, d.prenom, d.nom, d.login, d.societe, d.datefin,";
  82. $sql.= " d.adresse, d.cp, d.ville, d.naiss, d.email, d.photo,";
  83. $sql.= " t.libelle as type,";
  84. $sql.= " p.libelle as pays";
  85. $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
  86. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid";
  87. $sql.= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
  88. if (is_numeric($foruserid)) $sql.=" AND d.rowid=".$foruserid;
  89. if ($foruserlogin) $sql.=" AND d.login='".$db->escape($foruserlogin)."'";
  90. $sql.= " ORDER BY d.rowid ASC";
  91. $result = $db->query($sql);
  92. if ($result)
  93. {
  94. $num = $db->num_rows($result);
  95. $i = 0;
  96. while ($i < $num)
  97. {
  98. $objp = $db->fetch_object($result);
  99. if ($objp->pays == '-') $objp->pays='';
  100. // List of values to scan for a replacement
  101. $substitutionarray = array (
  102. '%PRENOM%'=>$objp->prenom,
  103. '%NOM%'=>$objp->nom,
  104. '%LOGIN%'=>$objp->login,
  105. '%SERVEUR%'=>"http://".$_SERVER["SERVER_NAME"]."/",
  106. '%SOCIETE%'=>$objp->societe,
  107. '%ADRESSE%'=>$objp->adresse,
  108. '%CP%'=>$objp->cp,
  109. '%VILLE%'=>$objp->ville,
  110. '%PAYS%'=>$objp->pays,
  111. '%EMAIL%'=>$objp->email,
  112. '%NAISS%'=>dol_print_date($objp->naiss,'day'),
  113. '%TYPE%'=>$objp->type,
  114. '%ID%'=>$objp->rowid,
  115. '%ANNEE%'=>$year, // For backward compatibility
  116. '%YEAR%'=>$year,
  117. '%MONTH%'=>$month,
  118. '%DAY%'=>$day
  119. );
  120. complete_substitutions_array($substitutionarray, $langs);
  121. // For business cards
  122. if (empty($mode) || $mode=='card' || $mode=='cardlogin')
  123. {
  124. $textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
  125. $textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
  126. $textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
  127. $textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
  128. if (is_numeric($foruserid) || $foruserlogin)
  129. {
  130. for($j=0;$j<100;$j++)
  131. {
  132. $arrayofmembers[]=array('textleft'=>$textleft,
  133. 'textheader'=>$textheader,
  134. 'textfooter'=>$textfooter,
  135. 'textright'=>$textright,
  136. 'id'=>$objp->rowid,
  137. 'photo'=>$objp->photo);
  138. }
  139. }
  140. else
  141. {
  142. $arrayofmembers[]=array('textleft'=>$textleft,
  143. 'textheader'=>$textheader,
  144. 'textfooter'=>$textfooter,
  145. 'textright'=>$textright,
  146. 'id'=>$objp->rowid,
  147. 'photo'=>$objp->photo);
  148. }
  149. }
  150. // For labels
  151. if ($mode == 'label')
  152. {
  153. $conf->global->ADHERENT_ETIQUETTE_TEXT="%PRENOM% %NOM%\n%ADRESSE%\n%CP% %VILLE%\n%PAYS%";
  154. $textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
  155. $textheader='';
  156. $textfooter='';
  157. $textright='';
  158. $arrayofmembers[]=array('textleft'=>$textleft,
  159. 'textheader'=>$textheader,
  160. 'textfooter'=>$textfooter,
  161. 'textright'=>$textright,
  162. 'id'=>$objp->rowid,
  163. 'photo'=>$objp->photo);
  164. }
  165. $i++;
  166. }
  167. // Build and output PDF
  168. if (empty($mode) || $mode=='card' || $mode='cardlogin')
  169. {
  170. $result=members_card_pdf_create($db, $arrayofmembers, '', $outputlangs);
  171. }
  172. if ($mode == 'label')
  173. {
  174. $result=members_label_pdf_create($db, $arrayofmembers, '', $outputlangs);
  175. }
  176. if ($result <= 0)
  177. {
  178. dol_print_error($db,$result);
  179. exit;
  180. }
  181. }
  182. else
  183. {
  184. dol_print_error($db);
  185. llxFooter();
  186. }
  187. }
  188. ?>