dolibarr 21.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-2019 Frederic France <frederic.france@netlogic.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
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 = '')
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";
91 $sql .= ", s.datec, s.tms, s.status";
92 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
95 }
96 $sql .= " WHERE s.client IN (2, 3)";
97 $sql .= " AND s.entity IN (".getEntity('societe').")";
98 if (!$user->hasRight('societe', 'client', 'voir')) {
99 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
100 }
101 // Add where from hooks
102 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
103 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
104 if (empty($reshook)) {
105 if ($user->socid > 0) {
106 $sql .= " AND s.rowid = ".((int) $user->socid);
107 }
108 }
109 $sql .= $hookmanager->resPrint;
110 $sql .= " ORDER BY s.tms DESC";
111 $sql .= $this->db->plimit($max, 0);
112
113 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
114 $resql = $this->db->query($sql);
115 if ($resql) {
116 $num = $this->db->num_rows($resql);
117
118 $line = 0;
119 while ($line < $num) {
120 $objp = $this->db->fetch_object($resql);
121 $datec = $this->db->jdate($objp->datec);
122 $datem = $this->db->jdate($objp->tms);
123
124 $thirdpartystatic->id = $objp->socid;
125 $thirdpartystatic->name = $objp->name;
126 $thirdpartystatic->name_alias = $objp->name_alias;
127 $thirdpartystatic->code_client = $objp->code_client;
128 $thirdpartystatic->code_compta = $objp->code_compta;
129 $thirdpartystatic->code_compta_client = $objp->code_compta;
130 $thirdpartystatic->client = $objp->client;
131 $thirdpartystatic->logo = $objp->logo;
132 $thirdpartystatic->email = $objp->email;
133 $thirdpartystatic->entity = $objp->entity;
134
135 $this->info_box_contents[$line][] = array(
136 'td' => 'class="tdoverflowmax150"',
137 'text' => $thirdpartystatic->getNomUrl(1),
138 'asis' => 1,
139 );
140
141 $this->info_box_contents[$line][] = array(
142 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
143 'text' => dol_print_date($datem, "day", 'tzuserrel'),
144 );
145
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="right" width="18"',
148 'text' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3)),
149 );
150
151 $this->info_box_contents[$line][] = array(
152 'td' => 'class="right" width="18"',
153 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
154 );
155
156 $line++;
157 }
158
159 $this->db->free($resql);
160 } else {
161 $this->info_box_contents[0][0] = array(
162 'td' => '',
163 'maxlength' => 500,
164 'text' => ($this->db->error().' sql='.$sql),
165 );
166 }
167 } else {
168 $this->info_box_contents[0][0] = array(
169 'td' => 'class="nohover left"',
170 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
171 );
172 }
173 }
174
175
176
185 public function showBox($head = null, $contents = null, $nooutput = 0)
186 {
187 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
188 }
189}
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79