dolibarr  17.0.3
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-2019 Frederic France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
34 {
35  public $boxcode = "birthdays_members";
36  public $boximg = "object_user";
37  public $boxlabel = "BoxTitleMemberNextBirthdays";
38  public $depends = array("adherent");
39 
43  public $db;
44 
45  public $enabled = 1;
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  public function __construct($db, $param = '')
58  {
59  global $user;
60 
61  $this->db = $db;
62 
63  $this->hidden = !($user->hasRight("adherent", "lire") && empty($user->socid));
64  }
65 
72  public function loadBox($max = 20)
73  {
74  global $user, $langs;
75  $langs->load("boxes");
76 
77  $this->max = $max;
78 
79  include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
80  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
81  $memberstatic = new Adherent($this->db);
82 
83  $this->info_box_head = array('text' => $langs->trans("BoxTitleMemberNextBirthdays"));
84 
85  if ($user->rights->adherent->lire) {
86  $tmparray = dol_getdate(dol_now(), true);
87 
88  $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth, date_format(u.birth, '%d') as daya, u.email, u.statut as status, u.datefin";
89  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u";
90  $sql .= " WHERE u.entity IN (".getEntity('adherent').")";
91  $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED;
92  $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
93  $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
94  $sql .= $this->db->plimit($max, 0);
95 
96  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
97  $result = $this->db->query($sql);
98  if ($result) {
99  $num = $this->db->num_rows($result);
100 
101  $line = 0;
102  while ($line < $num) {
103  $objp = $this->db->fetch_object($result);
104  $memberstatic->id = $objp->rowid;
105  $memberstatic->firstname = $objp->firstname;
106  $memberstatic->lastname = $objp->lastname;
107  $memberstatic->email = $objp->email;
108  $memberstatic->status = $objp->status;
109  $memberstatic->statut = $memberstatic->status;
110  $memberstatic->datefin = $this->db->jdate($objp->datefin);
111  //$memberstatic->need_subscription = 1;
112  $dateb = $this->db->jdate($objp->birth);
113  $age = date('Y', dol_now()) - date('Y', $dateb);
114 
115  $typea = '<i class="fas fa-birthday-cake inline-block"></i>';
116 
117  $this->info_box_contents[$line][] = array(
118  'td' => '',
119  'text' => $memberstatic->getNomUrl(1),
120  'asis' => 1,
121  );
122 
123  $this->info_box_contents[$line][] = array(
124  'td' => 'class="center nowraponall"',
125  'text' => dol_print_date($dateb, "day", 'gmt').' - '.$age.' '.$langs->trans('DurationYears')
126  );
127 
128  $this->info_box_contents[$line][] = array(
129  'td' => 'class="center nowraponall"',
130  'text' => $typea,
131  'asis' => 1
132  );
133 
134  /*$this->info_box_contents[$line][] = array(
135  'td' => 'class="right" width="18"',
136  'text' => $memberstatic->LibStatut($objp->status, 3)
137  );*/
138 
139  $line++;
140  }
141 
142  if ($num == 0) {
143  $this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>');
144  }
145 
146  $this->db->free($result);
147  } else {
148  $this->info_box_contents[0][0] = array(
149  'td' => '',
150  'maxlength'=>500,
151  'text' => ($this->db->error().' sql='.$sql)
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 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2820
db
$conf db
API class for accounts.
Definition: inc.php:41
box_birthdays_members\__construct
__construct($db, $param='')
Constructor.
Definition: box_birthdays_members.php:57
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
box_birthdays_members\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_birthdays_members.php:170
box_birthdays_members
Class to manage the box to show user birthdays.
Definition: box_birthdays_members.php:33
box_birthdays_members\loadBox
loadBox($max=20)
Load data for box to show them later.
Definition: box_birthdays_members.php:72
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
dolSqlDateFilter
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:358
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34