box_clients.php 5.9 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-2021 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_clients.php
  22. * \ingroup societes
  23. * \brief Module de generation de l'affichage de la box clients
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last thirdparties
  28. */
  29. class box_clients extends ModeleBoxes
  30. {
  31. public $boxcode = "lastcustomers";
  32. public $boximg = "object_company";
  33. public $boxlabel = "BoxLastCustomers";
  34. public $depends = array("societe");
  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 $conf, $user;
  51. $this->db = $db;
  52. // disable box for such cases
  53. if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  54. $this->enabled = 0; // disabled by this option
  55. }
  56. $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
  57. }
  58. /**
  59. * Load data for box to show them later
  60. *
  61. * @param int $max Maximum number of records to load
  62. * @return void
  63. */
  64. public function loadBox($max = 5)
  65. {
  66. global $user, $langs, $hookmanager;
  67. $langs->load("boxes");
  68. $this->max = $max;
  69. include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  70. $thirdpartystatic = new Client($this->db);
  71. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers", $max));
  72. if ($user->hasRight('societe', 'lire')) {
  73. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  74. $sql .= ", s.code_client, s.code_compta, s.client";
  75. $sql .= ", s.logo, s.email, s.entity";
  76. $sql .= ", s.datec, s.tms, s.status";
  77. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  78. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  79. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  80. }
  81. $sql .= " WHERE s.client IN (1, 3)";
  82. $sql .= " AND s.entity IN (".getEntity('societe').")";
  83. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  84. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  85. }
  86. // Add where from hooks
  87. $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
  88. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
  89. if (empty($reshook)) {
  90. if ($user->socid > 0) {
  91. $sql .= " AND s.rowid = ".((int) $user->socid);
  92. }
  93. }
  94. $sql .= $hookmanager->resPrint;
  95. $sql .= " ORDER BY s.tms DESC";
  96. $sql .= $this->db->plimit($max, 0);
  97. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  98. $result = $this->db->query($sql);
  99. if ($result) {
  100. $num = $this->db->num_rows($result);
  101. $line = 0;
  102. while ($line < $num) {
  103. $objp = $this->db->fetch_object($result);
  104. $datec = $this->db->jdate($objp->datec);
  105. $datem = $this->db->jdate($objp->tms);
  106. $thirdpartystatic->id = $objp->socid;
  107. $thirdpartystatic->name = $objp->name;
  108. $thirdpartystatic->name_alias = $objp->name_alias;
  109. $thirdpartystatic->code_client = $objp->code_client;
  110. $thirdpartystatic->code_compta = $objp->code_compta;
  111. $thirdpartystatic->client = $objp->client;
  112. $thirdpartystatic->logo = $objp->logo;
  113. $thirdpartystatic->email = $objp->email;
  114. $thirdpartystatic->entity = $objp->entity;
  115. $this->info_box_contents[$line][] = array(
  116. 'td' => 'class="tdoverflowmax150"',
  117. 'text' => $thirdpartystatic->getNomUrl(1),
  118. 'asis' => 1,
  119. );
  120. $this->info_box_contents[$line][] = array(
  121. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  122. 'text' => dol_print_date($datem, "day", 'tzuserrel')
  123. );
  124. $this->info_box_contents[$line][] = array(
  125. 'td' => 'class="right" width="18"',
  126. 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
  127. );
  128. $line++;
  129. }
  130. if ($num == 0) {
  131. $this->info_box_contents[$line][0] = array(
  132. 'td' => 'class="center opacitymedium"',
  133. 'text'=>$langs->trans("NoRecordedCustomers")
  134. );
  135. }
  136. $this->db->free($result);
  137. } else {
  138. $this->info_box_contents[0][0] = array(
  139. 'td' => '',
  140. 'maxlength'=>500,
  141. 'text' => ($this->db->error().' sql='.$sql)
  142. );
  143. }
  144. } else {
  145. $this->info_box_contents[0][0] = array(
  146. 'td' => 'class="nohover opacitymedium left"',
  147. 'text' => $langs->trans("ReadPermissionNotAllowed")
  148. );
  149. }
  150. }
  151. /**
  152. * Method to show box
  153. *
  154. * @param array $head Array with properties of box title
  155. * @param array $contents Array with properties of box lines
  156. * @param int $nooutput No print, only return string
  157. * @return string
  158. */
  159. public function showBox($head = null, $contents = null, $nooutput = 0)
  160. {
  161. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  162. }
  163. }