box_members_last_modified.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015-2020 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_members_last_modified.php
  22. * \ingroup adherent
  23. * \brief Module to show box of members
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last modofied members
  28. */
  29. class box_members_last_modified extends ModeleBoxes
  30. {
  31. public $boxcode = "box_members_last_modified";
  32. public $boximg = "object_user";
  33. public $boxlabel = "BoxLastModifiedMembers";
  34. public $depends = array("adherent");
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $param;
  40. public $enabled = 1;
  41. public $info_box_head = array();
  42. public $info_box_contents = array();
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. * @param string $param More parameters
  48. */
  49. public function __construct($db, $param = '')
  50. {
  51. global $conf, $user;
  52. $this->db = $db;
  53. // disable module for such cases
  54. $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
  55. if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
  56. $this->enabled = 0; // disabled for external users
  57. }
  58. $this->hidden = !($user->rights->adherent->lire);
  59. }
  60. /**
  61. * Load data into info_box_contents array to show array later.
  62. *
  63. * @param int $max Maximum number of records to load
  64. * @return void
  65. */
  66. public function loadBox($max = 5)
  67. {
  68. global $user, $langs, $conf;
  69. $langs->load("boxes");
  70. $this->max = $max;
  71. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  72. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  73. $memberstatic = new Adherent($this->db);
  74. $statictype = new AdherentType($this->db);
  75. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedMembers", $max));
  76. if ($user->rights->adherent->lire) {
  77. $sql = "SELECT a.rowid, a.ref, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
  78. $sql .= " a.datec, a.tms, a.statut as status, a.datefin as date_end_subscription,";
  79. $sql .= ' a.photo, a.email, a.gender, a.morphy,';
  80. $sql .= " t.rowid as typeid, t.subscription, t.libelle as label";
  81. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as t";
  82. $sql .= " WHERE a.entity IN (".getEntity('member').")";
  83. $sql .= " AND a.fk_adherent_type = t.rowid";
  84. $sql .= " ORDER BY a.tms DESC";
  85. $sql .= $this->db->plimit($max, 0);
  86. $result = $this->db->query($sql);
  87. if ($result) {
  88. $num = $this->db->num_rows($result);
  89. $line = 0;
  90. while ($line < $num) {
  91. $objp = $this->db->fetch_object($result);
  92. $datec = $this->db->jdate($objp->datec);
  93. $datem = $this->db->jdate($objp->tms);
  94. $memberstatic->lastname = $objp->lastname;
  95. $memberstatic->firstname = $objp->firstname;
  96. $memberstatic->id = $objp->rowid;
  97. $memberstatic->ref = $objp->ref;
  98. $memberstatic->photo = $objp->photo;
  99. $memberstatic->gender = $objp->gender;
  100. $memberstatic->email = $objp->email;
  101. $memberstatic->morphy = $objp->morphy;
  102. $memberstatic->company = $objp->company;
  103. $memberstatic->statut = $objp->status;
  104. $memberstatic->need_subscription = $objp->subscription;
  105. $memberstatic->datefin = $this->db->jdate($objp->date_end_subscription);
  106. if (!empty($objp->fk_soc)) {
  107. $memberstatic->socid = $objp->fk_soc;
  108. $memberstatic->fetch_thirdparty();
  109. $memberstatic->name = $memberstatic->thirdparty->name;
  110. } else {
  111. $memberstatic->name = $objp->company;
  112. }
  113. $statictype->id = $objp->typeid;
  114. $statictype->label = $objp->label;
  115. $statictype->subscription = $objp->subscription;
  116. $this->info_box_contents[$line][] = array(
  117. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  118. 'text' => $memberstatic->getNomUrl(-1),
  119. 'asis' => 1,
  120. );
  121. $this->info_box_contents[$line][] = array(
  122. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  123. 'text' => $statictype->getNomUrl(1, 32),
  124. 'asis' => 1,
  125. );
  126. $this->info_box_contents[$line][] = array(
  127. 'td' => 'class="center nowraponall"',
  128. 'text' => dol_print_date($datem, "day", 'tzuserrel'),
  129. );
  130. $this->info_box_contents[$line][] = array(
  131. 'td' => 'class="right" width="18"',
  132. 'text' => $memberstatic->LibStatut($objp->status, $objp->subscription, $this->db->jdate($objp->date_end_subscription), 3),
  133. );
  134. $line++;
  135. }
  136. if ($num == 0) {
  137. $this->info_box_contents[$line][0] = array(
  138. 'td' => 'class="center"',
  139. 'text'=>$langs->trans("NoRecordedCustomers"),
  140. );
  141. }
  142. $this->db->free($result);
  143. } else {
  144. $this->info_box_contents[0][0] = array(
  145. 'td' => '',
  146. 'maxlength'=>500,
  147. 'text' => ($this->db->error().' sql='.$sql),
  148. );
  149. }
  150. } else {
  151. $this->info_box_contents[0][0] = array(
  152. 'td' => 'class="nohover opacitymedium left"',
  153. 'text' => $langs->trans("ReadPermissionNotAllowed")
  154. );
  155. }
  156. }
  157. /**
  158. * Method to show box
  159. *
  160. * @param array $head Array with properties of box title
  161. * @param array $contents Array with properties of box lines
  162. * @param int $nooutput No print, only return string
  163. * @return string
  164. */
  165. public function showBox($head = null, $contents = null, $nooutput = 0)
  166. {
  167. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  168. }
  169. }