box_prospect.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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_prospect.php
  22. * \ingroup societe
  23. * \brief Module to generate the last prospects box.
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  27. /**
  28. * Class to manage the box to show last prospects
  29. */
  30. class box_prospect extends ModeleBoxes
  31. {
  32. public $boxcode = "lastprospects";
  33. public $boximg = "object_company";
  34. public $boxlabel = "BoxLastProspects";
  35. public $depends = array("societe");
  36. /**
  37. * @var DoliDB Database handler.
  38. */
  39. public $db;
  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 box for such cases
  54. if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  55. $this->enabled = 0; // disabled by this option
  56. }
  57. $this->hidden = !($user->rights->societe->lire && empty($user->socid));
  58. }
  59. /**
  60. * Load data into info_box_contents array to show array later.
  61. *
  62. * @param int $max Maximum number of records to load
  63. * @return void
  64. */
  65. public function loadBox($max = 5)
  66. {
  67. global $user, $langs, $hookmanager;
  68. $this->max = $max;
  69. $thirdpartystatic = new Client($this->db);
  70. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedProspects", $max));
  71. if ($user->rights->societe->lire) {
  72. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  73. $sql .= ", s.code_client, s.code_compta, s.client";
  74. $sql .= ", s.logo, s.email, s.entity";
  75. $sql .= ", s.fk_stcomm";
  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 (2, 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. $resql = $this->db->query($sql);
  99. if ($resql) {
  100. $num = $this->db->num_rows($resql);
  101. $line = 0;
  102. while ($line < $num) {
  103. $objp = $this->db->fetch_object($resql);
  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' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3)),
  127. );
  128. $this->info_box_contents[$line][] = array(
  129. 'td' => 'class="right" width="18"',
  130. 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
  131. );
  132. $line++;
  133. }
  134. if ($num == 0) {
  135. $this->info_box_contents[$line][0] = array(
  136. 'td' => 'class="center opacitymedium"',
  137. 'text'=> $langs->trans("NoRecordedProspects"),
  138. );
  139. }
  140. $this->db->free($resql);
  141. } else {
  142. $this->info_box_contents[0][0] = array(
  143. 'td' => '',
  144. 'maxlength' => 500,
  145. 'text' => ($this->db->error().' sql='.$sql),
  146. );
  147. }
  148. } else {
  149. $this->info_box_contents[0][0] = array(
  150. 'td' => 'class="nohover opacitymedium left"',
  151. 'text' => $langs->trans("ReadPermissionNotAllowed")
  152. );
  153. }
  154. }
  155. /**
  156. * Method to show box
  157. *
  158. * @param array $head Array with properties of box title
  159. * @param array $contents Array with properties of box lines
  160. * @param int $nooutput No print, only return string
  161. * @return string
  162. */
  163. public function showBox($head = null, $contents = null, $nooutput = 0)
  164. {
  165. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  166. }
  167. }