dolibarr 18.0.6
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-2023 Frédéric France <frederic.france@netlogic.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
28include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "box_members_by_tags";
37 public $boximg = "object_user";
38 public $boxlabel = "BoxTitleMembersByTags";
39 public $depends = array("adherent", "categorie");
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 = !(isModEnabled('adherent') && $user->rights->adherent->lire);
72 }
73
80 public function loadBox($max = 5)
81 {
82 global $user, $langs;
83 $langs->load("boxes");
84
85 $this->max = $max;
86
87 include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
88 $staticmember = new Adherent($this->db);
89
90 $now = dol_now();
91 $year = date('Y');
92 $numberyears = getDolGlobalInt("MAIN_NB_OF_YEAR_IN_MEMBERSHIP_WIDGET_GRAPH", 0);
93
94 $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByTags").($numberyears ? ' ('.($year - $numberyears).' - '.$year.')' : ''));
95
96 if ($user->hasRight('adherent', 'lire')) {
97 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
98 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
99 $stats = new AdherentStats($this->db, $user->socid, $user->id);
100
101 // Show array
102 $sumMembers= $stats->countMembersByTagAndStatus($numberyears);
103 if ($sumMembers) {
104 $line = 0;
105 $this->info_box_contents[$line][] = array(
106 'td' => 'class=""',
107 'text' => '',
108 );
109 // Members Status To Valid
110 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1);
111 $this->info_box_contents[$line][] = array(
112 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
113 'text' => $labelstatus
114 );
115 // Waiting for subscription
116 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, 0, 1);
117 $this->info_box_contents[$line][] = array(
118 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
119 'text' => $labelstatus,
120 );
121 // Up to date
122 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, $now + 86400, 1);
123 $this->info_box_contents[$line][] = array(
124 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
125 'text' => $labelstatus,
126 );
127 // Expired
128 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, $now - 86400, 1);
129 $this->info_box_contents[$line][] = array(
130 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
131 'text' => $labelstatus
132 );
133 // Excluded
134 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1);
135 $this->info_box_contents[$line][] = array(
136 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
137 'text' => $labelstatus
138 );
139 // Resiliated
140 $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
141 $this->info_box_contents[$line][] = array(
142 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
143 'text' => $labelstatus
144 );
145 // Total row
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($langs->trans("Total")).'"',
148 'text' => $langs->trans("Total")
149 );
150 $line++;
151 foreach ($sumMembers as $key => $data) {
152 $adhtag = new Categorie($this->db);
153 $adhtag->id = $key;
154
155 if ($key=='total') {
156 break;
157 }
158 $adhtag->label = $data['label'];
159 $AdherentTag[$key] = $adhtag;
160
161 $this->info_box_contents[$line][] = array(
162 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
163 '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>',
164 'asis' => 1,
165 );
166 $this->info_box_contents[$line][] = array(
167 'td' => 'class="right"',
168 'text' => (isset($data['members_draft']) && $data['members_draft'] > 0 ? $data['members_draft'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
169 'asis' => 1,
170 );
171 $this->info_box_contents[$line][] = array(
172 'td' => 'class="right"',
173 'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3),
174 'asis' => 1,
175 );
176 $this->info_box_contents[$line][] = array(
177 'td' => 'class="right"',
178 'text' => (isset($data['members_uptodate']) && $data['members_uptodate'] > 0 ? $data['members_uptodate'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, $now + 86400, 3),
179 'asis' => 1,
180 );
181 $this->info_box_contents[$line][] = array(
182 'td' => 'class="right"',
183 'text' => (isset($data['members_expired']) && $data['members_expired'] > 0 ? $data['members_expired'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now - 86400, 3),
184 'asis' => 1,
185 );
186 $this->info_box_contents[$line][] = array(
187 'td' => 'class="right"',
188 'text' => (isset($data['members_excluded']) && $data['members_excluded'] > 0 ? $data['members_excluded'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3),
189 'asis' => 1,
190 );
191 $this->info_box_contents[$line][] = array(
192 'td' => 'class="right"',
193 'text' => (isset($data['members_resiliated']) && $data['members_resiliated'] > 0 ? $data['members_resiliated'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
194 'asis' => 1,
195 );
196 $this->info_box_contents[$line][] = array(
197 'td' => 'class="right"',
198 'text' => (isset($data['total_adhtag']) && $data['total_adhtag'] > 0 ? $data['total_adhtag'] : ''),
199 'asis' => 1,
200 );
201 $line++;
202 }
203
204 if (count($sumMembers) == 0) {
205 $this->info_box_contents[$line][0] = array(
206 'td' => 'class="center" colspan="6"',
207 'text' => $langs->trans("NoRecordedMembersByType")
208 );
209 } else {
210 $this->info_box_contents[$line][] = array(
211 'tr' => 'class="liste_total"',
212 'td' => 'class="liste_total"',
213 'text' => $langs->trans("Total")
214 );
215 $this->info_box_contents[$line][] = array(
216 'td' => 'class="liste_total right"',
217 'text' => $sumMembers['total']['members_draft'].' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
218 'asis' => 1
219 );
220 $this->info_box_contents[$line][] = array(
221 'td' => 'class="liste_total right"',
222 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3),
223 'asis' => 1
224 );
225 $this->info_box_contents[$line][] = array(
226 'td' => 'class="liste_total right"',
227 'text' => $sumMembers['total']['members_uptodate'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3),
228 'asis' => 1
229 );
230 $this->info_box_contents[$line][] = array(
231 'td' => 'class="liste_total right"',
232 'text' => $sumMembers['total']['members_expired'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
233 'asis' => 1
234 );
235 $this->info_box_contents[$line][] = array(
236 'td' => 'class="liste_total right"',
237 'text' => $sumMembers['total']['members_excluded'].' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3),
238 'asis' => 1
239 );
240 $this->info_box_contents[$line][] = array(
241 'td' => 'class="liste_total right"',
242 'text' => $sumMembers['total']['members_resiliated'].' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
243 'asis' => 1
244 );
245 $this->info_box_contents[$line][] = array(
246 'td' => 'class="liste_total right"',
247 'text' => $sumMembers['total']['all'],
248 'asis' => 1
249 );
250 }
251 } else {
252 $this->info_box_contents[0][0] = array(
253 'td' => '',
254 'maxlength' => 500,
255 'text' => ($this->db->error() . ' sql=' . $sql)
256 );
257 }
258 } else {
259 $this->info_box_contents[0][0] = array(
260 'td' => 'class="nohover opacitymedium left"',
261 'text' => $langs->trans("ReadPermissionNotAllowed")
262 );
263 }
264 }
265
274 public function showBox($head = null, $contents = null, $nooutput = 0)
275 {
276 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
277 }
278}
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 modofied members.
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 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.
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...