PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/adherent/cartes/carte.php

https://bitbucket.org/speedealing/speedealing
PHP | 293 lines | 221 code | 34 blank | 38 comment | 38 complexity | 115f06930aa85e52e2183cf5e9ad110e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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.prenom as firstname, d.nom as lastname, d.login, d.societe as company, d.datefin,";
  56. $sql.= " d.adresse as address, d.cp as zip, d.ville as town, d.naiss, 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.pays = 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. '%NAISS%'=>dol_print_date($objp->naiss,'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"]."/", // deprecated
  98. // For backward compatibility
  99. '%PRENOM%'=>$objp->firstname,
  100. '%NOM%'=>$objp->lastname,
  101. '%SOCIETE%'=>$objp->company,
  102. '%ADRESSE%'=>$objp->address,
  103. '%CP%'=>$objp->zip,
  104. '%VILLE%'=>$objp->town,
  105. '%PAYS%'=>$objp->country,
  106. '%ANNEE%'=>$year,
  107. '%SERVEUR%'=>"http://".$_SERVER["SERVER_NAME"]."/" // deprecated
  108. );
  109. complete_substitutions_array($substitutionarray, $langs);
  110. // For business cards
  111. if (empty($mode) || $mode=='card' || $mode=='cardlogin')
  112. {
  113. $textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
  114. $textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
  115. $textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
  116. $textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
  117. if (is_numeric($foruserid) || $foruserlogin)
  118. {
  119. for($j=0;$j<100;$j++)
  120. {
  121. $arrayofmembers[]=array(
  122. 'textleft'=>$textleft,
  123. 'textheader'=>$textheader,
  124. 'textfooter'=>$textfooter,
  125. 'textright'=>$textright,
  126. 'id'=>$objp->rowid,
  127. 'photo'=>$objp->photo
  128. );
  129. }
  130. }
  131. else
  132. {
  133. $arrayofmembers[]=array(
  134. 'textleft'=>$textleft,
  135. 'textheader'=>$textheader,
  136. 'textfooter'=>$textfooter,
  137. 'textright'=>$textright,
  138. 'id'=>$objp->rowid,
  139. 'photo'=>$objp->photo
  140. );
  141. }
  142. }
  143. // For labels
  144. if ($mode == 'label')
  145. {
  146. if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT="%FULLNAME%\n%ADDRESS%\n%ZIP% %TOWN%\n%COUNTRY%";
  147. $textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
  148. $textheader='';
  149. $textfooter='';
  150. $textright='';
  151. $arrayofmembers[]=array('textleft'=>$textleft,
  152. 'textheader'=>$textheader,
  153. 'textfooter'=>$textfooter,
  154. 'textright'=>$textright,
  155. 'id'=>$objp->rowid,
  156. 'photo'=>$objp->photo);
  157. }
  158. $i++;
  159. }
  160. // Build and output PDF
  161. if (empty($mode) || $mode=='card' || $mode=='cardlogin')
  162. {
  163. if (! count($arrayofmembers))
  164. {
  165. $mesg=$langs->trans("ErrorRecordNotFound");
  166. }
  167. if (empty($model) || $model == '-1')
  168. {
  169. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
  170. }
  171. if (! $mesg) $result=members_card_pdf_create($db, $arrayofmembers, $model, $outputlangs);
  172. }
  173. elseif ($mode == 'label')
  174. {
  175. if (! count($arrayofmembers))
  176. {
  177. $mesg=$langs->trans("ErrorRecordNotFound");
  178. }
  179. if (empty($modellabel) || $modellabel == '-1')
  180. {
  181. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
  182. }
  183. if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
  184. }
  185. if ($result <= 0)
  186. {
  187. dol_print_error('',$result);
  188. }
  189. }
  190. else
  191. {
  192. dol_print_error($db);
  193. }
  194. if (! $mesg)
  195. {
  196. $db->close();
  197. exit;
  198. }
  199. }
  200. /*
  201. * View
  202. */
  203. $form=new Form($db);
  204. llxHeader('',$langs->trans("MembersCards"));
  205. print_fiche_titre($langs->trans("LinkToGeneratedPages"));
  206. print '<br>';
  207. print $langs->trans("LinkToGeneratedPagesDesc").'<br>';
  208. print '<br>';
  209. dol_htmloutput_errors($mesg);
  210. print img_picto('','puce').' '.$langs->trans("DocForAllMembersCards",($conf->global->ADHERENT_CARD_TYPE?$conf->global->ADHERENT_CARD_TYPE:$langs->transnoentitiesnoconv("None"))).' ';
  211. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  212. print '<input type="hidden" name="foruserid" value="all">';
  213. print '<input type="hidden" name="mode" value="card">';
  214. print '<input type="hidden" name="action" value="builddoc">';
  215. print $langs->trans("DescADHERENT_CARD_TYPE").' ';
  216. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  217. $arrayoflabels=array();
  218. foreach(array_keys($_Avery_Labels) as $codecards)
  219. {
  220. $arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
  221. }
  222. print $form->selectarray('model',$arrayoflabels,(GETPOST('model')?GETPOST('model'):$conf->global->ADHERENT_CARD_TYPE),1,0,0);
  223. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  224. print '</form>';
  225. print '<br>';
  226. print img_picto('','puce').' '.$langs->trans("DocForOneMemberCards",($conf->global->ADHERENT_CARD_TYPE?$conf->global->ADHERENT_CARD_TYPE:$langs->transnoentitiesnoconv("None"))).' ';
  227. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  228. print '<input type="hidden" name="mode" value="cardlogin">';
  229. print '<input type="hidden" name="action" value="builddoc">';
  230. print $langs->trans("DescADHERENT_CARD_TYPE").' ';
  231. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  232. $arrayoflabels=array();
  233. foreach(array_keys($_Avery_Labels) as $codecards)
  234. {
  235. $arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
  236. }
  237. print $form->selectarray('model',$arrayoflabels,(GETPOST('model')?GETPOST('model'):$conf->global->ADHERENT_CARD_TYPE),1,0,0);
  238. print '<br>'.$langs->trans("Login").': <input size="10" type="text" name="foruserlogin" value="'.GETPOST('foruserlogin').'">';
  239. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  240. print '</form>';
  241. print '<br>';
  242. print img_picto('','puce').' '.$langs->trans("DocForLabels",$conf->global->ADHERENT_ETIQUETTE_TYPE).' ';
  243. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  244. print '<input type="hidden" name="mode" value="label">';
  245. print '<input type="hidden" name="action" value="builddoc">';
  246. print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
  247. // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
  248. $arrayoflabels=array();
  249. foreach(array_keys($_Avery_Labels) as $codecards)
  250. {
  251. $arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
  252. }
  253. print $form->selectarray('modellabel',$arrayoflabels,(GETPOST('modellabel')?GETPOST('modellabel'):$conf->global->ADHERENT_ETIQUETTE_TYPE),1,0,0);
  254. print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
  255. print '</form>';
  256. print '<br>';
  257. llxFooter();
  258. $db->close();
  259. ?>