box_birthdays.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. /**
  21. * \file htdocs/core/boxes/box_birthdays.php
  22. * \ingroup user
  23. * \brief Box for user birthdays
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show user birthdays
  28. */
  29. class box_birthdays extends ModeleBoxes
  30. {
  31. public $boxcode = "birthdays";
  32. public $boximg = "object_user";
  33. public $boxlabel = "BoxTitleUserBirthdaysOfMonth";
  34. public $depends = array("user");
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $enabled = 1;
  40. public $info_box_head = array();
  41. public $info_box_contents = array();
  42. /**
  43. * Constructor
  44. *
  45. * @param DoliDB $db Database handler
  46. * @param string $param More parameters
  47. */
  48. public function __construct($db, $param = '')
  49. {
  50. global $user;
  51. $this->db = $db;
  52. $this->hidden = !($user->hasRight('user', 'user', 'read') && empty($user->socid));
  53. }
  54. /**
  55. * Load data for box to show them later
  56. *
  57. * @param int $max Maximum number of records to load
  58. * @return void
  59. */
  60. public function loadBox($max = 20)
  61. {
  62. global $conf, $user, $langs;
  63. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  64. include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  65. $userstatic = new User($this->db);
  66. $langs->load("boxes");
  67. $this->max = $max;
  68. $this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth"));
  69. if ($user->hasRight('user', 'user', 'lire')) {
  70. $data = array();
  71. $tmparray = dol_getdate(dol_now(), true);
  72. $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";
  73. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  74. $sql .= " WHERE u.entity IN (".getEntity('user').")";
  75. $sql .= " AND u.statut = ".User::STATUS_ENABLED;
  76. $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
  77. $sql .= " AND u.birth < '".$this->db->idate(dol_get_first_day($tmparray['year']))."'";
  78. $sql .= ' UNION ';
  79. $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";
  80. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  81. $sql .= " WHERE u.entity IN (".getEntity('user').")";
  82. $sql .= " AND u.statut = ".User::STATUS_ENABLED;
  83. $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0);
  84. $sql .= " AND u.dateemployment < '".$this->db->idate(dol_get_first_day($tmparray['year']))."'";
  85. $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
  86. $sql .= $this->db->plimit($max, 0);
  87. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  88. $resql = $this->db->query($sql);
  89. if ($resql) {
  90. $num = $this->db->num_rows($resql);
  91. $line = 0;
  92. while ($line < $num) {
  93. $data[$line] = $this->db->fetch_object($resql);
  94. $line++;
  95. }
  96. $this->db->free($resql);
  97. }
  98. if (!empty($data)) {
  99. $j = 0;
  100. while ($j < count($data)) {
  101. $userstatic->id = $data[$j]->rowid;
  102. $userstatic->firstname = $data[$j]->firstname;
  103. $userstatic->lastname = $data[$j]->lastname;
  104. $userstatic->email = $data[$j]->email;
  105. $userstatic->statut = $data[$j]->status;
  106. $dateb = $this->db->jdate($data[$j]->datea);
  107. $age = date('Y', dol_now()) - date('Y', $dateb);
  108. $picb = '<i class="fas fa-birthday-cake inline-block"></i>';
  109. $pice = '<i class="fas fa-briefcase inline-block"></i>';
  110. $typea = ($data[$j]->typea == 'birth') ? $picb : $pice;
  111. $this->info_box_contents[$j][0] = array(
  112. 'td' => '',
  113. 'text' => $userstatic->getNomUrl(1),
  114. 'asis' => 1,
  115. );
  116. $this->info_box_contents[$j][1] = array(
  117. 'td' => 'class="center nowraponall"',
  118. 'text' => dol_print_date($dateb, "day", 'tzserver')
  119. );
  120. $this->info_box_contents[$j][2] = array(
  121. 'td' => 'class="right nowraponall"',
  122. 'text' => $age.' '.$langs->trans('DurationYears')
  123. );
  124. $this->info_box_contents[$j][3] = array(
  125. 'td' => 'class="right nowraponall"',
  126. 'text' => $typea,
  127. 'asis' => 1
  128. );
  129. $j++;
  130. }
  131. }
  132. if (is_array($data) && count($data) == 0) {
  133. $this->info_box_contents[0][0] = array(
  134. 'td' => 'class="center"',
  135. 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>',
  136. );
  137. }
  138. } else {
  139. $this->info_box_contents[0][0] = array(
  140. 'td' => 'class="nohover left"',
  141. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
  142. );
  143. }
  144. }
  145. /**
  146. * Method to show box
  147. *
  148. * @param array $head Array with properties of box title
  149. * @param array $contents Array with properties of box lines
  150. * @param int $nooutput No print, only return string
  151. * @return string
  152. */
  153. public function showBox($head = null, $contents = null, $nooutput = 0)
  154. {
  155. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  156. }
  157. }