dolibarr 20.0.0
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
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
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 $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(
79 'text' => $langs->trans("BoxTitleLastModifiedCustomers", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/societe/list.php?type=c&sortfield=s.tms&sortorder=DESC"><span class="badge">...</span></a>',
80 );
81
82 if ($user->hasRight('societe', 'lire')) {
83 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
84 $sql .= ", s.code_client, s.code_compta, s.client";
85 $sql .= ", s.logo, s.email, s.entity";
86 $sql .= ", s.datec, s.tms, s.status";
87 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
88 if (!$user->hasRight('societe', 'client', 'voir')) {
89 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
90 }
91 $sql .= " WHERE s.client IN (1, 3)";
92 $sql .= " AND s.entity IN (".getEntity('societe').")";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95 }
96 // Add where from hooks
97 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
98 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
99 if (empty($reshook)) {
100 if ($user->socid > 0) {
101 $sql .= " AND s.rowid = ".((int) $user->socid);
102 }
103 }
104 $sql .= $hookmanager->resPrint;
105 $sql .= " ORDER BY s.tms DESC";
106 $sql .= $this->db->plimit($max, 0);
107
108 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
109 $result = $this->db->query($sql);
110 if ($result) {
111 $num = $this->db->num_rows($result);
112
113 $line = 0;
114 while ($line < $num) {
115 $objp = $this->db->fetch_object($result);
116 $datec = $this->db->jdate($objp->datec);
117 $datem = $this->db->jdate($objp->tms);
118
119 $thirdpartystatic->id = $objp->socid;
120 $thirdpartystatic->name = $objp->name;
121 $thirdpartystatic->name_alias = $objp->name_alias;
122 $thirdpartystatic->code_client = $objp->code_client;
123 $thirdpartystatic->code_compta = $objp->code_compta;
124 $thirdpartystatic->client = $objp->client;
125 $thirdpartystatic->logo = $objp->logo;
126 $thirdpartystatic->email = $objp->email;
127 $thirdpartystatic->entity = $objp->entity;
128
129 $this->info_box_contents[$line][] = array(
130 'td' => 'class="tdoverflowmax150"',
131 'text' => $thirdpartystatic->getNomUrl(1),
132 'asis' => 1,
133 );
134
135 $this->info_box_contents[$line][] = array(
136 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
137 'text' => dol_print_date($datem, "day", 'tzuserrel')
138 );
139
140 $this->info_box_contents[$line][] = array(
141 'td' => 'class="right" width="18"',
142 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
143 );
144
145 $line++;
146 }
147
148 if ($num == 0) {
149 $this->info_box_contents[$line][0] = array(
150 'td' => 'class="center"',
151 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedCustomers").'</span>'
152 );
153 }
154
155 $this->db->free($result);
156 } else {
157 $this->info_box_contents[0][0] = array(
158 'td' => '',
159 'maxlength'=>500,
160 'text' => ($this->db->error().' sql='.$sql)
161 );
162 }
163 } else {
164 $this->info_box_contents[0][0] = array(
165 'td' => 'class="nohover left"',
166 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
167 );
168 }
169 }
170
179 public function showBox($head = null, $contents = null, $nooutput = 0)
180 {
181 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
182 }
183}
Class to manage customers or prospects.
Class ModeleBoxes.
Class to manage the box to show last customers.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param='')
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
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...