dolibarr 18.0.6
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
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)) {
65 $this->enabled = 0; // disabled by this option
66 }
67
68 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
69 }
70
77 public function loadBox($max = 5)
78 {
79 global $user, $langs, $hookmanager;
80 $langs->load("boxes");
81
82 $this->max = $max;
83
84 include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
85 $thirdpartystatic = new Client($this->db);
86
87 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers", $max));
88
89 if ($user->hasRight('societe', 'lire')) {
90 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .= ", s.code_client, s.code_compta, s.client";
92 $sql .= ", s.logo, s.email, s.entity";
93 $sql .= ", s.datec, s.tms, s.status";
94 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
95 if (empty($user->rights->societe->client->voir) && !$user->socid) {
96 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97 }
98 $sql .= " WHERE s.client IN (1, 3)";
99 $sql .= " AND s.entity IN (".getEntity('societe').")";
100 if (empty($user->rights->societe->client->voir) && !$user->socid) {
101 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
102 }
103 // Add where from hooks
104 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
105 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
106 if (empty($reshook)) {
107 if ($user->socid > 0) {
108 $sql .= " AND s.rowid = ".((int) $user->socid);
109 }
110 }
111 $sql .= $hookmanager->resPrint;
112 $sql .= " ORDER BY s.tms DESC";
113 $sql .= $this->db->plimit($max, 0);
114
115 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
116 $result = $this->db->query($sql);
117 if ($result) {
118 $num = $this->db->num_rows($result);
119
120 $line = 0;
121 while ($line < $num) {
122 $objp = $this->db->fetch_object($result);
123 $datec = $this->db->jdate($objp->datec);
124 $datem = $this->db->jdate($objp->tms);
125
126 $thirdpartystatic->id = $objp->socid;
127 $thirdpartystatic->name = $objp->name;
128 $thirdpartystatic->name_alias = $objp->name_alias;
129 $thirdpartystatic->code_client = $objp->code_client;
130 $thirdpartystatic->code_compta = $objp->code_compta;
131 $thirdpartystatic->client = $objp->client;
132 $thirdpartystatic->logo = $objp->logo;
133 $thirdpartystatic->email = $objp->email;
134 $thirdpartystatic->entity = $objp->entity;
135
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="tdoverflowmax150"',
138 'text' => $thirdpartystatic->getNomUrl(1),
139 'asis' => 1,
140 );
141
142 $this->info_box_contents[$line][] = array(
143 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
144 'text' => dol_print_date($datem, "day", 'tzuserrel')
145 );
146
147 $this->info_box_contents[$line][] = array(
148 'td' => 'class="right" width="18"',
149 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
150 );
151
152 $line++;
153 }
154
155 if ($num == 0) {
156 $this->info_box_contents[$line][0] = array(
157 'td' => 'class="center opacitymedium"',
158 'text'=>$langs->trans("NoRecordedCustomers")
159 );
160 }
161
162 $this->db->free($result);
163 } else {
164 $this->info_box_contents[0][0] = array(
165 'td' => '',
166 'maxlength'=>500,
167 'text' => ($this->db->error().' sql='.$sql)
168 );
169 }
170 } else {
171 $this->info_box_contents[0][0] = array(
172 'td' => 'class="nohover opacitymedium left"',
173 'text' => $langs->trans("ReadPermissionNotAllowed")
174 );
175 }
176 }
177
186 public function showBox($head = null, $contents = null, $nooutput = 0)
187 {
188 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
189 }
190}
Class to manage customers or prospects.
Class ModeleBoxes.
Class to manage the box to show last thirdparties.
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...