index.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. $hookmanager = new HookManager($db);
  34. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  35. $hookmanager->initHooks(array('membersindex'));
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("companies", "members"));
  38. // Security check
  39. $result = restrictedArea($user, 'adherent');
  40. /*
  41. * Actions
  42. */
  43. if (GETPOST('addbox')) {
  44. // Add box (when submit is done from a form when ajax disabled)
  45. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  46. $zone = GETPOST('areacode', 'int');
  47. $userid = GETPOST('userid', 'int');
  48. $boxorder = GETPOST('boxorder', 'aZ09');
  49. $boxorder .= GETPOST('boxcombo', 'aZ09');
  50. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  51. if ($result > 0) {
  52. setEventMessages($langs->trans("BoxAdded"), null);
  53. }
  54. }
  55. /*
  56. * View
  57. */
  58. $form = new Form($db);
  59. // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
  60. $resultboxes = FormOther::getBoxesArea($user, "2");
  61. llxHeader('', $langs->trans("Members"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  62. $staticmember = new Adherent($db);
  63. $statictype = new AdherentType($db);
  64. $subscriptionstatic = new Subscription($db);
  65. print load_fiche_titre($langs->trans("MembersArea"), $resultboxes['selectboxlist'], 'members');
  66. $MembersValidated = array();
  67. $MembersToValidate = array();
  68. $MembersUpToDate = array();
  69. $MembersExcluded = array();
  70. $MembersResiliated = array();
  71. $AdherentType = array();
  72. // Type of membership
  73. $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
  74. $sql .= " d.statut, count(d.rowid) as somme";
  75. $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
  76. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
  77. $sql .= " ON t.rowid = d.fk_adherent_type";
  78. $sql .= " AND d.entity IN (".getEntity('adherent').")";
  79. $sql .= " WHERE t.entity IN (".getEntity('member_type').")";
  80. $sql .= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut";
  81. dol_syslog("index.php::select nb of members per type", LOG_DEBUG);
  82. $resql = $db->query($sql);
  83. if ($resql) {
  84. $num = $db->num_rows($resql);
  85. $i = 0;
  86. while ($i < $num) {
  87. $objp = $db->fetch_object($resql);
  88. $adhtype = new AdherentType($db);
  89. $adhtype->id = $objp->rowid;
  90. $adhtype->subscription = $objp->subscription;
  91. $adhtype->label = $objp->label;
  92. $AdherentType[$objp->rowid] = $adhtype;
  93. if ($objp->statut == -1) {
  94. $MembersToValidate[$objp->rowid] = $objp->somme;
  95. }
  96. if ($objp->statut == 1) {
  97. $MembersValidated[$objp->rowid] = $objp->somme;
  98. }
  99. if ($objp->statut == -2) {
  100. $MembersExcluded[$objp->rowid] = $objp->somme;
  101. }
  102. if ($objp->statut == 0) {
  103. $MembersResiliated[$objp->rowid] = $objp->somme;
  104. }
  105. $i++;
  106. }
  107. $db->free($resql);
  108. }
  109. $now = dol_now();
  110. // Members up to date list
  111. // current rule: uptodate = the end date is in future whatever is type
  112. // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
  113. $sql = "SELECT count(*) as somme , d.fk_adherent_type";
  114. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  115. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  116. $sql .= " AND d.statut = 1 AND (d.datefin >= '".$db->idate($now)."' OR t.subscription = 0)";
  117. $sql .= " AND t.rowid = d.fk_adherent_type";
  118. $sql .= " GROUP BY d.fk_adherent_type";
  119. dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
  120. $resql = $db->query($sql);
  121. if ($resql) {
  122. $num = $db->num_rows($resql);
  123. $i = 0;
  124. while ($i < $num) {
  125. $objp = $db->fetch_object($resql);
  126. $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme;
  127. $i++;
  128. }
  129. $db->free($resql);
  130. }
  131. /*
  132. * Statistics
  133. */
  134. $boxgraph = '';
  135. if ($conf->use_javascript_ajax) {
  136. $boxgraph .='<div class="div-table-responsive-no-min">';
  137. $boxgraph .='<table class="noborder nohover centpercent">';
  138. $boxgraph .='<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  139. $boxgraph .='<tr><td class="center" colspan="2">';
  140. $SumToValidate = 0;
  141. $SumValidated = 0;
  142. $SumUpToDate = 0;
  143. $SumResiliated = 0;
  144. $SumExcluded = 0;
  145. $total = 0;
  146. $dataval = array();
  147. $i = 0;
  148. foreach ($AdherentType as $key => $adhtype) {
  149. $dataval['draft'][] = array($i, isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0);
  150. $dataval['uptodate'][] = array($i, isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0);
  151. $dataval['notuptodate'][] = array($i, isset($MembersValidated[$key]) ? $MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) : 0);
  152. $dataval['excluded'][] = array($i, isset($MembersExcluded[$key]) ? $MembersExcluded[$key] : 0);
  153. $dataval['resiliated'][] = array($i, isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0);
  154. $SumToValidate += isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0;
  155. $SumValidated += isset($MembersValidated[$key]) ? $MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) : 0;
  156. $SumUpToDate += isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0;
  157. $SumExcluded += isset($MembersExcluded[$key]) ? $MembersExcluded [$key] : 0;
  158. $SumResiliated += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0;
  159. $i++;
  160. }
  161. $total = $SumToValidate + $SumValidated + $SumUpToDate + $SumExcluded + $SumResiliated;
  162. $dataseries = array();
  163. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), round($SumToValidate)); // Draft, not yet validated
  164. $dataseries[] = array($langs->transnoentitiesnoconv("UpToDate"), round($SumUpToDate));
  165. $dataseries[] = array($langs->transnoentitiesnoconv("OutOfDate"), round($SumValidated));
  166. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusExcluded"), round($SumExcluded));
  167. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), round($SumResiliated));
  168. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  169. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  170. $dolgraph = new DolGraph();
  171. $dolgraph->SetData($dataseries);
  172. $dolgraph->SetDataColor(array('-'.$badgeStatus0, $badgeStatus4, '-'.$badgeStatus1, '-'.$badgeStatus8, $badgeStatus6));
  173. $dolgraph->setShowLegend(2);
  174. $dolgraph->setShowPercent(1);
  175. $dolgraph->SetType(array('pie'));
  176. $dolgraph->setHeight('200');
  177. $dolgraph->draw('idgraphstatus');
  178. $boxgraph .=$dolgraph->show($total ? 0 : 1);
  179. $boxgraph .= '</td></tr>';
  180. $boxgraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
  181. $boxgraph .= $SumToValidate + $SumValidated + $SumUpToDate + $SumExcluded + $SumResiliated;
  182. $boxgraph .= '</td></tr>';
  183. $boxgraph .= '</table>';
  184. $boxgraph .= '</div>';
  185. $boxgraph .= '<br>';
  186. }
  187. // boxes
  188. print '<div class="clearboth"></div>';
  189. print '<div class="fichecenter fichecenterbis">';
  190. print '<div class="twocolumns">';
  191. print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  192. print $boxgraph;
  193. print $resultboxes['boxlista'];
  194. print '</div>'."\n";
  195. print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  196. print $resultboxes['boxlistb'];
  197. print '</div>'."\n";
  198. print '</div>';
  199. print '</div>';
  200. $parameters = array('user' => $user);
  201. $reshook = $hookmanager->executeHooks('dashboardMembers', $parameters, $object); // Note that $action and $object may have been modified by hook
  202. // End of page
  203. llxFooter();
  204. $db->close();