dolibarr 21.0.0-alpha
box_birthdays_members.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2023 Frederic France <frederic.france@netlogic.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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 = "birthdays_members";
37 public $boximg = "object_user";
38 public $boxlabel = "BoxTitleMemberNextBirthdays";
39 public $depends = array("adherent");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param = '')
50 {
51 global $user;
52
53 $this->db = $db;
54
55 $this->hidden = !($user->hasRight("adherent", "lire") && empty($user->socid));
56 }
57
64 public function loadBox($max = 20)
65 {
66 global $conf, $user, $langs;
67
68 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
69 include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
70 $memberstatic = new Adherent($this->db);
71
72 $langs->load("boxes");
73
74 $this->max = $max;
75
76 $this->info_box_head = array('text' => $langs->trans("BoxTitleMemberNextBirthdays"));
77
78 if ($user->hasRight('adherent', 'lire')) {
79 $data = array();
80
81 $tmparray = dol_getdate(dol_now(), true);
82
83 $sql = "SELECT u.rowid, u.firstname, u.lastname, u.societe, u.birth, date_format(u.birth, '%d') as daya, u.email, u.statut as status, u.datefin";
84 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u";
85 $sql .= " WHERE u.entity IN (".getEntity('adherent').")";
86 $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED;
87 $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
88 $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
89 $sql .= $this->db->plimit($max, 0);
90
91 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
92 $resql = $this->db->query($sql);
93 if ($resql) {
94 $num = $this->db->num_rows($resql);
95
96 $line = 0;
97 while ($line < $num) {
98 $data[$line] = $this->db->fetch_object($resql);
99
100 $line++;
101 }
102
103 $this->db->free($resql);
104 }
105
106 if (!empty($data)) {
107 $j = 0;
108 while ($j < count($data)) {
109 $memberstatic->id = $data[$j]->rowid;
110 $memberstatic->firstname = $data[$j]->firstname;
111 $memberstatic->lastname = $data[$j]->lastname;
112 $memberstatic->company = $data[$j]->societe;
113 $memberstatic->email = $data[$j]->email;
114 $memberstatic->status = $data[$j]->status;
115 $memberstatic->statut = $data[$j]->status;
116 $memberstatic->datefin = $this->db->jdate($data[$j]->datefin);
117
118 $dateb = $this->db->jdate($data[$j]->birth);
119 $age = idate('Y', dol_now()) - idate('Y', $dateb);
120
121 $typea = '<i class="fas fa-birthday-cake inline-block"></i>';
122
123 $this->info_box_contents[$j][0] = array(
124 'td' => '',
125 'text' => $memberstatic->getNomUrl(1),
126 'asis' => 1,
127 );
128
129 $this->info_box_contents[$j][1] = array(
130 'td' => 'class="center nowraponall"',
131 'text' => dol_print_date($dateb, "day", 'tzserver').' - '.$age.' '.$langs->trans('DurationYears')
132 );
133
134 $this->info_box_contents[$j][2] = array(
135 'td' => 'class="right nowraponall"',
136 'text' => $typea,
137 'asis' => 1
138 );
139
140 /*$this->info_box_contents[$j][3] = array(
141 'td' => 'class="right" width="18"',
142 'text' => $memberstatic->LibStatut($objp->status, 3)
143 );*/
144
145 $j++;
146 }
147 }
148 if (is_array($data) && count($data) == 0) {
149 $this->info_box_contents[0][0] = array(
150 'td' => 'class="center"',
151 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>',
152 );
153 }
154 } else {
155 $this->info_box_contents[0][0] = array(
156 'td' => 'class="nohover left"',
157 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
158 );
159 }
160 }
161
170 public function showBox($head = null, $contents = null, $nooutput = 0)
171 {
172 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
173 }
174}
Class to manage members of a foundation.
Class ModeleBoxes.
Class to manage the box to show members birthdays.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
loadBox($max=20)
Load data for box to show them later.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:377
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.