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