carte.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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-2011 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 <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.'/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->load("members");
  31. $langs->load("errors");
  32. // Choix de l'annee d'impression ou annee courante.
  33. $now = dol_now();
  34. $year=dol_print_date($now,'%Y');
  35. $month=dol_print_date($now,'%m');
  36. $day=dol_print_date($now,'%d');
  37. $foruserid=GETPOST('foruserid');
  38. $foruserlogin=GETPOST('foruserlogin');
  39. $mode=GETPOST('mode');
  40. $model=GETPOST("model"); // Doc template to use for business cards
  41. $modellabel=GETPOST("modellabel"); // Doc template to use for address sheet
  42. $mesg='';
  43. $adherentstatic=new Adherent($db);
  44. /*
  45. * Actions
  46. */
  47. if ($mode == 'cardlogin' && empty($foruserlogin))
  48. {
  49. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Login"));
  50. }
  51. if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg)
  52. {
  53. $arrayofmembers=array();
  54. // requete en prenant que les adherents a jour de cotisation
  55. $sql = "SELECT d.rowid, d.firstname, d.lastname, d.login, d.societe as company, d.datefin,";
  56. $sql.= " d.address, d.zip, d.town, d.country, d.birth, d.email, d.photo,";
  57. $sql.= " t.libelle as type,";
  58. $sql.= " p.code as country_code, p.libelle as country";
  59. $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
  60. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.country = p.rowid";
  61. $sql.= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
  62. if (is_numeric($foruserid)) $sql.=" AND d.rowid=".$foruserid;
  63. if ($foruserlogin) $sql.=" AND d.login='".$db->escape($foruserlogin)."'";
  64. $sql.= " ORDER BY d.rowid ASC";
  65. dol_syslog("Search members sql=".$sql);
  66. $result = $db->query($sql);
  67. if ($result)
  68. {
  69. $num = $db->num_rows($result);
  70. $i = 0;
  71. while ($i < $num)
  72. {
  73. $objp = $db->fetch_object($result);
  74. if ($objp->country == '-') $objp->country='';
  75. $adherentstatic->lastname=$objp->lastname;
  76. $adherentstatic->firstname=$objp->firstname;
  77. // List of values to scan for a replacement
  78. $substitutionarray = array (
  79. '%ID%'=>$objp->rowid,
  80. '%LOGIN%'=>$objp->login,
  81. '%FIRSTNAME%'=>$objp->firstname,
  82. '%LASTNAME%'=>$objp->lastname,
  83. '%FULLNAME%'=>$adherentstatic->getFullName($langs),
  84. '%COMPANY%'=>$objp->company,
  85. '%ADDRESS%'=>$objp->address,
  86. '%ZIP%'=>$objp->zip,
  87. '%TOWN%'=>$objp->town,
  88. '%COUNTRY%'=>$objp->country,
  89. '%COUNTRY_CODE%'=>$objp->country_code,
  90. '%EMAIL%'=>$objp->email,
  91. '%BIRTH%'=>dol_print_date($objp->birth,'day'),
  92. '%TYPE%'=>$objp->type,
  93. '%YEAR%'=>$year,
  94. '%MONTH%'=>$month,
  95. '%DAY%'=>$day,
  96. '%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
  97. '%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/"
  98. );
  99. complete_substitutions_array($substitutionarray, $langs);
  100. // For business cards
  101. if (empty($mode) || $mode=='card' || $mode=='cardlogin')
  102. {
  103. $textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
  104. $textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
  105. $textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
  106. $textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
  107. if (is_numeric($foruserid) || $foruserlogin)
  108. {
  109. for($j=0;$j<100;$j++)
  110. {
  111. $arrayofmembers[]=array(
  112. 'textleft'=>$textleft,
  113. 'textheader'=>$textheader,
  114. 'textfooter'=>$textfooter,
  115. 'textright'=>$textright,
  116. 'id'=>$objp->rowid,
  117. 'photo'=>$objp->photo
  118. );
  119. }
  120. }
  121. else
  122. {
  123. $arrayofmembers[]=array(
  124. 'textleft'=>$textleft,
  125. 'textheader'=>$textheader,
  126. 'textfooter'=>$textfooter,
  127. 'textright'=>$textright,
  128. 'id'=>$objp->rowid,
  129. 'photo'=>$objp->photo
  130. );
  131. }
  132. }
  133. // For labels
  134. if ($mode == 'label')
  135. {
  136. if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT="%FULLNAME%\n%ADDRESS%\n%ZIP% %TOWN%\n%COUNTRY%";
  137. $textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
  138. $textheader='';
  139. $textfooter='';
  140. $textright='';
  141. $arrayofmembers[]=array('textleft'=>$textleft,
  142. 'textheader'=>$textheader,
  143. 'textfooter'=>$textfooter,
  144. 'textright'=>$textright,
  145. 'id'=>$objp->rowid,
  146. 'photo'=>$objp->photo);
  147. }
  148. $i++;
  149. }
  150. // Build and output PDF
  151. if (empty($mode) || $mode=='card' || $mode=='cardlogin')
  152. {
  153. if (! count($arrayofmembers))
  154. {
  155. $mesg=$langs->trans("ErrorRecordNotFound");
  156. }
  157. if (empty($model) || $model == '-1')
  158. {
  159. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
  160. }
  161. if (! $mesg) $result=members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs);
  162. }
  163. elseif ($mode == 'label')
  164. {
  165. if (! count($arrayofmembers))
  166. {
  167. $mesg=$langs->trans("ErrorRecordNotFound");
  168. }
  169. if (empty($modellabel) || $modellabel == '-1')
  170. {
  171. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
  172. }
  173. if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
  174. }
  175. if ($result <= 0)
  176. {
  177. dol_print_error('',$result);
  178. }
  179. }
  180. else
  181. {
  182. dol_print_error($db);
  183. }
  184. if (! $mesg)
  185. {
  186. $db->close();
  187. exit;
  188. }
  189. }
  190. /*
  191. * View
  192. */
  193. $form=new Form($db);
  194. llxHeader('',$langs->trans("MembersCards"));
  195. print_fiche_titre($langs->trans("LinkToGeneratedPages"));
  196. print '<br>';
  197. print $langs->trans("LinkToGeneratedPagesDesc").'<br>';
  198. print '<br>';
  199. dol_htmloutput_errors($mesg);
  200. print img_picto('','puce').' '.$langs->trans("DocForAllMembersCards",($conf->global->ADHERENT_CARD_TYPE?$conf->global->ADHERENT_CARD_TYPE:$langs->transnoentitiesnoconv("None"))).' ';
  201. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  202. print '<input type="hidden" name="foruserid" value="all">';
  203. print '<input type="hidden" name="mode" value="card">';
  204. print '<input type="hidden" name="action" value="builddoc">';
  205. print $langs->trans("DescADHERENT_CARD_TYPE").' ';
  206. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  207. $arrayoflabels=array();
  208. foreach(array_keys($_Avery_Labels) as $codecards)
  209. {
  210. $arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
  211. }
  212. print $form->selectarray('model',$arrayoflabels,(GETPOST('model')?GETPOST('model'):$conf->global->ADHERENT_CARD_TYPE),1,0,0);
  213. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  214. print '</form>';
  215. print '<br>';
  216. print img_picto('','puce').' '.$langs->trans("DocForOneMemberCards",($conf->global->ADHERENT_CARD_TYPE?$conf->global->ADHERENT_CARD_TYPE:$langs->transnoentitiesnoconv("None"))).' ';
  217. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  218. print '<input type="hidden" name="mode" value="cardlogin">';
  219. print '<input type="hidden" name="action" value="builddoc">';
  220. print $langs->trans("DescADHERENT_CARD_TYPE").' ';
  221. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  222. $arrayoflabels=array();
  223. foreach(array_keys($_Avery_Labels) as $codecards)
  224. {
  225. $arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
  226. }
  227. print $form->selectarray('model',$arrayoflabels,(GETPOST('model')?GETPOST('model'):$conf->global->ADHERENT_CARD_TYPE),1,0,0);
  228. print '<br>'.$langs->trans("Login").': <input size="10" type="text" name="foruserlogin" value="'.GETPOST('foruserlogin').'">';
  229. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  230. print '</form>';
  231. print '<br>';
  232. print img_picto('','puce').' '.$langs->trans("DocForLabels",$conf->global->ADHERENT_ETIQUETTE_TYPE).' ';
  233. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  234. print '<input type="hidden" name="mode" value="label">';
  235. print '<input type="hidden" name="action" value="builddoc">';
  236. print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
  237. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  238. $arrayoflabels=array();
  239. foreach(array_keys($_Avery_Labels) as $codecards)
  240. {
  241. $arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
  242. }
  243. print $form->selectarray('modellabel',$arrayoflabels,(GETPOST('modellabel')?GETPOST('modellabel'):$conf->global->ADHERENT_ETIQUETTE_TYPE),1,0,0);
  244. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  245. print '</form>';
  246. print '<br>';
  247. llxFooter();
  248. $db->close();