dolibarr  16.0.5
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-2020 Frederic France <frederic.france@netlogic.fr>
6  * Copyright (C) 2021 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 
44  public $db;
45 
46  public $param;
47  public $enabled = 1;
48 
49  public $info_box_head = array();
50  public $info_box_contents = array();
51 
52 
59  public function __construct($db, $param = '')
60  {
61  global $conf, $user;
62 
63  $this->db = $db;
64 
65  // disable module for such cases
66  $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
67  if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
68  $this->enabled = 0; // disabled for external users
69  }
70 
71  $this->hidden = !(!empty($conf->adherent->enabled) && $user->rights->adherent->lire);
72  }
73 
80  public function loadBox($max = 5)
81  {
82  global $user, $langs, $conf;
83  $langs->load("boxes");
84 
85  $this->max = $max;
86 
87  include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
88  require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php';
89  $staticmember = new Adherent($this->db);
90 
91  $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType", $max));
92 
93  if ($user->rights->adherent->lire) {
94  $MembersToValidate = array();
95  $MembersValidated = array();
96  $MembersUpToDate = array();
97  $MembersExcluded = array();
98  $MembersResiliated = array();
99 
100  $SumToValidate = 0;
101  $SumValidated = 0;
102  $SumUpToDate = 0;
103  $SumResiliated = 0;
104  $SumExcluded = 0;
105 
106  $AdherentType = array();
107 
108  // Type of membership
109  $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
110  $sql .= " d.statut, count(d.rowid) as somme";
111  $sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type as t";
112  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "adherent as d";
113  $sql .= " ON t.rowid = d.fk_adherent_type";
114  $sql .= " AND d.entity IN (" . getEntity('adherent') . ")";
115  $sql .= " WHERE t.entity IN (" . getEntity('member_type') . ")";
116  $sql .= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut";
117 
118  dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG);
119  $result = $this->db->query($sql);
120  if ($result) {
121  $num = $this->db->num_rows($result);
122  $i = 0;
123  while ($i < $num) {
124  $objp = $this->db->fetch_object($result);
125 
126  $adhtype = new AdherentType($this->db);
127  $adhtype->id = $objp->rowid;
128  $adhtype->subscription = $objp->subscription;
129  $adhtype->label = $objp->label;
130  $AdherentType[$objp->rowid] = $adhtype;
131 
132  if ($objp->statut == Adherent::STATUS_DRAFT) {
133  $MembersToValidate[$objp->rowid] = $objp->somme;
134  }
135  if ($objp->statut == Adherent::STATUS_VALIDATED) {
136  $MembersValidated[$objp->rowid] = $objp->somme;
137  }
138  if ($objp->statut == Adherent::STATUS_EXCLUDED) {
139  $MembersExcluded[$objp->rowid] = $objp->somme;
140  }
141  if ($objp->statut == Adherent::STATUS_RESILIATED) {
142  $MembersResiliated[$objp->rowid] = $objp->somme;
143  }
144 
145  $i++;
146  }
147  $this->db->free($result);
148  $now = dol_now();
149 
150  // Members up to date list
151  // current rule: uptodate = the end date is in future whatever is type
152  // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
153  $sql = "SELECT count(*) as somme , d.fk_adherent_type";
154  $sql .= " FROM " . MAIN_DB_PREFIX . "adherent as d, " . MAIN_DB_PREFIX . "adherent_type as t";
155  $sql .= " WHERE d.entity IN (" . getEntity('adherent') . ")";
156  $sql .= " AND d.statut = 1 AND (d.datefin >= '" . $this->db->idate($now) . "' OR t.subscription = 0)";
157  $sql .= " AND t.rowid = d.fk_adherent_type";
158  $sql .= " GROUP BY d.fk_adherent_type";
159 
160  dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
161  $result = $this->db->query($sql);
162  if ($result) {
163  $num2 = $this->db->num_rows($result);
164  $i = 0;
165  while ($i < $num2) {
166  $objp = $this->db->fetch_object($result);
167  $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme;
168  $i++;
169  }
170  $this->db->free($result);
171  }
172 
173  $line = 0;
174  $this->info_box_contents[$line][] = array(
175  'td' => 'class=""',
176  'text' => '',
177  );
178  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1);
179  $this->info_box_contents[$line][] = array(
180  'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"',
181  'text' => $labelstatus
182  );
183  $labelstatus = $langs->trans("UpToDate");
184  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() + 86400, 1);
185  $this->info_box_contents[$line][] = array(
186  'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"',
187  'text' => $labelstatus,
188  );
189  $labelstatus = $langs->trans("OutOfDate");
190  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() - 86400, 1);
191  $this->info_box_contents[$line][] = array(
192  'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"',
193  'text' => $labelstatus
194  );
195  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1);
196  $this->info_box_contents[$line][] = array(
197  'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"',
198  'text' => $labelstatus
199  );
200  $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
201  $this->info_box_contents[$line][] = array(
202  'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"',
203  'text' => $labelstatus
204  );
205  $line++;
206  foreach ($AdherentType as $key => $adhtype) {
207  $SumToValidate += isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0;
208  $SumValidated += isset($MembersValidated[$key]) ? $MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) : 0;
209  $SumUpToDate += isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0;
210  $SumExcluded += isset($MembersExcluded[$key]) ? $MembersExcluded [$key] : 0;
211  $SumResiliated += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0;
212 
213  $this->info_box_contents[$line][] = array(
214  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
215  'text' => $adhtype->getNomUrl(1, dol_size(32)),
216  'asis' => 1,
217  );
218  $this->info_box_contents[$line][] = array(
219  'td' => 'class="right"',
220  'text' => (isset($MembersToValidate[$key]) && $MembersToValidate[$key] > 0 ? $MembersToValidate[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
221  'asis' => 1,
222  );
223  $this->info_box_contents[$line][] = array(
224  'td' => 'class="right"',
225  'text' => (isset($MembersUpToDate[$key]) && $MembersUpToDate[$key] > 0 ? $MembersUpToDate[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3),
226  'asis' => 1,
227  );
228  $this->info_box_contents[$line][] = array(
229  'td' => 'class="right"',
230  'text' => (isset($MembersValidated[$key]) && ($MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) > 0) ? $MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
231  'asis' => 1,
232  );
233  $this->info_box_contents[$line][] = array(
234  'td' => 'class="right"',
235  'text' => (isset($MembersExcluded[$key]) && $MembersExcluded[$key] > 0 ? $MembersExcluded[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3),
236  'asis' => 1,
237  );
238  $this->info_box_contents[$line][] = array(
239  'td' => 'class="right"',
240  'text' => (isset($MembersResiliated[$key]) && $MembersResiliated[$key] > 0 ? $MembersResiliated[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
241  'asis' => 1,
242  );
243 
244  $line++;
245  }
246 
247  if ($num == 0) {
248  $this->info_box_contents[$line][0] = array(
249  'td' => 'class="center"',
250  'text' => $langs->trans("NoRecordedMembersByType")
251  );
252  } else {
253  $this->info_box_contents[$line][] = array(
254  'tr' => 'class="liste_total"',
255  'td' => 'class="liste_total"',
256  'text' => $langs->trans("Total")
257  );
258  $this->info_box_contents[$line][] = array(
259  'td' => 'class="liste_total right"',
260  'text' => $SumToValidate.' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
261  'asis' => 1
262  );
263  $this->info_box_contents[$line][] = array(
264  'td' => 'class="liste_total right"',
265  'text' => $SumUpToDate.' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3),
266  'asis' => 1
267  );
268  $this->info_box_contents[$line][] = array(
269  'td' => 'class="liste_total right"',
270  'text' => $SumValidated.' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
271  'asis' => 1
272  );
273  $this->info_box_contents[$line][] = array(
274  'td' => 'class="liste_total right"',
275  'text' => $SumExcluded.' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3),
276  'asis' => 1
277  );
278  $this->info_box_contents[$line][] = array(
279  'td' => 'class="liste_total right"',
280  'text' => $SumResiliated.' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
281  'asis' => 1
282  );
283  }
284  } else {
285  $this->info_box_contents[0][0] = array(
286  'td' => '',
287  'maxlength' => 500,
288  'text' => ($this->db->error() . ' sql=' . $sql)
289  );
290  }
291  } else {
292  $this->info_box_contents[0][0] = array(
293  'td' => 'class="nohover opacitymedium left"',
294  'text' => $langs->trans("ReadPermissionNotAllowed")
295  );
296  }
297  }
298 
307  public function showBox($head = null, $contents = null, $nooutput = 0)
308  {
309  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
310  }
311 }
Adherent\STATUS_RESILIATED
const STATUS_RESILIATED
Resiliated.
Definition: adherent.class.php:357
db
$conf db
API class for accounts.
Definition: inc.php:41
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
box_members_by_type\__construct
__construct($db, $param='')
Constructor.
Definition: box_members_by_type.php:59
dol_size
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone, ...)
Definition: functions.lib.php:1201
box_members_by_type
Class to manage the box to show last modofied members.
Definition: box_members_by_type.php:34
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
Adherent\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: adherent.class.php:353
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
Adherent\STATUS_EXCLUDED
const STATUS_EXCLUDED
Excluded.
Definition: adherent.class.php:361
box_members_by_type\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_members_by_type.php:80
Adherent\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: adherent.class.php:349
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
box_members_by_type\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_members_by_type.php:307
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34