28 include_once DOL_DOCUMENT_ROOT .
'/core/boxes/modules_boxes.php';
36 public $boxcode =
"box_members_by_type";
37 public $boximg =
"object_user";
38 public $boxlabel =
"BoxTitleMembersByType";
39 public $depends = array(
"adherent");
49 public $info_box_head = array();
50 public $info_box_contents = array();
66 $listofmodulesforexternal = explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
67 if (!in_array(
'adherent', $listofmodulesforexternal) && !empty($user->socid)) {
71 $this->hidden = !(!empty($conf->adherent->enabled) && $user->rights->adherent->lire);
82 global $user, $langs, $conf;
83 $langs->load(
"boxes");
87 include_once DOL_DOCUMENT_ROOT .
'/adherents/class/adherent.class.php';
88 require_once DOL_DOCUMENT_ROOT .
'/adherents/class/adherent_type.class.php';
91 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleMembersByType", $max));
93 if ($user->rights->adherent->lire) {
94 $MembersToValidate = array();
95 $MembersValidated = array();
96 $MembersUpToDate = array();
97 $MembersExcluded = array();
98 $MembersResiliated = array();
106 $AdherentType = array();
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";
118 dol_syslog(
"box_members_by_type::select nb of members per type", LOG_DEBUG);
119 $result = $this->
db->query($sql);
121 $num = $this->
db->num_rows($result);
124 $objp = $this->
db->fetch_object($result);
127 $adhtype->id = $objp->rowid;
128 $adhtype->subscription = $objp->subscription;
129 $adhtype->label = $objp->label;
130 $AdherentType[$objp->rowid] = $adhtype;
133 $MembersToValidate[$objp->rowid] = $objp->somme;
136 $MembersValidated[$objp->rowid] = $objp->somme;
139 $MembersExcluded[$objp->rowid] = $objp->somme;
142 $MembersResiliated[$objp->rowid] = $objp->somme;
147 $this->
db->free($result);
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";
160 dol_syslog(
"index.php::select nb of uptodate members by type", LOG_DEBUG);
161 $result = $this->
db->query($sql);
163 $num2 = $this->
db->num_rows($result);
166 $objp = $this->
db->fetch_object($result);
167 $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme;
170 $this->
db->free($result);
174 $this->info_box_contents[$line][] = array(
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
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,
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
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
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
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;
213 $this->info_box_contents[$line][] = array(
214 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
215 'text' => $adhtype->getNomUrl(1,
dol_size(32)),
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),
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),
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),
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),
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),
248 $this->info_box_contents[$line][0] = array(
249 'td' =>
'class="center"',
250 'text' => $langs->trans(
"NoRecordedMembersByType")
253 $this->info_box_contents[$line][] = array(
254 'tr' =>
'class="liste_total"',
255 'td' =>
'class="liste_total"',
256 'text' => $langs->trans(
"Total")
258 $this->info_box_contents[$line][] = array(
259 'td' =>
'class="liste_total right"',
263 $this->info_box_contents[$line][] = array(
264 'td' =>
'class="liste_total right"',
268 $this->info_box_contents[$line][] = array(
269 'td' =>
'class="liste_total right"',
273 $this->info_box_contents[$line][] = array(
274 'td' =>
'class="liste_total right"',
278 $this->info_box_contents[$line][] = array(
279 'td' =>
'class="liste_total right"',
285 $this->info_box_contents[0][0] = array(
288 'text' => ($this->
db->error() .
' sql=' . $sql)
292 $this->info_box_contents[0][0] = array(
293 'td' =>
'class="nohover opacitymedium left"',
294 'text' => $langs->trans(
"ReadPermissionNotAllowed")
307 public function showBox($head =
null, $contents =
null, $nooutput = 0)
309 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);