dolibarr 21.0.0-alpha
box_birthdays.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-2024 Frédéric France <frederic.france@free.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";
37 public $boximg = "object_user";
38 public $boxlabel = "BoxTitleUserBirthdaysOfMonth";
39 public $depends = array("user");
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('user', 'user', 'read') && 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.'/user/class/user.class.php';
70 $userstatic = new User($this->db);
71
72
73 $langs->load("boxes");
74
75 $this->max = $max;
76
77 $this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth"));
78
79 if ($user->hasRight('user', 'user', 'lire')) {
80 $data = array();
81
82 $tmparray = dol_getdate(dol_now(), true);
83
84 $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, date_format(u.birth, '%d') as daya, 'birth' as typea, u.email, u.statut as status";
85 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
86 $sql .= " WHERE u.entity IN (".getEntity('user').")";
87 $sql .= " AND u.statut = ".User::STATUS_ENABLED;
88 $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
89 $sql .= " AND u.birth < '".$this->db->idate(dol_get_first_day($tmparray['year']))."'";
90 $sql .= ' UNION ';
91 $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, date_format(u.dateemployment, '%d') as daya, 'employment' as typea, u.email, u.statut as status";
92 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
93 $sql .= " WHERE u.entity IN (".getEntity('user').")";
94 $sql .= " AND u.statut = ".User::STATUS_ENABLED;
95 $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0);
96 $sql .= " AND u.dateemployment < '".$this->db->idate(dol_get_first_day($tmparray['year']))."'";
97 $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
98 $sql .= $this->db->plimit($max, 0);
99
100 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
101 $resql = $this->db->query($sql);
102 if ($resql) {
103 $num = $this->db->num_rows($resql);
104
105 $line = 0;
106 while ($line < $num) {
107 $data[$line] = $this->db->fetch_object($resql);
108
109 $line++;
110 }
111
112 $this->db->free($resql);
113 }
114
115 if (!empty($data)) {
116 $j = 0;
117 while ($j < count($data)) {
118 $userstatic->id = $data[$j]->rowid;
119 $userstatic->firstname = $data[$j]->firstname;
120 $userstatic->lastname = $data[$j]->lastname;
121 $userstatic->email = $data[$j]->email;
122 $userstatic->status = $data[$j]->status;
123
124 $dateb = $this->db->jdate($data[$j]->datea);
125 $age = idate('Y', dol_now()) - idate('Y', $dateb);
126
127 $picb = '<i class="fas fa-birthday-cake inline-block"></i>';
128 $pice = '<i class="fas fa-briefcase inline-block"></i>';
129 $typea = ($data[$j]->typea == 'birth') ? $picb : $pice;
130
131 $this->info_box_contents[$j][0] = array(
132 'td' => '',
133 'text' => $userstatic->getNomUrl(1),
134 'asis' => 1,
135 );
136
137 $this->info_box_contents[$j][1] = array(
138 'td' => 'class="center nowraponall"',
139 'text' => dol_print_date($dateb, "day", 'tzserver')
140 );
141
142 $this->info_box_contents[$j][2] = array(
143 'td' => 'class="right nowraponall"',
144 'text' => $age.' '.$langs->trans('DurationYears')
145 );
146
147 $this->info_box_contents[$j][3] = array(
148 'td' => 'class="right nowraponall"',
149 'text' => $typea,
150 'asis' => 1
151 );
152
153 $j++;
154 }
155 }
156 if (is_array($data) && count($data) == 0) {
157 $this->info_box_contents[0][0] = array(
158 'td' => 'class="center"',
159 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>',
160 );
161 }
162 } else {
163 $this->info_box_contents[0][0] = array(
164 'td' => 'class="nohover left"',
165 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
166 );
167 }
168 }
169
178 public function showBox($head = null, $contents = null, $nooutput = 0)
179 {
180 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
181 }
182}
Class ModeleBoxes.
Class to manage Dolibarr users.
Class to manage the box to show user birthdays.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=20)
Load data for box to show them later.
__construct($db, $param='')
Constructor.
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_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:594
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.