index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  7. * Copyright (C) 2021 Frédéric France <frederic.france@netlgic.fr>
  8. * Copyright (C) 2021 Waël Almoman <info@almoman.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/adherents/index.php
  25. * \ingroup member
  26. * \brief Home page of membership module
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("companies", "members"));
  36. $hookmanager = new HookManager($db);
  37. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  38. $hookmanager->initHooks(array('membersindex'));
  39. // Security check
  40. $result = restrictedArea($user, 'adherent');
  41. /*
  42. * Actions
  43. */
  44. if (GETPOST('addbox')) {
  45. // Add box (when submit is done from a form when ajax disabled)
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  47. $zone = GETPOST('areacode', 'int');
  48. $userid = GETPOST('userid', 'int');
  49. $boxorder = GETPOST('boxorder', 'aZ09');
  50. $boxorder .= GETPOST('boxcombo', 'aZ09');
  51. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  52. if ($result > 0) {
  53. setEventMessages($langs->trans("BoxAdded"), null);
  54. }
  55. }
  56. /*
  57. * View
  58. */
  59. $form = new Form($db);
  60. // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
  61. $resultboxes = FormOther::getBoxesArea($user, "2");
  62. llxHeader('', $langs->trans("Members"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder');
  63. $staticmember = new Adherent($db);
  64. $statictype = new AdherentType($db);
  65. $subscriptionstatic = new Subscription($db);
  66. print load_fiche_titre($langs->trans("MembersArea"), $resultboxes['selectboxlist'], 'members');
  67. $MembersValidated = array();
  68. $MembersToValidate = array();
  69. $MembersWaitingSubscription = array();
  70. $MembersUpToDate = array();
  71. $MembersExpired = array();
  72. $MembersExcluded = array();
  73. $MembersResiliated = array();
  74. $AdherentType = array();
  75. // Type of membership
  76. $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
  77. $sql .= " d.statut, count(d.rowid) as somme";
  78. $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
  79. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
  80. $sql .= " ON t.rowid = d.fk_adherent_type";
  81. $sql .= " AND d.entity IN (".getEntity('adherent').")";
  82. $sql .= " WHERE t.entity IN (".getEntity('member_type').")";
  83. $sql .= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut";
  84. dol_syslog("index.php::select nb of members per type", LOG_DEBUG);
  85. $resql = $db->query($sql);
  86. if ($resql) {
  87. $num = $db->num_rows($resql);
  88. $i = 0;
  89. while ($i < $num) {
  90. $objp = $db->fetch_object($resql);
  91. $adhtype = new AdherentType($db);
  92. $adhtype->id = $objp->rowid;
  93. $adhtype->subscription = $objp->subscription;
  94. $adhtype->label = $objp->label;
  95. $AdherentType[$objp->rowid] = $adhtype;
  96. if ($objp->statut == -1) {
  97. $MembersToValidate[$objp->rowid] = $objp->somme;
  98. }
  99. if ($objp->statut == 1) {
  100. $MembersValidated[$objp->rowid] = $objp->somme;
  101. }
  102. if ($objp->statut == -2) {
  103. $MembersExcluded[$objp->rowid] = $objp->somme;
  104. }
  105. if ($objp->statut == 0) {
  106. $MembersResiliated[$objp->rowid] = $objp->somme;
  107. }
  108. $i++;
  109. }
  110. $db->free($resql);
  111. }
  112. $now = dol_now();
  113. // Members waiting subscription
  114. $sql = "SELECT count(*) as somme , d.fk_adherent_type";
  115. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  116. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  117. $sql .= " AND d.statut = 1"; // validated
  118. $sql .= " AND (d.datefin IS NULL AND t.subscription = '1')";
  119. $sql .= " AND t.rowid = d.fk_adherent_type";
  120. $sql .= " GROUP BY d.fk_adherent_type";
  121. dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
  122. $resql = $db->query($sql);
  123. if ($resql) {
  124. $num = $db->num_rows($resql);
  125. $i = 0;
  126. while ($i < $num) {
  127. $objp = $db->fetch_object($resql);
  128. $MembersWaitingSubscription[$objp->fk_adherent_type] = $objp->somme;
  129. $i++;
  130. }
  131. $db->free($resql);
  132. }
  133. // Members up to date list
  134. // current rule: uptodate = the end date is in future or no subcription required
  135. // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
  136. $sql = "SELECT count(*) as somme , d.fk_adherent_type";
  137. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  138. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  139. $sql .= " AND d.statut = 1"; // validated
  140. $sql .= " AND (d.datefin >= '".$db->idate($now)."' OR t.subscription = '0')"; // end date in future
  141. $sql .= " AND t.rowid = d.fk_adherent_type";
  142. $sql .= " GROUP BY d.fk_adherent_type";
  143. dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
  144. $resql = $db->query($sql);
  145. if ($resql) {
  146. $num = $db->num_rows($resql);
  147. $i = 0;
  148. while ($i < $num) {
  149. $objp = $db->fetch_object($resql);
  150. $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme;
  151. $i++;
  152. }
  153. $db->free($resql);
  154. }
  155. // Members expired list
  156. $sql = "SELECT count(*) as somme , d.fk_adherent_type";
  157. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  158. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  159. $sql .= " AND d.statut = 1"; // validated
  160. $sql .= " AND (d.datefin < '".$db->idate($now)."' AND t.subscription = '1')";
  161. $sql .= " AND t.rowid = d.fk_adherent_type";
  162. $sql .= " GROUP BY d.fk_adherent_type";
  163. dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
  164. $resql = $db->query($sql);
  165. if ($resql) {
  166. $num = $db->num_rows($resql);
  167. $i = 0;
  168. while ($i < $num) {
  169. $objp = $db->fetch_object($resql);
  170. $MembersExpired[$objp->fk_adherent_type] = $objp->somme;
  171. $i++;
  172. }
  173. $db->free($resql);
  174. }
  175. /*
  176. * Statistics
  177. */
  178. $boxgraph = '';
  179. if ($conf->use_javascript_ajax) {
  180. $boxgraph .='<div class="div-table-responsive-no-min">';
  181. $boxgraph .='<table class="noborder nohover centpercent">';
  182. $boxgraph .='<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  183. $boxgraph .='<tr><td class="center" colspan="2">';
  184. $SumToValidate = 0;
  185. $SumWaitingSubscription = 0;
  186. $SumUpToDate = 0;
  187. $SumExpired = 0;
  188. $SumResiliated = 0;
  189. $SumExcluded = 0;
  190. $total = 0;
  191. $dataval = array();
  192. $i = 0;
  193. foreach ($AdherentType as $key => $adhtype) {
  194. $dataval['draft'][] = array($i, isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0);
  195. $dataval['waitingsubscription'][] = array($i, isset($MembersWaitingSubscription[$key]) ? $MembersWaitingSubscription[$key] : 0);
  196. $dataval['uptodate'][] = array($i, isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0);
  197. $dataval['expired'][] = array($i, isset($MembersExpired[$key]) ? $MembersExpired[$key] : 0);
  198. $dataval['excluded'][] = array($i, isset($MembersExcluded[$key]) ? $MembersExcluded[$key] : 0);
  199. $dataval['resiliated'][] = array($i, isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0);
  200. $SumToValidate += isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0;
  201. $SumWaitingSubscription += isset($MembersWaitingSubscription[$key]) ? $MembersWaitingSubscription[$key] : 0;
  202. $SumUpToDate += isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0;
  203. $SumExpired += isset($MembersExpired[$key]) ? $MembersExpired[$key] : 0;
  204. $SumExcluded += isset($MembersExcluded[$key]) ? $MembersExcluded [$key] : 0;
  205. $SumResiliated += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0;
  206. $i++;
  207. }
  208. $total = $SumToValidate + $SumWaitingSubscription + $SumUpToDate + $SumExpired + $SumExcluded + $SumResiliated;
  209. $dataseries = array();
  210. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), round($SumToValidate)); // Draft, not yet validated
  211. $dataseries[] = array($langs->transnoentitiesnoconv("WaitingSubscription"), round($SumWaitingSubscription));
  212. $dataseries[] = array($langs->transnoentitiesnoconv("UpToDate"), round($SumUpToDate));
  213. $dataseries[] = array($langs->transnoentitiesnoconv("OutOfDate"), round($SumExpired));
  214. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusExcluded"), round($SumExcluded));
  215. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), round($SumResiliated));
  216. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  217. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  218. $dolgraph = new DolGraph();
  219. $dolgraph->SetData($dataseries);
  220. $dolgraph->SetDataColor(array('-'.$badgeStatus0, $badgeStatus1, $badgeStatus4, $badgeStatus8, '-'.$badgeStatus8, $badgeStatus6));
  221. $dolgraph->setShowLegend(2);
  222. $dolgraph->setShowPercent(1);
  223. $dolgraph->SetType(array('pie'));
  224. $dolgraph->setHeight('200');
  225. $dolgraph->draw('idgraphstatus');
  226. $boxgraph .=$dolgraph->show($total ? 0 : 1);
  227. $boxgraph .= '</td></tr>';
  228. $boxgraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
  229. $boxgraph .= $SumToValidate + $SumWaitingSubscription + $SumUpToDate + $SumExpired + $SumExcluded + $SumResiliated;
  230. $boxgraph .= '</td></tr>';
  231. $boxgraph .= '</table>';
  232. $boxgraph .= '</div>';
  233. $boxgraph .= '<br>';
  234. }
  235. // boxes
  236. print '<div class="clearboth"></div>';
  237. print '<div class="fichecenter fichecenterbis">';
  238. print '<div class="twocolumns">';
  239. print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  240. print $boxgraph;
  241. print $resultboxes['boxlista'];
  242. print '</div>'."\n";
  243. print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  244. print $resultboxes['boxlistb'];
  245. print '</div>'."\n";
  246. print '</div>';
  247. print '</div>';
  248. $parameters = array('user' => $user);
  249. $reshook = $hookmanager->executeHooks('dashboardMembers', $parameters, $object); // Note that $action and $object may have been modified by hook
  250. // End of page
  251. llxFooter();
  252. $db->close();