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