box_birthdays_members.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. /**
  21. * \file htdocs/core/boxes/box_birthdays_members.php
  22. * \ingroup member
  23. * \brief Box for member 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_members extends ModeleBoxes
  30. {
  31. public $boxcode = "birthdays_members";
  32. public $boximg = "object_user";
  33. public $boxlabel = "BoxTitleMemberNextBirthdays";
  34. public $depends = array("adherent");
  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("adherent", "lire") && 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 $user, $langs;
  63. $langs->load("boxes");
  64. $this->max = $max;
  65. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  66. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  67. $memberstatic = new Adherent($this->db);
  68. $this->info_box_head = array('text' => $langs->trans("BoxTitleMemberNextBirthdays"));
  69. if ($user->rights->adherent->lire) {
  70. $tmparray = dol_getdate(dol_now(), true);
  71. $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";
  72. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u";
  73. $sql .= " WHERE u.entity IN (".getEntity('adherent').")";
  74. $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED;
  75. $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
  76. $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
  77. $sql .= $this->db->plimit($max, 0);
  78. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  79. $result = $this->db->query($sql);
  80. if ($result) {
  81. $num = $this->db->num_rows($result);
  82. $line = 0;
  83. while ($line < $num) {
  84. $objp = $this->db->fetch_object($result);
  85. $memberstatic->id = $objp->rowid;
  86. $memberstatic->firstname = $objp->firstname;
  87. $memberstatic->lastname = $objp->lastname;
  88. $memberstatic->email = $objp->email;
  89. $memberstatic->status = $objp->status;
  90. $memberstatic->statut = $memberstatic->status;
  91. $memberstatic->datefin = $this->db->jdate($objp->datefin);
  92. //$memberstatic->need_subscription = 1;
  93. $dateb = $this->db->jdate($objp->birth);
  94. $age = date('Y', dol_now()) - date('Y', $dateb);
  95. $typea = '<i class="fas fa-birthday-cake inline-block"></i>';
  96. $this->info_box_contents[$line][] = array(
  97. 'td' => '',
  98. 'text' => $memberstatic->getNomUrl(1),
  99. 'asis' => 1,
  100. );
  101. $this->info_box_contents[$line][] = array(
  102. 'td' => 'class="center nowraponall"',
  103. 'text' => dol_print_date($dateb, "day", 'gmt').' - '.$age.' '.$langs->trans('DurationYears')
  104. );
  105. $this->info_box_contents[$line][] = array(
  106. 'td' => 'class="center nowraponall"',
  107. 'text' => $typea,
  108. 'asis' => 1
  109. );
  110. /*$this->info_box_contents[$line][] = array(
  111. 'td' => 'class="right" width="18"',
  112. 'text' => $memberstatic->LibStatut($objp->status, 3)
  113. );*/
  114. $line++;
  115. }
  116. if ($num == 0) {
  117. $this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>');
  118. }
  119. $this->db->free($result);
  120. } else {
  121. $this->info_box_contents[0][0] = array(
  122. 'td' => '',
  123. 'maxlength'=>500,
  124. 'text' => ($this->db->error().' sql='.$sql)
  125. );
  126. }
  127. } else {
  128. $this->info_box_contents[0][0] = array(
  129. 'td' => 'class="nohover left"',
  130. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
  131. );
  132. }
  133. }
  134. /**
  135. * Method to show box
  136. *
  137. * @param array $head Array with properties of box title
  138. * @param array $contents Array with properties of box lines
  139. * @param int $nooutput No print, only return string
  140. * @return string
  141. */
  142. public function showBox($head = null, $contents = null, $nooutput = 0)
  143. {
  144. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  145. }
  146. }