box_members_last_subscriptions.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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_subscriptions.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_subscriptions extends ModeleBoxes
  30. {
  31. public $boxcode = "box_members_last_subscriptions";
  32. public $boximg = "object_user";
  33. public $boxlabel = "BoxLastMembersSubscriptions";
  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. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  74. $staticmember = new Adherent($this->db);
  75. $statictype = new AdherentType($this->db);
  76. $subscriptionstatic = new Subscription($this->db);
  77. $this->info_box_head = array('text' => $langs->trans("LastSubscriptionsModified", $max));
  78. if ($user->rights->adherent->lire) {
  79. $sql = "SELECT a.rowid, a.statut as status, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
  80. $sql .= " a.gender, a.email, a.photo, a.morphy,";
  81. $sql .= " a.datefin as date_end_subscription,";
  82. $sql .= " ta.rowid as typeid, ta.libelle as label, ta.subscription as need_subscription,";
  83. $sql .= " c.rowid as cid, c.tms as datem, c.datec as datec, c.dateadh as date_start, c.datef as date_end, c.subscription";
  84. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta, ".MAIN_DB_PREFIX."subscription as c";
  85. $sql .= " WHERE a.entity IN (".getEntity('adherent').")";
  86. $sql .= " AND a.fk_adherent_type = ta.rowid";
  87. $sql .= " AND c.fk_adherent = a.rowid";
  88. $sql .= $this->db->order("c.tms", "DESC");
  89. $sql .= $this->db->plimit($max, 0);
  90. $result = $this->db->query($sql);
  91. if ($result) {
  92. $num = $this->db->num_rows($result);
  93. $line = 0;
  94. while ($line < $num) {
  95. $obj = $this->db->fetch_object($result);
  96. $staticmember->id = $obj->rowid;
  97. $staticmember->ref = $obj->rowid;
  98. $staticmember->lastname = $obj->lastname;
  99. $staticmember->firstname = $obj->firstname;
  100. $staticmember->gender = $obj->gender;
  101. $staticmember->email = $obj->email;
  102. $staticmember->photo = $obj->photo;
  103. $staticmember->morphy = $obj->morphy;
  104. $staticmember->statut = $obj->status;
  105. $staticmember->need_subscription = $obj->need_subscription;
  106. $staticmember->datefin = $this->db->jdate($obj->date_end_subscription);
  107. if (!empty($obj->fk_soc)) {
  108. $staticmember->fk_soc = $obj->fk_soc;
  109. $staticmember->fetch_thirdparty();
  110. $staticmember->name = $staticmember->thirdparty->name;
  111. } else {
  112. $staticmember->name = $obj->company;
  113. }
  114. $subscriptionstatic->id = $obj->cid;
  115. $subscriptionstatic->ref = $obj->cid;
  116. $this->info_box_contents[$line][] = array(
  117. 'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
  118. 'text' => $subscriptionstatic->getNomUrl(1),
  119. 'asis' => 1,
  120. );
  121. $this->info_box_contents[$line][] = array(
  122. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  123. 'text' => $staticmember->getNomUrl(-1, 32, 'subscription'),
  124. 'asis' => 1,
  125. );
  126. $this->info_box_contents[$line][] = array(
  127. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  128. 'text' => get_date_range($this->db->jdate($obj->date_start), $this->db->jdate($obj->date_end)),
  129. );
  130. $this->info_box_contents[$line][] = array(
  131. 'td' => 'class="right" width="18"',
  132. 'text' => '<span class="amount">'.price($obj->subscription).'</span>',
  133. );
  134. $this->info_box_contents[$line][] = array(
  135. 'td' => 'class="right tdoverflowmax150 maxwidth150onsmartphone"',
  136. 'text' => dol_print_date($this->db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour', 'tzuserrel'),
  137. );
  138. $line++;
  139. }
  140. if ($num == 0) {
  141. $this->info_box_contents[$line][0] = array(
  142. 'td' => 'class="center"',
  143. 'text'=>$langs->trans("NoRecordedCustomers"),
  144. );
  145. }
  146. $this->db->free($result);
  147. } else {
  148. $this->info_box_contents[0][0] = array(
  149. 'td' => '',
  150. 'maxlength'=>500,
  151. 'text' => ($this->db->error().' sql='.$sql),
  152. );
  153. }
  154. } else {
  155. $this->info_box_contents[0][0] = array(
  156. 'td' => 'class="nohover opacitymedium left"',
  157. 'text' => $langs->trans("ReadPermissionNotAllowed")
  158. );
  159. }
  160. }
  161. /**
  162. * Method to show box
  163. *
  164. * @param array $head Array with properties of box title
  165. * @param array $contents Array with properties of box lines
  166. * @param int $nooutput No print, only return string
  167. * @return string
  168. */
  169. public function showBox($head = null, $contents = null, $nooutput = 0)
  170. {
  171. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  172. }
  173. }