box_contacts.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  6. * Copyright (C) 2018 Josep Lluís Amador <joseplluis@lliuretic.cat>
  7. * Copyright (C) 2020 Ferran Marcet <fmarcet@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/core/boxes/box_contacts.php
  24. * \ingroup contacts
  25. * \brief Module to show box of contacts
  26. */
  27. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  28. include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. /**
  30. * Class to manage the box to show last contacts
  31. */
  32. class box_contacts extends ModeleBoxes
  33. {
  34. public $boxcode = "lastcontacts";
  35. public $boximg = "object_contact";
  36. public $boxlabel = "BoxLastContacts";
  37. public $depends = array("societe");
  38. /**
  39. * @var DoliDB Database handler.
  40. */
  41. public $db;
  42. public $param;
  43. public $info_box_head = array();
  44. public $info_box_contents = array();
  45. /**
  46. * Constructor
  47. *
  48. * @param DoliDB $db Database handler
  49. * @param string $param More parameters
  50. */
  51. public function __construct($db, $param)
  52. {
  53. global $user;
  54. $this->db = $db;
  55. $this->hidden = !($user->rights->societe->lire && $user->rights->societe->contact->lire);
  56. }
  57. /**
  58. * Load data into info_box_contents array to show array later.
  59. *
  60. * @param int $max Maximum number of records to load
  61. * @return void
  62. */
  63. public function loadBox($max = 5)
  64. {
  65. global $user, $langs, $conf;
  66. $langs->load("boxes");
  67. $this->max = $max;
  68. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedContacts", $max));
  69. if ($user->rights->societe->lire && $user->rights->societe->contact->lire) {
  70. $sql = "SELECT sp.rowid as id, sp.lastname, sp.firstname, sp.civility as civility_id, sp.datec, sp.tms, sp.fk_soc, sp.statut as status";
  71. $sql .= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile, sp.email as spemail";
  72. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  73. $sql .= ", s.code_client, s.client";
  74. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  75. if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
  76. $sql .= ", spe.accountancy_code_customer as code_compta";
  77. $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
  78. } else {
  79. $sql .= ", s.code_compta";
  80. $sql .= ", s.code_compta_fournisseur";
  81. }
  82. $sql .= ", s.logo, s.email, s.entity";
  83. $sql .= ", co.label as country, co.code as country_code";
  84. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
  85. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON sp.fk_pays = co.rowid";
  86. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
  87. if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
  88. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
  89. }
  90. if (!$user->rights->societe->client->voir && !$user->socid) {
  91. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  92. }
  93. $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")";
  94. if (!$user->rights->societe->client->voir && !$user->socid) {
  95. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  96. }
  97. if ($user->socid) {
  98. $sql .= " AND sp.fk_soc = ".((int) $user->socid);
  99. }
  100. $sql .= " ORDER BY sp.tms DESC";
  101. $sql .= $this->db->plimit($max, 0);
  102. $result = $this->db->query($sql);
  103. if ($result) {
  104. $num = $this->db->num_rows($result);
  105. $contactstatic = new Contact($this->db);
  106. $societestatic = new Societe($this->db);
  107. $line = 0;
  108. while ($line < $num) {
  109. $objp = $this->db->fetch_object($result);
  110. $datec = $this->db->jdate($objp->datec);
  111. $datem = $this->db->jdate($objp->tms);
  112. $contactstatic->id = $objp->id;
  113. $contactstatic->lastname = $objp->lastname;
  114. $contactstatic->firstname = $objp->firstname;
  115. $contactstatic->civility_id = $objp->civility_id;
  116. $contactstatic->statut = $objp->status;
  117. $contactstatic->phone_pro = $objp->phone;
  118. $contactstatic->phone_perso = $objp->phone_perso;
  119. $contactstatic->phone_mobile = $objp->phone_mobile;
  120. $contactstatic->email = $objp->spemail;
  121. $contactstatic->address = $objp->address;
  122. $contactstatic->zip = $objp->zip;
  123. $contactstatic->town = $objp->town;
  124. $contactstatic->country = $objp->country;
  125. $contactstatic->country_code = $objp->country_code;
  126. $societestatic->id = $objp->socid;
  127. $societestatic->name = $objp->name;
  128. //$societestatic->name_alias = $objp->name_alias;
  129. $societestatic->code_client = $objp->code_client;
  130. $societestatic->code_compta = $objp->code_compta;
  131. $societestatic->client = $objp->client;
  132. $societestatic->code_fournisseur = $objp->code_fournisseur;
  133. $societestatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  134. $societestatic->fournisseur = $objp->fournisseur;
  135. $societestatic->logo = $objp->logo;
  136. $societestatic->email = $objp->email;
  137. $societestatic->entity = $objp->entity;
  138. $this->info_box_contents[$line][] = array(
  139. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  140. 'text' => $contactstatic->getNomUrl(1),
  141. 'asis' => 1,
  142. );
  143. $this->info_box_contents[$line][] = array(
  144. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  145. 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
  146. 'asis' => 1,
  147. );
  148. $this->info_box_contents[$line][] = array(
  149. 'td' => 'class="right"',
  150. 'text' => dol_print_date($datem, "day", 'tzuserrel'),
  151. );
  152. $this->info_box_contents[$line][] = array(
  153. 'td' => 'class="nowrap right" width="18"',
  154. 'text' => $contactstatic->getLibStatut(3),
  155. 'asis'=>1,
  156. );
  157. $line++;
  158. }
  159. if ($num == 0) {
  160. $this->info_box_contents[$line][0] = array(
  161. 'td' => 'class="center"',
  162. 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContacts").'</span>',
  163. 'asis'=> 1
  164. );
  165. }
  166. $this->db->free($result);
  167. } else {
  168. $this->info_box_contents[0][0] = array(
  169. 'td' => '',
  170. 'maxlength'=>500,
  171. 'text' => ($this->db->error().' sql='.$sql),
  172. );
  173. }
  174. } else {
  175. $this->info_box_contents[0][0] = array(
  176. 'td' => 'class="nohover left"',
  177. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
  178. );
  179. }
  180. }
  181. /**
  182. * Method to show box
  183. *
  184. * @param array $head Array with properties of box title
  185. * @param array $contents Array with properties of box lines
  186. * @param int $nooutput No print, only return string
  187. * @return string
  188. */
  189. public function showBox($head = null, $contents = null, $nooutput = 0)
  190. {
  191. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  192. }
  193. }