dolibarr 20.0.0
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 *
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
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
30
31
36{
37 public $boxcode = "lastprospects";
38 public $boximg = "object_company";
39 public $boxlabel = "BoxLastProspects";
40 public $depends = array("societe");
41
42 public $enabled = 1;
43
50 public function __construct($db, $param = '')
51 {
52 global $conf, $user;
53
54 $this->db = $db;
55
56 // disable box for such cases
57 if (getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
58 $this->enabled = 0; // disabled by this option
59 }
60
61 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $user, $langs, $hookmanager;
73
74 $this->max = $max;
75
76 $thirdpartystatic = new Client($this->db);
77
78 $this->info_box_head = array(
79 '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>',
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.fk_stcomm";
87 $sql .= ", s.datec, s.tms, s.status";
88 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
89 if (!$user->hasRight('societe', 'client', 'voir')) {
90 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91 }
92 $sql .= " WHERE s.client IN (2, 3)";
93 $sql .= " AND s.entity IN (".getEntity('societe').")";
94 if (!$user->hasRight('societe', 'client', 'voir')) {
95 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
96 }
97 // Add where from hooks
98 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
99 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
100 if (empty($reshook)) {
101 if ($user->socid > 0) {
102 $sql .= " AND s.rowid = ".((int) $user->socid);
103 }
104 }
105 $sql .= $hookmanager->resPrint;
106 $sql .= " ORDER BY s.tms DESC";
107 $sql .= $this->db->plimit($max, 0);
108
109 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
110 $resql = $this->db->query($sql);
111 if ($resql) {
112 $num = $this->db->num_rows($resql);
113
114 $line = 0;
115 while ($line < $num) {
116 $objp = $this->db->fetch_object($resql);
117 $datec = $this->db->jdate($objp->datec);
118 $datem = $this->db->jdate($objp->tms);
119
120 $thirdpartystatic->id = $objp->socid;
121 $thirdpartystatic->name = $objp->name;
122 $thirdpartystatic->name_alias = $objp->name_alias;
123 $thirdpartystatic->code_client = $objp->code_client;
124 $thirdpartystatic->code_compta = $objp->code_compta;
125 $thirdpartystatic->client = $objp->client;
126 $thirdpartystatic->logo = $objp->logo;
127 $thirdpartystatic->email = $objp->email;
128 $thirdpartystatic->entity = $objp->entity;
129
130 $this->info_box_contents[$line][] = array(
131 'td' => 'class="tdoverflowmax150"',
132 'text' => $thirdpartystatic->getNomUrl(1),
133 'asis' => 1,
134 );
135
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
138 'text' => dol_print_date($datem, "day", 'tzuserrel'),
139 );
140
141 $this->info_box_contents[$line][] = array(
142 'td' => 'class="right" width="18"',
143 'text' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3)),
144 );
145
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="right" width="18"',
148 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
149 );
150
151 $line++;
152 }
153
154 if ($num == 0) {
155 $this->info_box_contents[$line][0] = array(
156 'td' => 'class="center"',
157 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedProspects").'</span>'
158 );
159 }
160
161 $this->db->free($resql);
162 } else {
163 $this->info_box_contents[0][0] = array(
164 'td' => '',
165 'maxlength' => 500,
166 'text' => ($this->db->error().' sql='.$sql),
167 );
168 }
169 } else {
170 $this->info_box_contents[0][0] = array(
171 'td' => 'class="nohover left"',
172 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
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 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...