dolibarr  20.0.0-beta
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 
49  public function __construct($db, $param)
50  {
51  global $user;
52 
53  $this->db = $db;
54 
55  $this->hidden = !($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire'));
56  }
57 
64  public function loadBox($max = 5)
65  {
66  global $user, $langs, $conf, $hookmanager;
67 
68  $langs->load("boxes");
69 
70  $this->max = $max;
71 
72  $contactstatic = new Contact($this->db);
73  $societestatic = new Societe($this->db);
74 
75  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedContacts", $max));
76 
77  if ($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire')) {
78  $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";
79 
80  $sql .= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile, sp.email as spemail";
81  $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
82  $sql .= ", s.code_client, s.client";
83  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
84  if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
85  $sql .= ", spe.accountancy_code_customer as code_compta";
86  $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
87  } else {
88  $sql .= ", s.code_compta";
89  $sql .= ", s.code_compta_fournisseur";
90  }
91  $sql .= ", s.logo, s.email, s.entity";
92  $sql .= ", co.label as country, co.code as country_code";
93  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
94  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON sp.fk_pays = co.rowid";
95  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
96  if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
97  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
98  }
99  if (!$user->hasRight('societe', 'client', 'voir')) {
100  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
101  }
102  $sql .= " WHERE sp.entity IN (".getEntity('contact').")";
103  if (!$user->hasRight('societe', 'client', 'voir')) {
104  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105  }
106  // Add where from hooks
107  $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
108  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
109  if (empty($reshook)) {
110  if ($user->socid > 0) {
111  $sql .= " AND sp.fk_soc = ".((int) $user->socid);
112  }
113  }
114  $sql .= $hookmanager->resPrint;
115  $sql .= " ORDER BY sp.tms DESC";
116  $sql .= $this->db->plimit($max, 0);
117 
118  $result = $this->db->query($sql);
119  if ($result) {
120  $num = $this->db->num_rows($result);
121 
122  $line = 0;
123  while ($line < $num) {
124  $objp = $this->db->fetch_object($result);
125  $datec = $this->db->jdate($objp->datec);
126  $datem = $this->db->jdate($objp->tms);
127 
128  $contactstatic->id = $objp->id;
129  $contactstatic->lastname = $objp->lastname;
130  $contactstatic->firstname = $objp->firstname;
131  $contactstatic->civility_id = $objp->civility_id;
132  $contactstatic->statut = $objp->status;
133  $contactstatic->phone_pro = $objp->phone;
134  $contactstatic->phone_perso = $objp->phone_perso;
135  $contactstatic->phone_mobile = $objp->phone_mobile;
136  $contactstatic->email = $objp->spemail;
137  $contactstatic->address = $objp->address;
138  $contactstatic->zip = $objp->zip;
139  $contactstatic->town = $objp->town;
140  $contactstatic->country = $objp->country;
141  $contactstatic->country_code = $objp->country_code;
142 
143  $societestatic->id = $objp->socid;
144  $societestatic->name = $objp->name;
145  //$societestatic->name_alias = $objp->name_alias;
146  $societestatic->code_client = $objp->code_client;
147  $societestatic->code_compta = $objp->code_compta;
148  $societestatic->client = $objp->client;
149  $societestatic->code_fournisseur = $objp->code_fournisseur;
150  $societestatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
151  $societestatic->fournisseur = $objp->fournisseur;
152  $societestatic->logo = $objp->logo;
153  $societestatic->email = $objp->email;
154  $societestatic->entity = $objp->entity;
155 
156  $this->info_box_contents[$line][] = array(
157  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
158  'text' => $contactstatic->getNomUrl(1),
159  'asis' => 1,
160  );
161 
162  $this->info_box_contents[$line][] = array(
163  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
164  'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
165  'asis' => 1,
166  );
167 
168  $this->info_box_contents[$line][] = array(
169  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
170  'text' => dol_print_date($datem, "day", 'tzuserrel'),
171  );
172 
173  $this->info_box_contents[$line][] = array(
174  'td' => 'class="nowrap right" width="18"',
175  'text' => $contactstatic->getLibStatut(3),
176  'asis'=>1,
177  );
178 
179  $line++;
180  }
181 
182  if ($num == 0) {
183  $this->info_box_contents[$line][0] = array(
184  'td' => 'class="center"',
185  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContacts").'</span>',
186  'asis'=> 1
187  );
188  }
189 
190  $this->db->free($result);
191  } else {
192  $this->info_box_contents[0][0] = array(
193  'td' => '',
194  'maxlength'=>500,
195  'text' => ($this->db->error().' sql='.$sql),
196  );
197  }
198  } else {
199  $this->info_box_contents[0][0] = array(
200  'td' => 'class="nohover left"',
201  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
202  );
203  }
204  }
205 
214  public function showBox($head = null, $contents = null, $nooutput = 0)
215  {
216  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
217  }
218 }
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('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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...