dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "lastcustomers";
37 public $boximg = "object_company";
38 public $boxlabel = "BoxLastCustomers";
39 public $depends = array("societe");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param = '')
50 {
51 global $user;
52
53 $this->db = $db;
54
55 // disable box for such cases
56 if (getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
57 $this->enabled = 0; // disabled by this option
58 }
59
60 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
61
62 $this->urltoaddentry = DOL_URL_ROOT.'/societe/card.php?action=create&type=c';
63 $this->msgNoRecords = 'NoRecordedCustomers';
64 }
65
72 public function loadBox($max = 5)
73 {
74 global $user, $langs, $hookmanager;
75 $langs->load("boxes");
76
77 $this->max = $max;
78
79 include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
80 $thirdpartystatic = new Client($this->db);
81
82 $this->info_box_head = array(
83 '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>',
84 );
85
86 if ($user->hasRight('societe', 'lire')) {
87 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
88 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
89 $sql .= ", s.logo, s.email, s.entity";
90 $sql .= ", s.datec, s.tms, s.status";
91 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
92 if (!$user->hasRight('societe', 'client', 'voir')) {
93 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94 }
95 $sql .= " WHERE s.client IN (1, 3)";
96 $sql .= " AND s.entity IN (".getEntity('societe').")";
97 if (!$user->hasRight('societe', 'client', 'voir')) {
98 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
99 }
100 // Add where from hooks
101 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
102 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
103 if (empty($reshook)) {
104 if ($user->socid > 0) {
105 $sql .= " AND s.rowid = ".((int) $user->socid);
106 }
107 }
108 $sql .= $hookmanager->resPrint;
109 $sql .= " ORDER BY s.tms DESC";
110 $sql .= $this->db->plimit($max, 0);
111
112 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
113 $result = $this->db->query($sql);
114 if ($result) {
115 $num = $this->db->num_rows($result);
116
117 $line = 0;
118 while ($line < $num) {
119 $objp = $this->db->fetch_object($result);
120 $datec = $this->db->jdate($objp->datec);
121 $datem = $this->db->jdate($objp->tms);
122
123 $thirdpartystatic->id = $objp->socid;
124 $thirdpartystatic->name = $objp->name;
125 $thirdpartystatic->name_alias = $objp->name_alias;
126 $thirdpartystatic->code_client = $objp->code_client;
127 $thirdpartystatic->code_compta = $objp->code_compta_client;
128 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
129 $thirdpartystatic->client = $objp->client;
130 $thirdpartystatic->logo = $objp->logo;
131 $thirdpartystatic->email = $objp->email;
132 $thirdpartystatic->entity = $objp->entity;
133
134 $this->info_box_contents[$line][] = array(
135 'td' => 'class="tdoverflowmax150"',
136 'text' => $thirdpartystatic->getNomUrl(1),
137 'asis' => 1,
138 );
139
140 $this->info_box_contents[$line][] = array(
141 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
142 'text' => dol_print_date($datem, "day", 'tzuserrel')
143 );
144
145 $this->info_box_contents[$line][] = array(
146 'td' => 'class="right" width="18"',
147 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
148 );
149
150 $line++;
151 }
152
153
154 $this->db->free($result);
155 } else {
156 $this->info_box_contents[0][0] = array(
157 'td' => '',
158 'maxlength' => 500,
159 'text' => ($this->db->error().' sql='.$sql)
160 );
161 }
162 } else {
163 $this->info_box_contents[0][0] = array(
164 'td' => 'class="nohover left"',
165 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
166 );
167 }
168 }
169
170
171
180 public function showBox($head = null, $contents = null, $nooutput = 0)
181 {
182 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
183 }
184}
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 a 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...