dolibarr 20.0.0
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
29include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
30include_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(
76 'text' => $langs->trans("BoxTitleLastModifiedContacts", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/contact/list.php?sortfield=p.tms&sortorder=DESC"><span class="badge">...</span></a>'
77 );
78
79 if ($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire')) {
80 $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";
81
82 $sql .= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile, sp.email as spemail";
83 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
84 $sql .= ", s.code_client, s.client";
85 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
86 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
87 $sql .= ", spe.accountancy_code_customer as code_compta";
88 $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
89 } else {
90 $sql .= ", s.code_compta";
91 $sql .= ", s.code_compta_fournisseur";
92 }
93 $sql .= ", s.logo, s.email, s.entity";
94 $sql .= ", co.label as country, co.code as country_code";
95 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
96 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON sp.fk_pays = co.rowid";
97 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
98 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
99 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
100 }
101 if (!$user->hasRight('societe', 'client', 'voir')) {
102 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
103 }
104 $sql .= " WHERE sp.entity IN (".getEntity('contact').")";
105 if (!$user->hasRight('societe', 'client', 'voir')) {
106 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107 }
108 // Add where from hooks
109 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
110 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
111 if (empty($reshook)) {
112 if ($user->socid > 0) {
113 $sql .= " AND sp.fk_soc = ".((int) $user->socid);
114 }
115 }
116 $sql .= $hookmanager->resPrint;
117 $sql .= " ORDER BY sp.tms DESC";
118 $sql .= $this->db->plimit($max, 0);
119
120 $result = $this->db->query($sql);
121 if ($result) {
122 $num = $this->db->num_rows($result);
123
124 $line = 0;
125 while ($line < $num) {
126 $objp = $this->db->fetch_object($result);
127 $datec = $this->db->jdate($objp->datec);
128 $datem = $this->db->jdate($objp->tms);
129
130 $contactstatic->id = $objp->id;
131 $contactstatic->lastname = $objp->lastname;
132 $contactstatic->firstname = $objp->firstname;
133 $contactstatic->civility_id = $objp->civility_id;
134 $contactstatic->statut = $objp->status;
135 $contactstatic->phone_pro = $objp->phone;
136 $contactstatic->phone_perso = $objp->phone_perso;
137 $contactstatic->phone_mobile = $objp->phone_mobile;
138 $contactstatic->email = $objp->spemail;
139 $contactstatic->address = $objp->address;
140 $contactstatic->zip = $objp->zip;
141 $contactstatic->town = $objp->town;
142 $contactstatic->country = $objp->country;
143 $contactstatic->country_code = $objp->country_code;
144
145 $societestatic->id = $objp->socid;
146 $societestatic->name = $objp->name;
147 //$societestatic->name_alias = $objp->name_alias;
148 $societestatic->code_client = $objp->code_client;
149 $societestatic->code_compta = $objp->code_compta;
150 $societestatic->client = $objp->client;
151 $societestatic->code_fournisseur = $objp->code_fournisseur;
152 $societestatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
153 $societestatic->fournisseur = $objp->fournisseur;
154 $societestatic->logo = $objp->logo;
155 $societestatic->email = $objp->email;
156 $societestatic->entity = $objp->entity;
157
158 $this->info_box_contents[$line][] = array(
159 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
160 'text' => $contactstatic->getNomUrl(1),
161 'asis' => 1,
162 );
163
164 $this->info_box_contents[$line][] = array(
165 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
166 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
167 'asis' => 1,
168 );
169
170 $this->info_box_contents[$line][] = array(
171 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
172 'text' => dol_print_date($datem, "day", 'tzuserrel'),
173 );
174
175 $this->info_box_contents[$line][] = array(
176 'td' => 'class="nowrap right" width="18"',
177 'text' => $contactstatic->getLibStatut(3),
178 'asis'=>1,
179 );
180
181 $line++;
182 }
183
184 if ($num == 0) {
185 $this->info_box_contents[$line][0] = array(
186 'td' => 'class="center"',
187 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContacts").'</span>',
188 'asis'=> 1
189 );
190 }
191
192 $this->db->free($result);
193 } else {
194 $this->info_box_contents[0][0] = array(
195 'td' => '',
196 'maxlength'=>500,
197 'text' => ($this->db->error().' sql='.$sql),
198 );
199 }
200 } else {
201 $this->info_box_contents[0][0] = array(
202 'td' => 'class="nohover left"',
203 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
204 );
205 }
206 }
207
216 public function showBox($head = null, $contents = null, $nooutput = 0)
217 {
218 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
219 }
220}
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.
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...