dolibarr 19.0.3
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 Frederic France <frederic.france@free.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
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
34{
35 public $boxcode = "birthdays";
36 public $boximg = "object_user";
37 public $boxlabel = "BoxTitleUserBirthdaysOfMonth";
38 public $depends = array("user");
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('user', 'user', 'read') && empty($user->socid));
64 }
65
72 public function loadBox($max = 20)
73 {
74 global $conf, $user, $langs;
75
76 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
77 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
78 $userstatic = new User($this->db);
79
80
81 $langs->load("boxes");
82
83 $this->max = $max;
84
85 $this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth"));
86
87 if ($user->hasRight('user', 'user', 'lire')) {
88 $data = array();
89
90 $tmparray = dol_getdate(dol_now(), true);
91
92 $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";
93 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
94 $sql .= " WHERE u.entity IN (".getEntity('user').")";
95 $sql .= " AND u.statut = ".User::STATUS_ENABLED;
96 $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
97 $sql .= " AND u.birth < '".$this->db->idate(dol_get_first_day($tmparray['year']))."'";
98 $sql .= ' UNION ';
99 $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";
100 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
101 $sql .= " WHERE u.entity IN (".getEntity('user').")";
102 $sql .= " AND u.statut = ".User::STATUS_ENABLED;
103 $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0);
104 $sql .= " AND u.dateemployment < '".$this->db->idate(dol_get_first_day($tmparray['year']))."'";
105 $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
106 $sql .= $this->db->plimit($max, 0);
107
108 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
109 $resql = $this->db->query($sql);
110 if ($resql) {
111 $num = $this->db->num_rows($resql);
112
113 $line = 0;
114 while ($line < $num) {
115 $data[$line] = $this->db->fetch_object($resql);
116
117 $line++;
118 }
119
120 $this->db->free($resql);
121 }
122
123 if (!empty($data)) {
124 $j = 0;
125 while ($j < count($data)) {
126 $userstatic->id = $data[$j]->rowid;
127 $userstatic->firstname = $data[$j]->firstname;
128 $userstatic->lastname = $data[$j]->lastname;
129 $userstatic->email = $data[$j]->email;
130 $userstatic->statut = $data[$j]->status;
131
132 $dateb = $this->db->jdate($data[$j]->datea);
133 $age = date('Y', dol_now()) - date('Y', $dateb);
134
135 $picb = '<i class="fas fa-birthday-cake inline-block"></i>';
136 $pice = '<i class="fas fa-briefcase inline-block"></i>';
137 $typea = ($data[$j]->typea == 'birth') ? $picb : $pice;
138
139 $this->info_box_contents[$j][0] = array(
140 'td' => '',
141 'text' => $userstatic->getNomUrl(1),
142 'asis' => 1,
143 );
144
145 $this->info_box_contents[$j][1] = array(
146 'td' => 'class="center nowraponall"',
147 'text' => dol_print_date($dateb, "day", 'tzserver')
148 );
149
150 $this->info_box_contents[$j][2] = array(
151 'td' => 'class="right nowraponall"',
152 'text' => $age.' '.$langs->trans('DurationYears')
153 );
154
155 $this->info_box_contents[$j][3] = array(
156 'td' => 'class="right nowraponall"',
157 'text' => $typea,
158 'asis' => 1
159 );
160
161 $j++;
162 }
163 }
164 if (is_array($data) && count($data) == 0) {
165 $this->info_box_contents[0][0] = array(
166 'td' => 'class="center"',
167 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>',
168 );
169 }
170 } else {
171 $this->info_box_contents[0][0] = array(
172 'td' => 'class="nohover left"',
173 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
174 );
175 }
176 }
177
186 public function showBox($head = null, $contents = null, $nooutput = 0)
187 {
188 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
189 }
190}
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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.