dolibarr  x.y.z
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 
27 include_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 $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.'/user/class/user.class.php';
81  $userstatic = new User($this->db);
82 
83  $this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth"));
84 
85  if ($user->rights->user->user->lire) {
86  $tmparray = dol_getdate(dol_now(), true);
87 
88  $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, 'birth' as typea, u.email, u.statut as status";
89  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
90  $sql .= " WHERE u.entity IN (".getEntity('user').")";
91  $sql .= " AND u.statut = 1";
92  $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
93  $sql .= ' UNION ';
94  $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, 'employment' as typea, u.email, u.statut as status";
95  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
96  $sql .= " WHERE u.entity IN (".getEntity('user').")";
97  $sql .= " AND u.statut = 1";
98  $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0);
99 
100  $sql .= " ORDER BY DAY(datea) ASC";
101 
102  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
103  $result = $this->db->query($sql);
104  if ($result) {
105  $num = $this->db->num_rows($result);
106 
107  $line = 0;
108  while ($line < $num) {
109  $objp = $this->db->fetch_object($result);
110 
111  $userstatic->id = $objp->rowid;
112  $userstatic->firstname = $objp->firstname;
113  $userstatic->lastname = $objp->lastname;
114  $userstatic->email = $objp->email;
115  $userstatic->statut = $objp->status;
116 
117  $dateb = $this->db->jdate($objp->datea);
118  $age = date('Y', dol_now()) - date('Y', $dateb);
119 
120  $picb = '<i class="fas fa-birthday-cake inline-block"></i>';
121  $pice = '<i class="fas fa-briefcase inline-block"></i>';
122  $typea = ($objp->typea == 'birth') ? $picb : $pice;
123 
124  $this->info_box_contents[$line][] = array(
125  'td' => '',
126  'text' => $userstatic->getNomUrl(1),
127  'asis' => 1,
128  );
129 
130  $this->info_box_contents[$line][] = array(
131  'td' => 'class="center nowraponall"',
132  'text' => dol_print_date($dateb, "day", 'tzserver')
133  );
134 
135  $this->info_box_contents[$line][] = array(
136  'td' => 'class="right nowraponall"',
137  'text' => $age.' '.$langs->trans('DurationYears')
138  );
139 
140  $this->info_box_contents[$line][] = array(
141  'td' => 'class="center nowraponall"',
142  'text' => $typea,
143  'asis' => 1
144  );
145 
146  /*$this->info_box_contents[$line][] = array(
147  'td' => 'class="right" width="18"',
148  'text' => $userstatic->LibStatut($objp->status, 3)
149  );*/
150 
151  $line++;
152  }
153 
154  if ($num == 0) {
155  $this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>');
156  }
157 
158  $this->db->free($result);
159  } else {
160  $this->info_box_contents[0][0] = array(
161  'td' => '',
162  'maxlength'=>500,
163  'text' => ($this->db->error().' sql='.$sql)
164  );
165  }
166  } else {
167  $this->info_box_contents[0][0] = array(
168  'td' => 'class="nohover left"',
169  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
170  );
171  }
172  }
173 
182  public function showBox($head = null, $contents = null, $nooutput = 0)
183  {
184  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
185  }
186 }
Class ModeleBoxes.
Class to manage Dolibarr users.
Definition: user.class.php:45
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:358
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.
$conf db
API class for accounts.
Definition: inc.php:41