dolibarr  20.0.0-alpha
box_members_by_type.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
6  * Copyright (C) 2021-2023 Waël Almoman <info@almoman.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
29 
30 
35 {
36  public $boxcode = "box_members_by_type";
37  public $boximg = "object_user";
38  public $boxlabel = "BoxTitleMembersByType";
39  public $depends = array("adherent");
40 
41  public $enabled = 1;
42 
49  public function __construct($db, $param = '')
50  {
51  global $conf, $user;
52 
53  $this->db = $db;
54 
55  // disable module for such cases
56  $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
57  if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
58  $this->enabled = 0; // disabled for external users
59  }
60 
61  $this->hidden = !(isModEnabled('member') && $user->hasRight('adherent', 'lire'));
62  }
63 
70  public function loadBox($max = 5)
71  {
72  global $user, $langs;
73  $langs->loadLangs(array("boxes", "members"));
74 
75  $this->max = $max;
76 
77  include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
78  require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php';
79  $staticmember = new Adherent($this->db);
80 
81  $now = dol_now();
82  $year = date('Y');
83  $numberyears = getDolGlobalInt("MAIN_NB_OF_YEAR_IN_MEMBERSHIP_WIDGET_GRAPH");
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType").($numberyears ? ' ('.($year - $numberyears).' - '.$year.')' : ''));
86 
87  if ($user->hasRight('adherent', 'lire')) {
88  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
89  $stats = new AdherentStats($this->db, $user->socid, $user->id);
90  // Show array
91  $sumMembers = $stats->countMembersByTypeAndStatus($numberyears);
92  if ($sumMembers) {
93  $line = 0;
94  $this->info_box_contents[$line][] = array(
95  'td' => 'class=""',
96  'text' => '',
97  );
98  // Members Status To Valid
99  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1);
100  $this->info_box_contents[$line][] = array(
101  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
102  'text' => $labelstatus
103  );
104  // Waiting for subscription
105  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, 0, 1);
106  $this->info_box_contents[$line][] = array(
107  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
108  'text' => $labelstatus,
109  );
110  // Up to date
111  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, $now + 86400, 1);
112  $this->info_box_contents[$line][] = array(
113  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
114  'text' => $labelstatus,
115  );
116  // Expired
117  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, $now - 86400, 1);
118  $this->info_box_contents[$line][] = array(
119  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
120  'text' => $labelstatus
121  );
122  // Excluded
123  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1);
124  $this->info_box_contents[$line][] = array(
125  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
126  'text' => $labelstatus
127  );
128  // Resiliated
129  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
130  $this->info_box_contents[$line][] = array(
131  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
132  'text' => $labelstatus
133  );
134  // Total row
135  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($langs->trans("Total")).'"',
138  'text' => $langs->trans("Total")
139  );
140  $line++;
141  $AdherentType = array();
142  foreach ($sumMembers as $key => $data) {
143  if ($key == 'total') {
144  break;
145  }
146  $adhtype = new AdherentType($this->db);
147  $adhtype->id = (int) $key;
148  $adhtype->label = $data['label'];
149  $AdherentType[$key] = $adhtype;
150 
151  $this->info_box_contents[$line][] = array(
152  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
153  'text' => $adhtype->getNomUrl(1, dol_size(32)),
154  'asis' => 1,
155  );
156  $this->info_box_contents[$line][] = array(
157  'td' => 'class="right"',
158  'text' => (isset($data['members_draft']) && $data['members_draft'] > 0 ? $data['members_draft'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
159  'asis' => 1,
160  );
161  $this->info_box_contents[$line][] = array(
162  'td' => 'class="right"',
163  'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3),
164  'asis' => 1,
165  );
166  $this->info_box_contents[$line][] = array(
167  'td' => 'class="right"',
168  'text' => (isset($data['members_uptodate']) && $data['members_uptodate'] > 0 ? $data['members_uptodate'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3),
169  'asis' => 1,
170  );
171  $this->info_box_contents[$line][] = array(
172  'td' => 'class="right"',
173  'text' => (isset($data['members_expired']) && $data['members_expired'] > 0 ? $data['members_expired'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
174  'asis' => 1,
175  );
176  $this->info_box_contents[$line][] = array(
177  'td' => 'class="right"',
178  'text' => (isset($data['members_excluded']) && $data['members_excluded'] > 0 ? $data['members_excluded'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3),
179  'asis' => 1,
180  );
181  $this->info_box_contents[$line][] = array(
182  'td' => 'class="right"',
183  'text' => (isset($data['members_resiliated']) && $data['members_resiliated'] > 0 ? $data['members_resiliated'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
184  'asis' => 1,
185  );
186  $this->info_box_contents[$line][] = array(
187  'td' => 'class="right"',
188  'text' => (isset($data['total_adhtype']) && $data['total_adhtype'] > 0 ? $data['total_adhtype'] : ''),
189  'asis' => 1,
190  );
191  $line++;
192  }
193 
194  if (count($sumMembers) == 0) {
195  $this->info_box_contents[$line][0] = array(
196  'td' => 'colspan="7" class="center"',
197  'text' => $langs->trans("NoRecordedMembersByType")
198  );
199  } else {
200  $this->info_box_contents[$line][] = array(
201  'tr' => 'class="liste_total"',
202  'td' => 'class="liste_total"',
203  'text' => $langs->trans("Total")
204  );
205  $this->info_box_contents[$line][] = array(
206  'td' => 'class="liste_total right"',
207  'text' => $sumMembers['total']['members_draft'].' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
208  'asis' => 1
209  );
210  $this->info_box_contents[$line][] = array(
211  'td' => 'class="liste_total right"',
212  'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3),
213  'asis' => 1
214  );
215  $this->info_box_contents[$line][] = array(
216  'td' => 'class="liste_total right"',
217  'text' => $sumMembers['total']['members_uptodate'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3),
218  'asis' => 1
219  );
220  $this->info_box_contents[$line][] = array(
221  'td' => 'class="liste_total right"',
222  'text' => $sumMembers['total']['members_expired'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
223  'asis' => 1
224  );
225  $this->info_box_contents[$line][] = array(
226  'td' => 'class="liste_total right"',
227  'text' => $sumMembers['total']['members_excluded'].' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3),
228  'asis' => 1
229  );
230  $this->info_box_contents[$line][] = array(
231  'td' => 'class="liste_total right"',
232  'text' => $sumMembers['total']['members_resiliated'].' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
233  'asis' => 1
234  );
235  $this->info_box_contents[$line][] = array(
236  'td' => 'class="liste_total right"',
237  'text' => $sumMembers['total']['all'],
238  'asis' => 1
239  );
240  }
241  } else {
242  $this->info_box_contents[0][0] = array(
243  'td' => '',
244  'maxlength' => 500,
245  'text' => ($this->db->lasterror())
246  );
247  }
248  } else {
249  $this->info_box_contents[0][0] = array(
250  'td' => 'class="nohover left"',
251  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
252  );
253  }
254  }
255 
264  public function showBox($head = null, $contents = null, $nooutput = 0)
265  {
266  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
267  }
268 }
Class to manage members of a foundation.
const STATUS_EXCLUDED
Excluded.
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated.
const STATUS_VALIDATED
Validated status.
Class to manage statistics of members.
Class to manage members type.
Class ModeleBoxes.
Class to manage the box to show last modofied members.
loadBox($max=5)
Load data into info_box_contents array to show array later.
__construct($db, $param='')
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone, ...)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...