box_members_last_modified.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 modified 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 = !(!empty($conf->adherent->enabled) && $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 as datem, 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->datem);
  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->date_creation = $datec;
  105. $memberstatic->date_modification = $datem;
  106. $memberstatic->need_subscription = $objp->subscription;
  107. $memberstatic->datefin = $this->db->jdate($objp->date_end_subscription);
  108. if (!empty($objp->fk_soc)) {
  109. $memberstatic->socid = $objp->fk_soc;
  110. $memberstatic->fetch_thirdparty();
  111. $memberstatic->name = $memberstatic->thirdparty->name;
  112. } else {
  113. $memberstatic->name = $objp->company;
  114. }
  115. $statictype->id = $objp->typeid;
  116. $statictype->label = $objp->label;
  117. $statictype->subscription = $objp->subscription;
  118. $this->info_box_contents[$line][] = array(
  119. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  120. 'text' => $memberstatic->getNomUrl(-1),
  121. 'asis' => 1,
  122. );
  123. $this->info_box_contents[$line][] = array(
  124. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  125. 'text' =>$memberstatic->company,
  126. );
  127. $this->info_box_contents[$line][] = array(
  128. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  129. 'text' => $statictype->getNomUrl(1, 32),
  130. 'asis' => 1,
  131. );
  132. $this->info_box_contents[$line][] = array(
  133. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  134. 'text' => dol_print_date($datem, "day", 'tzuserrel'),
  135. );
  136. $this->info_box_contents[$line][] = array(
  137. 'td' => 'class="right" width="18"',
  138. 'text' => $memberstatic->LibStatut($objp->status, $objp->subscription, $this->db->jdate($objp->date_end_subscription), 3),
  139. );
  140. $line++;
  141. }
  142. if ($num == 0) {
  143. $this->info_box_contents[$line][0] = array(
  144. 'td' => 'class="center"',
  145. 'text'=>$langs->trans("NoRecordedCustomers"),
  146. );
  147. }
  148. $this->db->free($result);
  149. } else {
  150. $this->info_box_contents[0][0] = array(
  151. 'td' => '',
  152. 'maxlength'=>500,
  153. 'text' => ($this->db->error().' sql='.$sql),
  154. );
  155. }
  156. } else {
  157. $this->info_box_contents[0][0] = array(
  158. 'td' => 'class="nohover opacitymedium left"',
  159. 'text' => $langs->trans("ReadPermissionNotAllowed")
  160. );
  161. }
  162. }
  163. /**
  164. * Method to show box
  165. *
  166. * @param array $head Array with properties of box title
  167. * @param array $contents Array with properties of box lines
  168. * @param int $nooutput No print, only return string
  169. * @return string
  170. */
  171. public function showBox($head = null, $contents = null, $nooutput = 0)
  172. {
  173. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  174. }
  175. }