dolibarr 18.0.6
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
45 public $db;
46
47 public $enabled = 1;
48
49 public $info_box_head = array();
50 public $info_box_contents = array();
51
52
59 public function __construct($db, $param = '')
60 {
61 global $conf, $user;
62
63 $this->db = $db;
64
65 // disable box for such cases
66 if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
67 $this->enabled = 0; // disabled by this option
68 }
69
70 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
71 }
72
79 public function loadBox($max = 5)
80 {
81 global $user, $langs, $hookmanager;
82
83 $this->max = $max;
84
85 $thirdpartystatic = new Client($this->db);
86
87 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedProspects", $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.fk_stcomm";
94 $sql .= ", s.datec, s.tms, s.status";
95 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
96 if (empty($user->rights->societe->client->voir) && !$user->socid) {
97 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98 }
99 $sql .= " WHERE s.client IN (2, 3)";
100 $sql .= " AND s.entity IN (".getEntity('societe').")";
101 if (empty($user->rights->societe->client->voir) && !$user->socid) {
102 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
103 }
104 // Add where from hooks
105 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
106 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
107 if (empty($reshook)) {
108 if ($user->socid > 0) {
109 $sql .= " AND s.rowid = ".((int) $user->socid);
110 }
111 }
112 $sql .= $hookmanager->resPrint;
113 $sql .= " ORDER BY s.tms DESC";
114 $sql .= $this->db->plimit($max, 0);
115
116 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
117 $resql = $this->db->query($sql);
118 if ($resql) {
119 $num = $this->db->num_rows($resql);
120
121 $line = 0;
122 while ($line < $num) {
123 $objp = $this->db->fetch_object($resql);
124 $datec = $this->db->jdate($objp->datec);
125 $datem = $this->db->jdate($objp->tms);
126
127 $thirdpartystatic->id = $objp->socid;
128 $thirdpartystatic->name = $objp->name;
129 $thirdpartystatic->name_alias = $objp->name_alias;
130 $thirdpartystatic->code_client = $objp->code_client;
131 $thirdpartystatic->code_compta = $objp->code_compta;
132 $thirdpartystatic->client = $objp->client;
133 $thirdpartystatic->logo = $objp->logo;
134 $thirdpartystatic->email = $objp->email;
135 $thirdpartystatic->entity = $objp->entity;
136
137 $this->info_box_contents[$line][] = array(
138 'td' => 'class="tdoverflowmax150"',
139 'text' => $thirdpartystatic->getNomUrl(1),
140 'asis' => 1,
141 );
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
145 'text' => dol_print_date($datem, "day", 'tzuserrel'),
146 );
147
148 $this->info_box_contents[$line][] = array(
149 'td' => 'class="right" width="18"',
150 'text' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3)),
151 );
152
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="right" width="18"',
155 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
156 );
157
158 $line++;
159 }
160
161 if ($num == 0) {
162 $this->info_box_contents[$line][0] = array(
163 'td' => 'class="center opacitymedium"',
164 'text'=> $langs->trans("NoRecordedProspects"),
165 );
166 }
167
168 $this->db->free($resql);
169 } else {
170 $this->info_box_contents[0][0] = array(
171 'td' => '',
172 'maxlength' => 500,
173 'text' => ($this->db->error().' sql='.$sql),
174 );
175 }
176 } else {
177 $this->info_box_contents[0][0] = array(
178 'td' => 'class="nohover opacitymedium left"',
179 'text' => $langs->trans("ReadPermissionNotAllowed")
180 );
181 }
182 }
183
192 public function showBox($head = null, $contents = null, $nooutput = 0)
193 {
194 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
195 }
196}
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='', $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...