dolibarr  7.0.0-beta
box_clients.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 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 
29 
33 class box_clients extends ModeleBoxes
34 {
35  var $boxcode="lastcustomers";
36  var $boximg="object_company";
37  var $boxlabel="BoxLastCustomers";
38  var $depends = array("societe");
39 
40  var $db;
41  var $enabled = 1;
42 
43  var $info_box_head = array();
44  var $info_box_contents = array();
45 
46 
53  function __construct($db,$param='')
54  {
55  global $conf, $user;
56 
57  $this->db = $db;
58 
59  // disable box for such cases
60  if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled=0; // disabled by this option
61 
62  $this->hidden = ! ($user->rights->societe->lire && empty($user->socid));
63  }
64 
71  function loadBox($max=5)
72  {
73  global $user, $langs, $db, $conf;
74  $langs->load("boxes");
75 
76  $this->max=$max;
77 
78  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
79  $thirdpartystatic=new Societe($db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers",$max));
82 
83  if ($user->rights->societe->lire)
84  {
85  $sql = "SELECT s.nom as name, s.rowid as socid";
86  $sql.= ", s.code_client";
87  $sql.= ", s.client";
88  $sql.= ", s.code_fournisseur";
89  $sql.= ", s.fournisseur";
90  $sql.= ", s.logo";
91  $sql.= ", s.datec, s.tms, s.status";
92  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
93  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94  $sql.= " WHERE s.client IN (1, 3)";
95  $sql.= " AND s.entity IN (".getEntity('societe').")";
96  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
97  if ($user->societe_id) $sql.= " AND s.rowid = $user->societe_id";
98  $sql.= " ORDER BY s.tms DESC";
99  $sql.= $db->plimit($max, 0);
100 
101  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
102  $result = $db->query($sql);
103  if ($result)
104  {
105  $num = $db->num_rows($result);
106 
107  $line = 0;
108  while ($line < $num)
109  {
110  $objp = $db->fetch_object($result);
111  $datec=$db->jdate($objp->datec);
112  $datem=$db->jdate($objp->tms);
113  $thirdpartystatic->id = $objp->socid;
114  $thirdpartystatic->name = $objp->name;
115  $thirdpartystatic->code_client = $objp->code_client;
116  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
117  $thirdpartystatic->client = $objp->client;
118  $thirdpartystatic->fournisseur = $objp->fournisseur;
119  $thirdpartystatic->logo = $objp->logo;
120 
121  $this->info_box_contents[$line][] = array(
122  'td' => '',
123  'text' => $thirdpartystatic->getNomUrl(1),
124  'asis' => 1,
125  );
126 
127  $this->info_box_contents[$line][] = array(
128  'td' => 'class="right"',
129  'text' => dol_print_date($datem, "day")
130  );
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => 'align="right" width="18"',
134  'text' => $thirdpartystatic->LibStatut($objp->status,3)
135  );
136 
137  $line++;
138  }
139 
140  if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedCustomers"));
141 
142  $db->free($result);
143  }
144  else {
145  $this->info_box_contents[0][0] = array( 'td' => '',
146  'maxlength'=>500,
147  'text' => ($db->error().' sql='.$sql));
148  }
149  }
150  else {
151  $this->info_box_contents[0][0] = array(
152  'td' => 'align="left" class="nohover opacitymedium"',
153  'text' => $langs->trans("ReadPermissionNotAllowed")
154  );
155  }
156 
157  }
158 
167  function showBox($head = null, $contents = null, $nooutput=0)
168  {
169  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
170  }
171 
172 }
173 
loadBox($max=5)
Load data for box to show them later.
Definition: box_clients.php:71
Class ModeleBoxes.
__construct($db, $param='')
Constructor.
Definition: box_clients.php:53
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage the box to show last thirdparties.
Definition: box_clients.php:33