member.lib.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  5. * Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. * or see https://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/lib/member.lib.php
  23. * \brief Functions for module members
  24. */
  25. /**
  26. * Return array head with list of tabs to view object informations
  27. *
  28. * @param Adherent $object Member
  29. * @return array head
  30. */
  31. function member_prepare_head(Adherent $object)
  32. {
  33. global $db, $langs, $conf, $user;
  34. $h = 0;
  35. $head = array();
  36. $head[$h][0] = DOL_URL_ROOT.'/adherents/card.php?rowid='.$object->id;
  37. $head[$h][1] = $langs->trans("Member");
  38. $head[$h][2] = 'general';
  39. $h++;
  40. if ((!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_MEMBER_ACTIVE))
  41. && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || !empty($user->admin))) {
  42. $langs->load("ldap");
  43. $head[$h][0] = DOL_URL_ROOT.'/adherents/ldap.php?id='.$object->id;
  44. $head[$h][1] = $langs->trans("LDAPCard");
  45. $head[$h][2] = 'ldap';
  46. $h++;
  47. }
  48. if (!empty($user->rights->adherent->cotisation->lire)) {
  49. $nbSubscription = is_array($object->subscriptions) ?count($object->subscriptions) : 0;
  50. $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$object->id;
  51. $head[$h][1] = $langs->trans("Subscriptions");
  52. $head[$h][2] = 'subscription';
  53. if ($nbSubscription > 0) {
  54. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbSubscription.'</span>';
  55. }
  56. $h++;
  57. }
  58. if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
  59. if (!empty($user->rights->partnership->read)) {
  60. $nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
  61. $head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?rowid='.$object->id;
  62. $head[$h][1] = $langs->trans("Partnerships");
  63. $nbNote = 0;
  64. $sql = "SELECT COUNT(n.rowid) as nb";
  65. $sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
  66. $sql .= " WHERE fk_member = ".((int) $object->id);
  67. $resql = $db->query($sql);
  68. if ($resql) {
  69. $obj = $db->fetch_object($resql);
  70. $nbNote = $obj->nb;
  71. } else {
  72. dol_print_error($db);
  73. }
  74. if ($nbNote > 0) {
  75. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  76. }
  77. $head[$h][2] = 'partnerships';
  78. if ($nbPartnership > 0) {
  79. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
  80. }
  81. $h++;
  82. }
  83. }
  84. // Show more tabs from modules
  85. // Entries must be declared in modules descriptor with line
  86. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  87. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  88. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'add', 'core');
  89. $nbNote = 0;
  90. if (!empty($object->note_private)) {
  91. $nbNote++;
  92. }
  93. if (!empty($object->note_public)) {
  94. $nbNote++;
  95. }
  96. $head[$h][0] = DOL_URL_ROOT.'/adherents/note.php?id='.$object->id;
  97. $head[$h][1] = $langs->trans("Note");
  98. $head[$h][2] = 'note';
  99. if ($nbNote > 0) {
  100. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  101. }
  102. $h++;
  103. // Attachments
  104. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  105. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  106. $upload_dir = $conf->adherent->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'member');
  107. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  108. $nbLinks = Link::count($db, $object->element, $object->id);
  109. $head[$h][0] = DOL_URL_ROOT.'/adherents/document.php?id='.$object->id;
  110. $head[$h][1] = $langs->trans('Documents');
  111. if (($nbFiles + $nbLinks) > 0) {
  112. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  113. }
  114. $head[$h][2] = 'document';
  115. $h++;
  116. // Show agenda tab
  117. if (isModEnabled('agenda')) {
  118. $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id;
  119. $head[$h][1] = $langs->trans("Events");
  120. if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  121. $head[$h][1] .= '/';
  122. $head[$h][1] .= $langs->trans("Agenda");
  123. }
  124. $head[$h][2] = 'agenda';
  125. $h++;
  126. }
  127. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'add', 'external');
  128. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'remove');
  129. return $head;
  130. }
  131. /**
  132. * Return array head with list of tabs to view object informations
  133. *
  134. * @param AdherentType $object Member
  135. * @return array head
  136. */
  137. function member_type_prepare_head(AdherentType $object)
  138. {
  139. global $langs, $conf, $user;
  140. $h = 0;
  141. $head = array();
  142. $head[$h][0] = DOL_URL_ROOT.'/adherents/type.php?rowid='.$object->id;
  143. $head[$h][1] = $langs->trans("MemberType");
  144. $head[$h][2] = 'card';
  145. $h++;
  146. // Multilangs
  147. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  148. $head[$h][0] = DOL_URL_ROOT."/adherents/type_translation.php?rowid=".$object->id;
  149. $head[$h][1] = $langs->trans("Translation");
  150. $head[$h][2] = 'translation';
  151. $h++;
  152. }
  153. if ((!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE))
  154. && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || !empty($user->admin))) {
  155. $langs->load("ldap");
  156. $head[$h][0] = DOL_URL_ROOT.'/adherents/type_ldap.php?rowid='.$object->id;
  157. $head[$h][1] = $langs->trans("LDAPCard");
  158. $head[$h][2] = 'ldap';
  159. $h++;
  160. }
  161. // Show more tabs from modules
  162. // Entries must be declared in modules descriptor with line
  163. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  164. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  165. complete_head_from_modules($conf, $langs, $object, $head, $h, 'membertype');
  166. complete_head_from_modules($conf, $langs, $object, $head, $h, 'membertype', 'remove');
  167. return $head;
  168. }
  169. /**
  170. * Return array head with list of tabs to view object informations
  171. *
  172. * @return array head
  173. */
  174. function member_admin_prepare_head()
  175. {
  176. global $langs, $conf, $user, $db;
  177. $extrafields = new ExtraFields($db);
  178. $extrafields->fetch_name_optionals_label('adherent');
  179. $extrafields->fetch_name_optionals_label('adherent_type');
  180. $h = 0;
  181. $head = array();
  182. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member.php';
  183. $head[$h][1] = $langs->trans("Miscellaneous");
  184. $head[$h][2] = 'general';
  185. $h++;
  186. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member_emails.php';
  187. $head[$h][1] = $langs->trans("EMails");
  188. $head[$h][2] = 'emails';
  189. $h++;
  190. // Show more tabs from modules
  191. // Entries must be declared in modules descriptor with line
  192. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  193. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  194. complete_head_from_modules($conf, $langs, null, $head, $h, 'member_admin');
  195. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member_extrafields.php';
  196. $head[$h][1] = $langs->trans("ExtraFieldsMember");
  197. $nbExtrafields = $extrafields->attributes['adherent']['count'];
  198. if ($nbExtrafields > 0) {
  199. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  200. }
  201. $head[$h][2] = 'attributes';
  202. $h++;
  203. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member_type_extrafields.php';
  204. $head[$h][1] = $langs->trans("ExtraFieldsMemberType");
  205. $nbExtrafields = $extrafields->attributes['adherent_type']['count'];
  206. if ($nbExtrafields > 0) {
  207. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  208. }
  209. $head[$h][2] = 'attributes_type';
  210. $h++;
  211. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/website.php';
  212. $head[$h][1] = $langs->trans("BlankSubscriptionForm");
  213. $head[$h][2] = 'website';
  214. $h++;
  215. complete_head_from_modules($conf, $langs, null, $head, $h, 'member_admin', 'remove');
  216. return $head;
  217. }
  218. /**
  219. * Return array head with list of tabs to view object stats informations
  220. *
  221. * @param Adherent $object Member or null
  222. * @return array head
  223. */
  224. function member_stats_prepare_head($object)
  225. {
  226. global $langs, $conf, $user;
  227. $h = 0;
  228. $head = array();
  229. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/index.php';
  230. $head[$h][1] = $langs->trans("Subscriptions");
  231. $head[$h][2] = 'statssubscription';
  232. $h++;
  233. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbycountry';
  234. $head[$h][1] = $langs->trans("Country");
  235. $head[$h][2] = 'statscountry';
  236. $h++;
  237. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbyregion';
  238. $head[$h][1] = $langs->trans("Region");
  239. $head[$h][2] = 'statsregion';
  240. $h++;
  241. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbystate';
  242. $head[$h][1] = $langs->trans("State");
  243. $head[$h][2] = 'statsstate';
  244. $h++;
  245. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbytown';
  246. $head[$h][1] = $langs->trans('Town');
  247. $head[$h][2] = 'statstown';
  248. $h++;
  249. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/byproperties.php';
  250. $head[$h][1] = $langs->trans('ByProperties');
  251. $head[$h][2] = 'statsbyproperties';
  252. $h++;
  253. // Show more tabs from modules
  254. // Entries must be declared in modules descriptor with line
  255. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  256. // $this->tabs = array('entity:-tabname); to remove a tab
  257. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member_stats');
  258. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member_stats', 'remove');
  259. return $head;
  260. }
  261. /**
  262. * Return array head with list of tabs to view object informations
  263. *
  264. * @param Subscription $object Subscription
  265. * @return array head
  266. */
  267. function subscription_prepare_head(Subscription $object)
  268. {
  269. global $db, $langs, $conf, $user;
  270. $h = 0;
  271. $head = array();
  272. $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/card.php?rowid='.$object->id;
  273. $head[$h][1] = $langs->trans("Subscription");
  274. $head[$h][2] = 'general';
  275. $h++;
  276. $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/info.php?rowid='.$object->id;
  277. $head[$h][1] = $langs->trans("Info");
  278. $head[$h][2] = 'info';
  279. $h++;
  280. // Show more tabs from modules
  281. // Entries must be declared in modules descriptor with line
  282. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  283. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  284. complete_head_from_modules($conf, $langs, $object, $head, $h, 'subscription');
  285. complete_head_from_modules($conf, $langs, $object, $head, $h, 'subscription', 'remove');
  286. return $head;
  287. }