dolibarr 21.0.0-alpha
box_members_by_tags.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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
30
31
36{
37 public $boxcode = "box_members_by_tags";
38 public $boximg = "object_user";
39 public $boxlabel = "BoxTitleMembersByTags";
40 public $depends = array("adherent", "categorie");
41
42 public $enabled = 1;
43
50 public function __construct($db, $param = '')
51 {
52 global $conf, $user;
53
54 $this->db = $db;
55
56 // disable module for such cases
57 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
58 if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
59 $this->enabled = 0; // disabled for external users
60 }
61
62 $this->hidden = !(isModEnabled('member') && $user->hasRight('adherent', 'lire'));
63 }
64
71 public function loadBox($max = 5)
72 {
73 global $user, $langs;
74 $langs->load("boxes");
75
76 $this->max = $max;
77
78 include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
79 $staticmember = new Adherent($this->db);
80
81 $now = dol_now();
82 $year = idate('Y');
83 $numberyears = getDolGlobalInt("MAIN_NB_OF_YEAR_IN_MEMBERSHIP_WIDGET_GRAPH", 0);
84
85 $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByTags").($numberyears ? ' ('.($year - $numberyears).' - '.$year.')' : ''));
86
87 if ($user->hasRight('adherent', 'lire')) {
88 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
89 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
90 $stats = new AdherentStats($this->db, $user->socid, $user->id);
91
92 // Show array
93 $sumMembers = $stats->countMembersByTagAndStatus($numberyears);
94 if ($sumMembers) {
95 $line = 0;
96 $this->info_box_contents[$line][] = array(
97 'td' => 'class=""',
98 'text' => '',
99 );
100 // Members Status To Valid
101 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1);
102 $this->info_box_contents[$line][] = array(
103 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
104 'text' => $labelstatus
105 );
106 // Waiting for subscription
107 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, 0, 1);
108 $this->info_box_contents[$line][] = array(
109 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
110 'text' => $labelstatus,
111 );
112 // Up to date
113 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, $now + 86400, 1);
114 $this->info_box_contents[$line][] = array(
115 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
116 'text' => $labelstatus,
117 );
118 // Expired
119 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, $now - 86400, 1);
120 $this->info_box_contents[$line][] = array(
121 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
122 'text' => $labelstatus
123 );
124 // Excluded
125 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1);
126 $this->info_box_contents[$line][] = array(
127 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
128 'text' => $labelstatus
129 );
130 // Resiliated
131 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
132 $this->info_box_contents[$line][] = array(
133 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
134 'text' => $labelstatus
135 );
136 // Total row
137 $this->info_box_contents[$line][] = array(
138 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($langs->trans("Total")).'"',
139 'text' => $langs->trans("Total")
140 );
141 $line++;
142 $AdherentTag = array();
143 foreach ($sumMembers as $key => $data) {
144 if ($key == 'total') {
145 break;
146 }
147 $adhtag = new Categorie($this->db);
148 $adhtag->id = (int) $key;
149 $adhtag->label = $data['label'];
150 $AdherentTag[$key] = $adhtag;
151
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
154 'text' => '<a href="'.DOL_MAIN_URL_ROOT.'/adherents/list.php?search_categ='.$adhtag->id.'&sortfield=d.datefin,t.subscription&sortorder=desc,desc&backtopage='.urlencode($_SERVER['PHP_SELF']).'">'.dol_trunc(($adhtag->ref ? $adhtag->ref : $adhtag->label), dol_size(32)).'</a>',
155 'asis' => 1,
156 );
157 $this->info_box_contents[$line][] = array(
158 'td' => 'class="right"',
159 'text' => (isset($data['members_draft']) && $data['members_draft'] > 0 ? $data['members_draft'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
160 'asis' => 1,
161 );
162 $this->info_box_contents[$line][] = array(
163 'td' => 'class="right"',
164 'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3),
165 'asis' => 1,
166 );
167 $this->info_box_contents[$line][] = array(
168 'td' => 'class="right"',
169 'text' => (isset($data['members_uptodate']) && $data['members_uptodate'] > 0 ? $data['members_uptodate'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, $now + 86400, 3),
170 'asis' => 1,
171 );
172 $this->info_box_contents[$line][] = array(
173 'td' => 'class="right"',
174 'text' => (isset($data['members_expired']) && $data['members_expired'] > 0 ? $data['members_expired'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now - 86400, 3),
175 'asis' => 1,
176 );
177 $this->info_box_contents[$line][] = array(
178 'td' => 'class="right"',
179 'text' => (isset($data['members_excluded']) && $data['members_excluded'] > 0 ? $data['members_excluded'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3),
180 'asis' => 1,
181 );
182 $this->info_box_contents[$line][] = array(
183 'td' => 'class="right"',
184 'text' => (isset($data['members_resiliated']) && $data['members_resiliated'] > 0 ? $data['members_resiliated'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
185 'asis' => 1,
186 );
187 $this->info_box_contents[$line][] = array(
188 'td' => 'class="right"',
189 'text' => (isset($data['total_adhtag']) && $data['total_adhtag'] > 0 ? $data['total_adhtag'] : ''),
190 'asis' => 1,
191 );
192 $line++;
193 }
194
195 if (count($sumMembers) == 0) {
196 $this->info_box_contents[$line][0] = array(
197 'td' => 'class="center" colspan="6"',
198 'text' => $langs->trans("NoRecordedMembersByType")
199 );
200 } else {
201 $this->info_box_contents[$line][] = array(
202 'tr' => 'class="liste_total"',
203 'td' => 'class="liste_total"',
204 'text' => $langs->trans("Total")
205 );
206 $this->info_box_contents[$line][] = array(
207 'td' => 'class="liste_total right"',
208 'text' => $sumMembers['total']['members_draft'].' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
209 'asis' => 1
210 );
211 $this->info_box_contents[$line][] = array(
212 'td' => 'class="liste_total right"',
213 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3),
214 'asis' => 1
215 );
216 $this->info_box_contents[$line][] = array(
217 'td' => 'class="liste_total right"',
218 'text' => $sumMembers['total']['members_uptodate'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3),
219 'asis' => 1
220 );
221 $this->info_box_contents[$line][] = array(
222 'td' => 'class="liste_total right"',
223 'text' => $sumMembers['total']['members_expired'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
224 'asis' => 1
225 );
226 $this->info_box_contents[$line][] = array(
227 'td' => 'class="liste_total right"',
228 'text' => $sumMembers['total']['members_excluded'].' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3),
229 'asis' => 1
230 );
231 $this->info_box_contents[$line][] = array(
232 'td' => 'class="liste_total right"',
233 'text' => $sumMembers['total']['members_resiliated'].' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
234 'asis' => 1
235 );
236 $this->info_box_contents[$line][] = array(
237 'td' => 'class="liste_total right"',
238 'text' => $sumMembers['total']['all'],
239 'asis' => 1
240 );
241 }
242 } else {
243 $this->info_box_contents[0][0] = array(
244 'td' => '',
245 'maxlength' => 500,
246 'text' => ($this->db->lasterror())
247 );
248 }
249 } else {
250 $this->info_box_contents[0][0] = array(
251 'td' => 'class="nohover left"',
252 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
253 );
254 }
255 }
256
265 public function showBox($head = null, $contents = null, $nooutput = 0)
266 {
267 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
268 }
269}
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 categories.
Class ModeleBoxes.
Class to manage the box to show (last modified) members by tags.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
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, ...)
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...