dolibarr  19.0.0-dev
box_contacts.php
Go to the documentation of this file.
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 
29 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
30 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 
32 
37 {
38  public $boxcode = "lastcontacts";
39  public $boximg = "object_contact";
40  public $boxlabel = "BoxLastContacts";
41  public $depends = array("societe");
42 
46  public $db;
47 
48  public $param;
49 
50  public $info_box_head = array();
51  public $info_box_contents = array();
52 
53 
60  public function __construct($db, $param)
61  {
62  global $user;
63 
64  $this->db = $db;
65 
66  $this->hidden = !($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire'));
67  }
68 
75  public function loadBox($max = 5)
76  {
77  global $user, $langs, $conf, $hookmanager;
78 
79  $langs->load("boxes");
80 
81  $this->max = $max;
82 
83  $contactstatic = new Contact($this->db);
84  $societestatic = new Societe($this->db);
85 
86  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedContacts", $max));
87 
88  if ($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire')) {
89  $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";
90 
91  $sql .= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile, sp.email as spemail";
92  $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
93  $sql .= ", s.code_client, s.client";
94  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
95  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
96  $sql .= ", spe.accountancy_code_customer as code_compta";
97  $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
98  } else {
99  $sql .= ", s.code_compta";
100  $sql .= ", s.code_compta_fournisseur";
101  }
102  $sql .= ", s.logo, s.email, s.entity";
103  $sql .= ", co.label as country, co.code as country_code";
104  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
105  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON sp.fk_pays = co.rowid";
106  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
107  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
108  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
109  }
110  if (empty($user->rights->societe->client->voir) && !$user->socid) {
111  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
112  }
113  $sql .= " WHERE sp.entity IN (".getEntity('contact').")";
114  if (empty($user->rights->societe->client->voir) && !$user->socid) {
115  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
116  }
117  // Add where from hooks
118  $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
119  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
120  if (empty($reshook)) {
121  if ($user->socid > 0) {
122  $sql .= " AND sp.fk_soc = ".((int) $user->socid);
123  }
124  }
125  $sql .= $hookmanager->resPrint;
126  $sql .= " ORDER BY sp.tms DESC";
127  $sql .= $this->db->plimit($max, 0);
128 
129  $result = $this->db->query($sql);
130  if ($result) {
131  $num = $this->db->num_rows($result);
132 
133  $line = 0;
134  while ($line < $num) {
135  $objp = $this->db->fetch_object($result);
136  $datec = $this->db->jdate($objp->datec);
137  $datem = $this->db->jdate($objp->tms);
138 
139  $contactstatic->id = $objp->id;
140  $contactstatic->lastname = $objp->lastname;
141  $contactstatic->firstname = $objp->firstname;
142  $contactstatic->civility_id = $objp->civility_id;
143  $contactstatic->statut = $objp->status;
144  $contactstatic->phone_pro = $objp->phone;
145  $contactstatic->phone_perso = $objp->phone_perso;
146  $contactstatic->phone_mobile = $objp->phone_mobile;
147  $contactstatic->email = $objp->spemail;
148  $contactstatic->address = $objp->address;
149  $contactstatic->zip = $objp->zip;
150  $contactstatic->town = $objp->town;
151  $contactstatic->country = $objp->country;
152  $contactstatic->country_code = $objp->country_code;
153 
154  $societestatic->id = $objp->socid;
155  $societestatic->name = $objp->name;
156  //$societestatic->name_alias = $objp->name_alias;
157  $societestatic->code_client = $objp->code_client;
158  $societestatic->code_compta = $objp->code_compta;
159  $societestatic->client = $objp->client;
160  $societestatic->code_fournisseur = $objp->code_fournisseur;
161  $societestatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
162  $societestatic->fournisseur = $objp->fournisseur;
163  $societestatic->logo = $objp->logo;
164  $societestatic->email = $objp->email;
165  $societestatic->entity = $objp->entity;
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
169  'text' => $contactstatic->getNomUrl(1),
170  'asis' => 1,
171  );
172 
173  $this->info_box_contents[$line][] = array(
174  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
175  'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
176  'asis' => 1,
177  );
178 
179  $this->info_box_contents[$line][] = array(
180  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
181  'text' => dol_print_date($datem, "day", 'tzuserrel'),
182  );
183 
184  $this->info_box_contents[$line][] = array(
185  'td' => 'class="nowrap right" width="18"',
186  'text' => $contactstatic->getLibStatut(3),
187  'asis'=>1,
188  );
189 
190  $line++;
191  }
192 
193  if ($num == 0) {
194  $this->info_box_contents[$line][0] = array(
195  'td' => 'class="center"',
196  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContacts").'</span>',
197  'asis'=> 1
198  );
199  }
200 
201  $this->db->free($result);
202  } else {
203  $this->info_box_contents[0][0] = array(
204  'td' => '',
205  'maxlength'=>500,
206  'text' => ($this->db->error().' sql='.$sql),
207  );
208  }
209  } else {
210  $this->info_box_contents[0][0] = array(
211  'td' => 'class="nohover left"',
212  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
213  );
214  }
215  }
216 
225  public function showBox($head = null, $contents = null, $nooutput = 0)
226  {
227  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
228  }
229 }
Class to manage contact/addresses.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last contacts.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...