member.lib.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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) && getDolGlobalString('LDAP_MEMBER_ACTIVE'))
  41. && (!getDolGlobalString('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 ($user->hasRight('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 ($user->hasRight('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. $head[$h][0] = DOL_URL_ROOT.'/adherents/agenda.php?id='.$object->id;
  118. $head[$h][1] = $langs->trans("Events");
  119. if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  120. $nbEvent = 0;
  121. // Enable caching of thirdparty count actioncomm
  122. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  123. $cachekey = 'count_events_member_'.$object->id;
  124. $dataretrieved = dol_getcache($cachekey);
  125. if (!is_null($dataretrieved)) {
  126. $nbEvent = $dataretrieved;
  127. } else {
  128. $sql = "SELECT COUNT(id) as nb";
  129. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
  130. $sql .= " WHERE elementtype = 'member' AND fk_element = ".((int) $object->id);
  131. $resql = $db->query($sql);
  132. if ($resql) {
  133. $obj = $db->fetch_object($resql);
  134. $nbEvent = $obj->nb;
  135. } else {
  136. dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
  137. }
  138. dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
  139. }
  140. $head[$h][1] .= '/';
  141. $head[$h][1] .= $langs->trans("Agenda");
  142. if ($nbEvent > 0) {
  143. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
  144. }
  145. }
  146. $head[$h][2] = 'agenda';
  147. $h++;
  148. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'add', 'external');
  149. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'remove');
  150. return $head;
  151. }
  152. /**
  153. * Return array head with list of tabs to view object informations
  154. *
  155. * @param AdherentType $object Member
  156. * @return array head
  157. */
  158. function member_type_prepare_head(AdherentType $object)
  159. {
  160. global $langs, $conf, $user;
  161. $h = 0;
  162. $head = array();
  163. $head[$h][0] = DOL_URL_ROOT.'/adherents/type.php?rowid='.$object->id;
  164. $head[$h][1] = $langs->trans("MemberType");
  165. $head[$h][2] = 'card';
  166. $h++;
  167. // Multilangs
  168. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  169. $head[$h][0] = DOL_URL_ROOT."/adherents/type_translation.php?rowid=".$object->id;
  170. $head[$h][1] = $langs->trans("Translation");
  171. $head[$h][2] = 'translation';
  172. $h++;
  173. }
  174. if ((!empty($conf->ldap->enabled) && getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE'))
  175. && (!getDolGlobalString('MAIN_DISABLE_LDAP_TAB') || !empty($user->admin))) {
  176. $langs->load("ldap");
  177. $head[$h][0] = DOL_URL_ROOT.'/adherents/type_ldap.php?rowid='.$object->id;
  178. $head[$h][1] = $langs->trans("LDAPCard");
  179. $head[$h][2] = 'ldap';
  180. $h++;
  181. }
  182. // Show more tabs from modules
  183. // Entries must be declared in modules descriptor with line
  184. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  185. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  186. complete_head_from_modules($conf, $langs, $object, $head, $h, 'membertype');
  187. complete_head_from_modules($conf, $langs, $object, $head, $h, 'membertype', 'remove');
  188. return $head;
  189. }
  190. /**
  191. * Return array head with list of tabs to view object informations
  192. *
  193. * @return array head
  194. */
  195. function member_admin_prepare_head()
  196. {
  197. global $langs, $conf, $user, $db;
  198. $extrafields = new ExtraFields($db);
  199. $extrafields->fetch_name_optionals_label('adherent');
  200. $extrafields->fetch_name_optionals_label('adherent_type');
  201. $h = 0;
  202. $head = array();
  203. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member.php';
  204. $head[$h][1] = $langs->trans("Miscellaneous");
  205. $head[$h][2] = 'general';
  206. $h++;
  207. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member_emails.php';
  208. $head[$h][1] = $langs->trans("EMails");
  209. $head[$h][2] = 'emails';
  210. $h++;
  211. // Show more tabs from modules
  212. // Entries must be declared in modules descriptor with line
  213. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  214. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  215. complete_head_from_modules($conf, $langs, null, $head, $h, 'member_admin');
  216. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member_extrafields.php';
  217. $head[$h][1] = $langs->trans("ExtraFieldsMember");
  218. $nbExtrafields = $extrafields->attributes['adherent']['count'];
  219. if ($nbExtrafields > 0) {
  220. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  221. }
  222. $head[$h][2] = 'attributes';
  223. $h++;
  224. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/member_type_extrafields.php';
  225. $head[$h][1] = $langs->trans("ExtraFieldsMemberType");
  226. $nbExtrafields = $extrafields->attributes['adherent_type']['count'];
  227. if ($nbExtrafields > 0) {
  228. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  229. }
  230. $head[$h][2] = 'attributes_type';
  231. $h++;
  232. $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/website.php';
  233. $head[$h][1] = $langs->trans("BlankSubscriptionForm");
  234. $head[$h][2] = 'website';
  235. $h++;
  236. complete_head_from_modules($conf, $langs, null, $head, $h, 'member_admin', 'remove');
  237. return $head;
  238. }
  239. /**
  240. * Return array head with list of tabs to view object stats informations
  241. *
  242. * @param Adherent $object Member or null
  243. * @return array head
  244. */
  245. function member_stats_prepare_head($object)
  246. {
  247. global $langs, $conf, $user;
  248. $h = 0;
  249. $head = array();
  250. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/index.php';
  251. $head[$h][1] = $langs->trans("Subscriptions");
  252. $head[$h][2] = 'statssubscription';
  253. $h++;
  254. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbycountry';
  255. $head[$h][1] = $langs->trans("Country");
  256. $head[$h][2] = 'statscountry';
  257. $h++;
  258. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbyregion';
  259. $head[$h][1] = $langs->trans("Region");
  260. $head[$h][2] = 'statsregion';
  261. $h++;
  262. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbystate';
  263. $head[$h][1] = $langs->trans("State");
  264. $head[$h][2] = 'statsstate';
  265. $h++;
  266. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/geo.php?mode=memberbytown';
  267. $head[$h][1] = $langs->trans('Town');
  268. $head[$h][2] = 'statstown';
  269. $h++;
  270. $head[$h][0] = DOL_URL_ROOT.'/adherents/stats/byproperties.php';
  271. $head[$h][1] = $langs->trans('ByProperties');
  272. $head[$h][2] = 'statsbyproperties';
  273. $h++;
  274. // Show more tabs from modules
  275. // Entries must be declared in modules descriptor with line
  276. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  277. // $this->tabs = array('entity:-tabname); to remove a tab
  278. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member_stats');
  279. complete_head_from_modules($conf, $langs, $object, $head, $h, 'member_stats', 'remove');
  280. return $head;
  281. }
  282. /**
  283. * Return array head with list of tabs to view object informations
  284. *
  285. * @param Subscription $object Subscription
  286. * @return array head
  287. */
  288. function subscription_prepare_head(Subscription $object)
  289. {
  290. global $db, $langs, $conf, $user;
  291. $h = 0;
  292. $head = array();
  293. $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/card.php?rowid='.$object->id;
  294. $head[$h][1] = $langs->trans("Subscription");
  295. $head[$h][2] = 'general';
  296. $h++;
  297. $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/info.php?rowid='.$object->id;
  298. $head[$h][1] = $langs->trans("Info");
  299. $head[$h][2] = 'info';
  300. $h++;
  301. // Show more tabs from modules
  302. // Entries must be declared in modules descriptor with line
  303. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  304. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  305. complete_head_from_modules($conf, $langs, $object, $head, $h, 'subscription');
  306. complete_head_from_modules($conf, $langs, $object, $head, $h, 'subscription', 'remove');
  307. return $head;
  308. }