dolibarr 24.0.0-beta
box_prospect.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 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
29include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
30include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
31
32
37{
38 public $boxcode = "lastprospects";
39 public $boximg = "object_company";
40 public $boxlabel = "BoxLastProspects";
41 public $depends = array("societe");
42
43 public $enabled = 1;
44
51 public function __construct($db, $param = '') // @phpstan-ignore constructor.unusedParameter
52 {
53 global $conf, $user;
54
55 $this->db = $db;
56
57 // disable box for such cases
58 if (getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
59 $this->enabled = 0; // disabled by this option
60 }
61
62 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
63
64 $this->urltoaddentry = DOL_URL_ROOT.'/societe/card.php?action=create&type=p';
65 $this->msgNoRecords = 'NoRecordedProspects';
66 }
67
74 public function loadBox($max = 5)
75 {
76 global $user, $langs, $hookmanager;
77
78 $this->max = $max;
79
80 $thirdpartystatic = new Client($this->db);
81
82 $this->info_box_head = array(
83 'text' => $langs->trans("BoxTitleLastModifiedProspects", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/societe/list.php?type=p&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, s.client";
89 $sql .= ", s.logo, s.email, s.entity";
90 $sql .= ", s.fk_stcomm, st.libelle as stcomm_label, st.picto as stcomm_picto";
91 $sql .= ", s.datec, s.tms, s.status";
92 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcomm as st ON s.fk_stcomm = st.id";
94 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
95 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
96 }
97 $sql .= " WHERE s.client IN (2, 3)";
98 $sql .= " AND s.entity IN (".getEntity('societe').")";
99 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
100 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
101 }
102 // Add where from hooks
103 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
104 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
105 if (empty($reshook)) {
106 if ($user->socid > 0) {
107 $sql .= " AND s.rowid = ".((int) $user->socid);
108 }
109 }
110 $sql .= $hookmanager->resPrint;
111 $sql .= " ORDER BY s.tms DESC";
112 $sql .= $this->db->plimit($max, 0);
113
114 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
115 $resql = $this->db->query($sql);
116 if ($resql) {
117 $num = $this->db->num_rows($resql);
118
119 $line = 0;
120 while ($line < $num) {
121 $objp = $this->db->fetch_object($resql);
122 $datec = $this->db->jdate($objp->datec);
123 $datem = $this->db->jdate($objp->tms);
124
125 $thirdpartystatic->id = $objp->socid;
126 $thirdpartystatic->name = $objp->name;
127 $thirdpartystatic->name_alias = $objp->name_alias;
128 $thirdpartystatic->code_client = $objp->code_client;
129 $thirdpartystatic->code_compta = $objp->code_compta;
130 $thirdpartystatic->code_compta_client = $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' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3, $objp->stcomm_label, $objp->stcomm_picto)),
150 );
151
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="right" width="18"',
154 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
155 );
156
157 $line++;
158 }
159
160 $this->db->free($resql);
161 } else {
162 $this->info_box_contents[0][0] = array(
163 'td' => '',
164 'maxlength' => 500,
165 'text' => ($this->db->error().' sql='.$sql),
166 );
167 }
168 } else {
169 $this->info_box_contents[0][0] = array(
170 'td' => 'class="nohover left"',
171 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
172 );
173 }
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 prospects.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
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...