dolibarr  20.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@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 
40  public $enabled = 1;
41 
48  public function __construct($db, $param = '')
49  {
50  global $conf, $user;
51 
52  $this->db = $db;
53 
54  // disable box for such cases
55  if (getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
56  $this->enabled = 0; // disabled by this option
57  }
58 
59  $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
60  }
61 
68  public function loadBox($max = 5)
69  {
70  global $user, $langs, $hookmanager;
71  $langs->load("boxes");
72 
73  $this->max = $max;
74 
75  include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
76  $thirdpartystatic = new Client($this->db);
77 
78  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers", $max));
79 
80  if ($user->hasRight('societe', 'lire')) {
81  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
82  $sql .= ", s.code_client, s.code_compta, s.client";
83  $sql .= ", s.logo, s.email, s.entity";
84  $sql .= ", s.datec, s.tms, s.status";
85  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
86  if (!$user->hasRight('societe', 'client', 'voir')) {
87  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
88  }
89  $sql .= " WHERE s.client IN (1, 3)";
90  $sql .= " AND s.entity IN (".getEntity('societe').")";
91  if (!$user->hasRight('societe', 'client', 'voir')) {
92  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
93  }
94  // Add where from hooks
95  $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
96  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
97  if (empty($reshook)) {
98  if ($user->socid > 0) {
99  $sql .= " AND s.rowid = ".((int) $user->socid);
100  }
101  }
102  $sql .= $hookmanager->resPrint;
103  $sql .= " ORDER BY s.tms DESC";
104  $sql .= $this->db->plimit($max, 0);
105 
106  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
107  $result = $this->db->query($sql);
108  if ($result) {
109  $num = $this->db->num_rows($result);
110 
111  $line = 0;
112  while ($line < $num) {
113  $objp = $this->db->fetch_object($result);
114  $datec = $this->db->jdate($objp->datec);
115  $datem = $this->db->jdate($objp->tms);
116 
117  $thirdpartystatic->id = $objp->socid;
118  $thirdpartystatic->name = $objp->name;
119  $thirdpartystatic->name_alias = $objp->name_alias;
120  $thirdpartystatic->code_client = $objp->code_client;
121  $thirdpartystatic->code_compta = $objp->code_compta;
122  $thirdpartystatic->client = $objp->client;
123  $thirdpartystatic->logo = $objp->logo;
124  $thirdpartystatic->email = $objp->email;
125  $thirdpartystatic->entity = $objp->entity;
126 
127  $this->info_box_contents[$line][] = array(
128  'td' => 'class="tdoverflowmax150"',
129  'text' => $thirdpartystatic->getNomUrl(1),
130  'asis' => 1,
131  );
132 
133  $this->info_box_contents[$line][] = array(
134  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
135  'text' => dol_print_date($datem, "day", 'tzuserrel')
136  );
137 
138  $this->info_box_contents[$line][] = array(
139  'td' => 'class="right" width="18"',
140  'text' => $thirdpartystatic->LibStatut($objp->status, 3)
141  );
142 
143  $line++;
144  }
145 
146  if ($num == 0) {
147  $this->info_box_contents[$line][0] = array(
148  'td' => 'class="center"',
149  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedCustomers").'</span>'
150  );
151  }
152 
153  $this->db->free($result);
154  } else {
155  $this->info_box_contents[0][0] = array(
156  'td' => '',
157  'maxlength'=>500,
158  'text' => ($this->db->error().' sql='.$sql)
159  );
160  }
161  } else {
162  $this->info_box_contents[0][0] = array(
163  'td' => 'class="nohover left"',
164  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
165  );
166  }
167  }
168 
177  public function showBox($head = null, $contents = null, $nooutput = 0)
178  {
179  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
180  }
181 }
Class to manage customers or prospects.
Class ModeleBoxes.
Class to manage the box to show last customers.
Definition: box_clients.php:34
loadBox($max=5)
Load data for box to show them later.
Definition: box_clients.php:68
__construct($db, $param='')
Constructor.
Definition: box_clients.php:48
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...