dolibarr 22.0.5
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-2025 Frédéric 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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
31include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32
33
38{
39 public $boxcode = "lastcontacts";
40 public $boximg = "object_contact";
41 public $boxlabel = "BoxLastContacts";
42 public $depends = array("societe");
43
50 public function __construct($db, $param)
51 {
52 global $user;
53
54 $this->db = $db;
55
56 $this->hidden = !($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire'));
57
58 $this->urltoaddentry = DOL_URL_ROOT.'/contact/card.php?action=create';
59
60 $this->msgNoRecords = 'NoRecordedContacts';
61 }
62
69 public function loadBox($max = 5)
70 {
71 global $user, $langs, $conf, $hookmanager;
72
73 $langs->loadLangs(array("boxes", "contracts"));
74
75 $this->max = $max;
76
77 $contactstatic = new Contact($this->db);
78 $societestatic = new Societe($this->db);
79
80 $this->info_box_head = array(
81 '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>'
82 );
83
84 if ($user->hasRight('societe', 'lire') && $user->hasRight('societe', 'contact', 'lire')) {
85 $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";
86
87 $sql .= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile, sp.email as spemail";
88 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
89 $sql .= ", s.code_client, s.client";
90 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
91 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
92 $sql .= ", spe.accountancy_code_customer as code_compta_client";
93 $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
94 } else {
95 $sql .= ", s.code_compta as code_compta_client";
96 $sql .= ", s.code_compta_fournisseur";
97 }
98 $sql .= ", s.logo, s.email, s.entity";
99 $sql .= ", co.label as country, co.code as country_code";
100 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
101 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON sp.fk_pays = co.rowid";
102 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
103 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
104 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
105 }
106 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
107 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
108 }
109 $sql .= " WHERE sp.entity IN (".getEntity('contact').")";
110 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
111 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
112 }
113 $sql .= " AND ((sp.fk_user_creat = ".((int) $user->id)." AND sp.priv = 1) OR sp.priv = 0)"; // check if this is a private contact
114 // Add where from hooks
115 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
116 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
117 if (empty($reshook)) {
118 if ($user->socid > 0) {
119 $sql .= " AND sp.fk_soc = ".((int) $user->socid);
120 }
121 }
122 $sql .= $hookmanager->resPrint;
123 $sql .= " ORDER BY sp.tms DESC";
124 $sql .= $this->db->plimit($max, 0);
125
126 $result = $this->db->query($sql);
127 if ($result) {
128 $num = $this->db->num_rows($result);
129
130 $line = 0;
131 while ($line < $num) {
132 $objp = $this->db->fetch_object($result);
133 $datec = $this->db->jdate($objp->datec);
134 $datem = $this->db->jdate($objp->tms);
135
136 $contactstatic->id = $objp->id;
137 $contactstatic->lastname = $objp->lastname;
138 $contactstatic->firstname = $objp->firstname;
139 $contactstatic->civility_id = $objp->civility_id;
140 $contactstatic->statut = $objp->status;
141 $contactstatic->phone_pro = $objp->phone;
142 $contactstatic->phone_perso = $objp->phone_perso;
143 $contactstatic->phone_mobile = $objp->phone_mobile;
144 $contactstatic->email = $objp->spemail;
145 $contactstatic->address = $objp->address;
146 $contactstatic->zip = $objp->zip;
147 $contactstatic->town = $objp->town;
148 $contactstatic->country = $objp->country;
149 $contactstatic->country_code = $objp->country_code;
150
151 $societestatic->id = $objp->socid;
152 $societestatic->name = $objp->name;
153 //$societestatic->name_alias = $objp->name_alias;
154 $societestatic->code_client = $objp->code_client;
155 $societestatic->code_compta = $objp->code_compta_client;
156 $societestatic->code_compta_client = $objp->code_compta_client;
157 $societestatic->client = $objp->client;
158 $societestatic->code_fournisseur = $objp->code_fournisseur;
159 $societestatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
160 $societestatic->fournisseur = $objp->fournisseur;
161 $societestatic->logo = $objp->logo;
162 $societestatic->email = $objp->email;
163 $societestatic->entity = $objp->entity;
164
165 $this->info_box_contents[$line][] = array(
166 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
167 'text' => $contactstatic->getNomUrl(1),
168 'asis' => 1,
169 );
170
171 $this->info_box_contents[$line][] = array(
172 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
173 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
174 'asis' => 1,
175 );
176
177 $this->info_box_contents[$line][] = array(
178 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
179 'text' => dol_print_date($datem, "day", 'tzuserrel'),
180 );
181
182 $this->info_box_contents[$line][] = array(
183 'td' => 'class="nowrap right" width="18"',
184 'text' => $contactstatic->getLibStatut(3),
185 'asis' => 1,
186 );
187
188 $line++;
189 }
190
191 // if ($num == 0) {
192 // $this->info_box_contents[$line][0] = array(
193 // 'td' => 'class="center"',
194 // 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedContacts").'</span>',
195 // 'asis' => 1
196 // );
197 // }
198
199 $this->db->free($result);
200 } else {
201 $this->info_box_contents[0][0] = array(
202 'td' => '',
203 'maxlength' => 500,
204 'text' => ($this->db->error().' sql='.$sql),
205 );
206 }
207 } else {
208 $this->info_box_contents[0][0] = array(
209 'td' => 'class="nohover left"',
210 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
211 );
212 }
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.
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 a 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79