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