dolibarr  13.0.2
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->rights->societe->lire && $user->rights->societe->contact->lire);
67  }
68 
75  public function loadBox($max = 5)
76  {
77  global $user, $langs, $conf;
78  $langs->load("boxes");
79 
80  $this->max = $max;
81 
82  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedContacts", $max));
83 
84  if ($user->rights->societe->lire && $user->rights->societe->contact->lire)
85  {
86  $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";
87 
88  $sql .= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile, sp.email as spemail";
89  $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
90  $sql .= ", s.code_client, s.code_compta, s.client";
91  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
92  $sql .= ", s.logo, s.email, s.entity";
93  $sql .= ", co.label as country, co.code as country_code";
94  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
95  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON sp.fk_pays = co.rowid";
96  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
97  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98  $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")";
99  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
100  if ($user->socid) $sql .= " AND sp.fk_soc = ".$user->socid;
101  $sql .= " ORDER BY sp.tms DESC";
102  $sql .= $this->db->plimit($max, 0);
103 
104  $result = $this->db->query($sql);
105  if ($result) {
106  $num = $this->db->num_rows($result);
107 
108  $contactstatic = new Contact($this->db);
109  $societestatic = new Societe($this->db);
110 
111  $line = 0;
112  while ($line < $num)
113  {
114  $objp = $this->db->fetch_object($result);
115  $datec = $this->db->jdate($objp->datec);
116  $datem = $this->db->jdate($objp->tms);
117 
118  $contactstatic->id = $objp->id;
119  $contactstatic->lastname = $objp->lastname;
120  $contactstatic->firstname = $objp->firstname;
121  $contactstatic->civility_id = $objp->civility_id;
122  $contactstatic->statut = $objp->status;
123  $contactstatic->phone_pro = $objp->phone;
124  $contactstatic->phone_perso = $objp->phone_perso;
125  $contactstatic->phone_mobile = $objp->phone_mobile;
126  $contactstatic->email = $objp->spemail;
127  $contactstatic->address = $objp->address;
128  $contactstatic->zip = $objp->zip;
129  $contactstatic->town = $objp->town;
130  $contactstatic->country = $objp->country;
131  $contactstatic->country_code = $objp->country_code;
132 
133  $societestatic->id = $objp->socid;
134  $societestatic->name = $objp->name;
135  //$societestatic->name_alias = $objp->name_alias;
136  $societestatic->code_client = $objp->code_client;
137  $societestatic->code_compta = $objp->code_compta;
138  $societestatic->client = $objp->client;
139  $societestatic->code_fournisseur = $objp->code_fournisseur;
140  $societestatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
141  $societestatic->fournisseur = $objp->fournisseur;
142  $societestatic->logo = $objp->logo;
143  $societestatic->email = $objp->email;
144  $societestatic->entity = $objp->entity;
145 
146  $this->info_box_contents[$line][] = array(
147  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
148  'text' => $contactstatic->getNomUrl(1),
149  'asis' => 1,
150  );
151 
152  $this->info_box_contents[$line][] = array(
153  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
154  'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
155  'asis' => 1,
156  );
157 
158  $this->info_box_contents[$line][] = array(
159  'td' => 'class="right"',
160  'text' => dol_print_date($datem, "day"),
161  );
162 
163  $this->info_box_contents[$line][] = array(
164  'td' => 'class="nowrap right" width="18"',
165  'text' => $contactstatic->getLibStatut(3),
166  'asis'=>1,
167  );
168 
169  $line++;
170  }
171 
172  if ($num == 0)
173  $this->info_box_contents[$line][0] = array(
174  'td' => 'class="center"',
175  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContacts").'</span>',
176  'asis'=> 1
177  );
178 
179  $this->db->free($result);
180  } else {
181  $this->info_box_contents[0][0] = array(
182  'td' => '',
183  'maxlength'=>500,
184  'text' => ($this->db->error().' sql='.$sql),
185  );
186  }
187  } else {
188  $this->info_box_contents[0][0] = array(
189  'td' => 'class="nohover left"',
190  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
191  );
192  }
193  }
194 
203  public function showBox($head = null, $contents = null, $nooutput = 0)
204  {
205  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
206  }
207 }
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage contact/addresses.
__construct($db, $param)
Constructor.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage third parties objects (customers, suppliers, prospects...)
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage the box to show last contacts.