dolibarr  17.0.4
index.php
Go to the documentation of this file.
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 
31 // Load Dolibarr environment
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array("companies", "members"));
41 
42 
43 $hookmanager = new HookManager($db);
44 
45 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
46 $hookmanager->initHooks(array('membersindex'));
47 
48 
49 // Security check
50 $result = restrictedArea($user, 'adherent');
51 
52 
53 /*
54  * Actions
55  */
56 
57 if (GETPOST('addbox')) {
58  // Add box (when submit is done from a form when ajax disabled)
59  require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
60  $zone = GETPOST('areacode', 'int');
61  $userid = GETPOST('userid', 'int');
62  $boxorder = GETPOST('boxorder', 'aZ09');
63  $boxorder .= GETPOST('boxcombo', 'aZ09');
64  $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
65  if ($result > 0) {
66  setEventMessages($langs->trans("BoxAdded"), null);
67  }
68 }
69 
70 
71 /*
72  * View
73  */
74 
75 $form = new Form($db);
76 
77 // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
78 $resultboxes = FormOther::getBoxesArea($user, "2");
79 
80 llxHeader('', $langs->trans("Members"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
81 
82 $staticmember = new Adherent($db);
83 $statictype = new AdherentType($db);
84 $subscriptionstatic = new Subscription($db);
85 
86 print load_fiche_titre($langs->trans("MembersArea"), $resultboxes['selectboxlist'], 'members');
87 
88 $MembersValidated = array();
89 $MembersToValidate = array();
90 $MembersWaitingSubscription = array();
91 $MembersUpToDate = array();
92 $MembersExpired = array();
93 $MembersExcluded = array();
94 $MembersResiliated = array();
95 
96 $AdherentType = array();
97 
98 // Type of membership
99 $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
100 $sql .= " d.statut, count(d.rowid) as somme";
101 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
102 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
103 $sql .= " ON t.rowid = d.fk_adherent_type";
104 $sql .= " AND d.entity IN (".getEntity('adherent').")";
105 $sql .= " WHERE t.entity IN (".getEntity('member_type').")";
106 $sql .= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut";
107 
108 dol_syslog("index.php::select nb of members per type", LOG_DEBUG);
109 $resql = $db->query($sql);
110 if ($resql) {
111  $num = $db->num_rows($resql);
112  $i = 0;
113  while ($i < $num) {
114  $objp = $db->fetch_object($resql);
115 
116  $adhtype = new AdherentType($db);
117  $adhtype->id = $objp->rowid;
118  $adhtype->subscription = $objp->subscription;
119  $adhtype->label = $objp->label;
120  $AdherentType[$objp->rowid] = $adhtype;
121 
122  if ($objp->statut == -1) {
123  $MembersToValidate[$objp->rowid] = $objp->somme;
124  }
125  if ($objp->statut == 1) {
126  $MembersValidated[$objp->rowid] = $objp->somme;
127  }
128  if ($objp->statut == -2) {
129  $MembersExcluded[$objp->rowid] = $objp->somme;
130  }
131  if ($objp->statut == 0) {
132  $MembersResiliated[$objp->rowid] = $objp->somme;
133  }
134 
135  $i++;
136  }
137  $db->free($resql);
138 }
139 
140 $now = dol_now();
141 
142 // Members waiting subscription
143 $sql = "SELECT count(*) as somme , d.fk_adherent_type";
144 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
145 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
146 $sql .= " AND d.statut = 1"; // validated
147 $sql .= " AND (d.datefin IS NULL AND t.subscription = '1')";
148 $sql .= " AND t.rowid = d.fk_adherent_type";
149 $sql .= " GROUP BY d.fk_adherent_type";
150 
151 dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
152 $resql = $db->query($sql);
153 if ($resql) {
154  $num = $db->num_rows($resql);
155  $i = 0;
156  while ($i < $num) {
157  $objp = $db->fetch_object($resql);
158  $MembersWaitingSubscription[$objp->fk_adherent_type] = $objp->somme;
159  $i++;
160  }
161  $db->free($resql);
162 }
163 
164 // Members up to date list
165 // current rule: uptodate = the end date is in future or no subcription required
166 // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
167 $sql = "SELECT count(*) as somme , d.fk_adherent_type";
168 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
169 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
170 $sql .= " AND d.statut = 1"; // validated
171 $sql .= " AND (d.datefin >= '".$db->idate($now)."' OR t.subscription = '0')"; // end date in future
172 $sql .= " AND t.rowid = d.fk_adherent_type";
173 $sql .= " GROUP BY d.fk_adherent_type";
174 
175 dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
176 $resql = $db->query($sql);
177 if ($resql) {
178  $num = $db->num_rows($resql);
179  $i = 0;
180  while ($i < $num) {
181  $objp = $db->fetch_object($resql);
182  $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme;
183  $i++;
184  }
185  $db->free($resql);
186 }
187 
188 // Members expired list
189 $sql = "SELECT count(*) as somme , d.fk_adherent_type";
190 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
191 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
192 $sql .= " AND d.statut = 1"; // validated
193 $sql .= " AND (d.datefin < '".$db->idate($now)."' AND t.subscription = '1')";
194 $sql .= " AND t.rowid = d.fk_adherent_type";
195 $sql .= " GROUP BY d.fk_adherent_type";
196 
197 dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
198 $resql = $db->query($sql);
199 if ($resql) {
200  $num = $db->num_rows($resql);
201  $i = 0;
202  while ($i < $num) {
203  $objp = $db->fetch_object($resql);
204  $MembersExpired[$objp->fk_adherent_type] = $objp->somme;
205  $i++;
206  }
207  $db->free($resql);
208 }
209 
210 /*
211  * Statistics
212  */
213 
214 $boxgraph = '';
215 if ($conf->use_javascript_ajax) {
216  $boxgraph .='<div class="div-table-responsive-no-min">';
217  $boxgraph .='<table class="noborder nohover centpercent">';
218  $boxgraph .='<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
219  $boxgraph .='<tr><td class="center" colspan="2">';
220 
221  $SumToValidate = 0;
222  $SumWaitingSubscription = 0;
223  $SumUpToDate = 0;
224  $SumExpired = 0;
225  $SumResiliated = 0;
226  $SumExcluded = 0;
227 
228  $total = 0;
229  $dataval = array();
230  $i = 0;
231  foreach ($AdherentType as $key => $adhtype) {
232  $dataval['draft'][] = array($i, isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0);
233  $dataval['waitingsubscription'][] = array($i, isset($MembersWaitingSubscription[$key]) ? $MembersWaitingSubscription[$key] : 0);
234  $dataval['uptodate'][] = array($i, isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0);
235  $dataval['expired'][] = array($i, isset($MembersExpired[$key]) ? $MembersExpired[$key] : 0);
236  $dataval['excluded'][] = array($i, isset($MembersExcluded[$key]) ? $MembersExcluded[$key] : 0);
237  $dataval['resiliated'][] = array($i, isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0);
238 
239  $SumToValidate += isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0;
240  $SumWaitingSubscription += isset($MembersWaitingSubscription[$key]) ? $MembersWaitingSubscription[$key] : 0;
241  $SumUpToDate += isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0;
242  $SumExpired += isset($MembersExpired[$key]) ? $MembersExpired[$key] : 0;
243  $SumExcluded += isset($MembersExcluded[$key]) ? $MembersExcluded [$key] : 0;
244  $SumResiliated += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0;
245  $i++;
246  }
247  $total = $SumToValidate + $SumWaitingSubscription + $SumUpToDate + $SumExpired + $SumExcluded + $SumResiliated;
248  $dataseries = array();
249  $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), round($SumToValidate)); // Draft, not yet validated
250  $dataseries[] = array($langs->transnoentitiesnoconv("WaitingSubscription"), round($SumWaitingSubscription));
251  $dataseries[] = array($langs->transnoentitiesnoconv("UpToDate"), round($SumUpToDate));
252  $dataseries[] = array($langs->transnoentitiesnoconv("OutOfDate"), round($SumExpired));
253  $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusExcluded"), round($SumExcluded));
254  $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), round($SumResiliated));
255 
256  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
257 
258  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
259  $dolgraph = new DolGraph();
260  $dolgraph->SetData($dataseries);
261  $dolgraph->SetDataColor(array('-'.$badgeStatus0, $badgeStatus1, $badgeStatus4, $badgeStatus8, '-'.$badgeStatus8, $badgeStatus6));
262  $dolgraph->setShowLegend(2);
263  $dolgraph->setShowPercent(1);
264  $dolgraph->SetType(array('pie'));
265  $dolgraph->setHeight('200');
266  $dolgraph->draw('idgraphstatus');
267  $boxgraph .=$dolgraph->show($total ? 0 : 1);
268 
269  $boxgraph .= '</td></tr>';
270  $boxgraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
271  $boxgraph .= $SumToValidate + $SumWaitingSubscription + $SumUpToDate + $SumExpired + $SumExcluded + $SumResiliated;
272  $boxgraph .= '</td></tr>';
273  $boxgraph .= '</table>';
274  $boxgraph .= '</div>';
275  $boxgraph .= '<br>';
276 }
277 
278 // boxes
279 print '<div class="clearboth"></div>';
280 print '<div class="fichecenter fichecenterbis">';
281 
282 print '<div class="twocolumns">';
283 
284 print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
285 
286 print $boxgraph;
287 
288 print $resultboxes['boxlista'];
289 
290 print '</div>'."\n";
291 
292 print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
293 
294 print $resultboxes['boxlistb'];
295 
296 print '</div>'."\n";
297 
298 print '</div>';
299 print '</div>';
300 
301 $parameters = array('user' => $user);
302 $reshook = $hookmanager->executeHooks('dashboardMembers', $parameters, $object); // Note that $action and $object may have been modified by hook
303 
304 // End of page
305 llxFooter();
306 $db->close();
Class to manage members of a foundation.
Class to manage members type.
Class to build graphs.
Class to manage generation of HTML components Only common components must be here.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user.
Class to manage hooks.
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
Class to manage subscriptions of foundation members.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.