dolibarr  13.0.2
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@inodbox.com>
5  * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.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 <https://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  public $boxcode = "lastcustomers";
36  public $boximg = "object_company";
37  public $boxlabel = "BoxLastCustomers";
38  public $depends = array("societe");
39 
43  public $db;
44 
45  public $enabled = 1;
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  public function __construct($db, $param = '')
58  {
59  global $conf, $user;
60 
61  $this->db = $db;
62 
63  // disable box for such cases
64  if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled = 0; // disabled by this option
65 
66  $this->hidden = !($user->rights->societe->lire && empty($user->socid));
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  include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
83  $thirdpartystatic = new Client($this->db);
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers", $max));
86 
87  if ($user->rights->societe->lire)
88  {
89  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
90  $sql .= ", s.code_client, s.code_compta, s.client";
91  $sql .= ", s.logo, s.email, s.entity";
92  $sql .= ", s.datec, s.tms, s.status";
93  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
94  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
95  $sql .= " WHERE s.client IN (1, 3)";
96  $sql .= " AND s.entity IN (".getEntity('societe').")";
97  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
98  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
99  $sql .= " ORDER BY s.tms DESC";
100  $sql .= $this->db->plimit($max, 0);
101 
102  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
103  $result = $this->db->query($sql);
104  if ($result)
105  {
106  $num = $this->db->num_rows($result);
107 
108  $line = 0;
109  while ($line < $num)
110  {
111  $objp = $this->db->fetch_object($result);
112  $datec = $this->db->jdate($objp->datec);
113  $datem = $this->db->jdate($objp->tms);
114 
115  $thirdpartystatic->id = $objp->socid;
116  $thirdpartystatic->name = $objp->name;
117  $thirdpartystatic->name_alias = $objp->name_alias;
118  $thirdpartystatic->code_client = $objp->code_client;
119  $thirdpartystatic->code_compta = $objp->code_compta;
120  $thirdpartystatic->client = $objp->client;
121  $thirdpartystatic->logo = $objp->logo;
122  $thirdpartystatic->email = $objp->email;
123  $thirdpartystatic->entity = $objp->entity;
124 
125  $this->info_box_contents[$line][] = array(
126  'td' => '',
127  'text' => $thirdpartystatic->getNomUrl(1),
128  'asis' => 1,
129  );
130 
131  $this->info_box_contents[$line][] = array(
132  'td' => 'class="right"',
133  'text' => dol_print_date($datem, "day")
134  );
135 
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="right" width="18"',
138  'text' => $thirdpartystatic->LibStatut($objp->status, 3)
139  );
140 
141  $line++;
142  }
143 
144  if ($num == 0) $this->info_box_contents[$line][0] = array(
145  'td' => 'class="center opacitymedium"',
146  'text'=>$langs->trans("NoRecordedCustomers")
147  );
148 
149  $this->db->free($result);
150  } else {
151  $this->info_box_contents[0][0] = array(
152  'td' => '',
153  'maxlength'=>500,
154  'text' => ($this->db->error().' sql='.$sql)
155  );
156  }
157  } else {
158  $this->info_box_contents[0][0] = array(
159  'td' => 'class="nohover opacitymedium left"',
160  'text' => $langs->trans("ReadPermissionNotAllowed")
161  );
162  }
163  }
164 
173  public function showBox($head = null, $contents = null, $nooutput = 0)
174  {
175  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
176  }
177 }
__construct($db, $param= '')
Constructor.
Definition: box_clients.php:57
Class to manage customers or prospects.
loadBox($max=5)
Load data for box to show them later.
Definition: box_clients.php:75
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_print_date($time, $format= '', $tzoutput= 'auto', $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