dolibarr  9.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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 
31 
36 {
37  var $boxcode="lastcontacts";
38  var $boximg="object_contact";
39  var $boxlabel="BoxLastContacts";
40  var $depends = array("societe");
41 
45  public $db;
46 
47  var $param;
48 
49  var $info_box_head = array();
50  var $info_box_contents = array();
51 
52 
59  function __construct($db,$param)
60  {
61  global $user;
62 
63  $this->db=$db;
64 
65  $this->hidden=! ($user->rights->societe->lire && $user->rights->societe->contact->lire);
66  }
67 
74  function loadBox($max=5)
75  {
76  global $user, $langs, $db, $conf;
77  $langs->load("boxes");
78 
79  $this->max=$max;
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedContacts",$max));
82 
83  if ($user->rights->societe->lire && $user->rights->societe->contact->lire)
84  {
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  $sql.= ", sp.address, sp.zip, sp.town, sp.phone, sp.phone_perso, sp.phone_mobile";
87  $sql.= ", s.nom as socname, s.name_alias";
88  $sql.= ", s.client, s.fournisseur, s.code_client, s.code_fournisseur";
89  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
90  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid";
91  if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
92  $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")";
93  if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND sp.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
94  if ($user->societe_id) $sql.= " AND sp.fk_soc = ".$user->societe_id;
95  $sql.= " ORDER BY sp.tms DESC";
96  $sql.= $db->plimit($max, 0);
97 
98  $result = $db->query($sql);
99  if ($result) {
100  $num = $db->num_rows($result);
101 
102  $contactstatic=new Contact($db);
103  $societestatic=new Societe($db);
104 
105  $line = 0;
106  while ($line < $num)
107  {
108  $objp = $db->fetch_object($result);
109  $datec=$db->jdate($objp->datec);
110  $datem=$db->jdate($objp->tms);
111 
112  $contactstatic->id=$objp->id;
113  $contactstatic->lastname=$objp->lastname;
114  $contactstatic->firstname=$objp->firstname;
115  $contactstatic->civility_id=$objp->civility_id;
116  $contactstatic->statut=$objp->status;
117  $contactstatic->phone_pro = $objp->phone;
118  $contactstatic->phone_perso = $objp->phone_perso;
119  $contactstatic->phone_mobile = $objp->phone_mobile;
120  $contactstatic->address = $objp->address;
121  $contactstatic->zip = $objp->zip;
122  $contactstatic->town = $objp->town;
123 
124  $societestatic->id = $objp->fk_soc;
125  $societestatic->name = $objp->socname;
126  $societestatic->name_alias = $objp->name_alias;
127  $societestatic->code_client = $objp->code_client;
128  $societestatic->code_fournisseur = $objp->code_fournisseur;
129  $societestatic->client = $objp->client;
130  $societestatic->fournisseur = $objp->fournisseur;
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => '',
134  'text' => $contactstatic->getNomUrl(1),
135  'asis' => 1,
136  );
137 
138  $this->info_box_contents[$line][] = array(
139  'td' => '',
140  'text' => ($objp->fk_soc > 0 ? $societestatic->getNomUrl(1) : ''),
141  'asis' => 1,
142  );
143 
144  $this->info_box_contents[$line][] = array(
145  'td' => 'class="right"',
146  'text' => dol_print_date($datem, "day"),
147  );
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'align="right" class="nowrap" width="18"',
151  'text' => $contactstatic->getLibStatut(3),
152  'asis'=>1,
153  );
154 
155  $line++;
156  }
157 
158  if ($num==0)
159  $this->info_box_contents[$line][0] = array(
160  'td' => 'align="center"',
161  'text'=>$langs->trans("NoRecordedContacts"),
162  );
163 
164  $db->free($result);
165  } else {
166  $this->info_box_contents[0][0] = array(
167  'td' => '',
168  'maxlength'=>500,
169  'text' => ($db->error().' sql='.$sql),
170  );
171  }
172  } else {
173  $this->info_box_contents[0][0] = array(
174  'td' => 'align="left" class="nohover opacitymedium"',
175  'text' => $langs->trans("ReadPermissionNotAllowed")
176  );
177  }
178  }
179 
188  function showBox($head = null, $contents = null, $nooutput=0)
189  {
190  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
191  }
192 }
193 
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage contact/addresses.
__construct($db, $param)
Constructor.
Class ModeleBoxes.
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='tzserver', $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.