dolibarr 19.0.3
box_actions_future.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-2011 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014 Charles-Fr BENKE <charles.fr@benke.fr>
6 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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
34{
35 public $boxcode = "futureactions";
36 public $boximg = "object_action";
37 public $boxlabel = "BoxTitleFutureActions";
38 public $depends = array("agenda");
39
43 public $db;
44
45 public $enabled = 1;
46
47 public $info_box_head = array();
48 public $info_box_contents = array();
49
50
57 public function __construct($db, $param)
58 {
59 global $user;
60
61 $this->db = $db;
62
63 $this->enabled = isModEnabled('agenda');
64
65 $this->hidden = !($user->hasRight('agenda', 'myactions', 'read'));
66 }
67
74 public function loadBox($max = 5)
75 {
76 global $user, $langs, $conf;
77
78 $this->max = $max;
79
80 $now = dol_now();
81
82 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
83 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
84 $societestatic = new Societe($this->db);
85 $actionstatic = new ActionComm($this->db);
86
87 $this->info_box_head = array('text' => $langs->trans("BoxTitleFutureActions", $max));
88
89 if ($user->hasRight('agenda', 'myactions', 'read')) {
90 $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
91 $sql .= ", ta.code";
92 $sql .= ", ta.libelle as type_label";
93 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
94 $sql .= ", s.code_client, s.code_compta, s.client";
95 $sql .= ", s.logo, s.email, s.entity";
96 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
97 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
98 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
99 }
100 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
101 $sql .= " WHERE a.fk_action = ta.id";
102 $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
103 //$sql .= " AND a.percent >= 0 AND a.percent < 100";
104 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
105 $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
106 }
107 if ($user->socid) {
108 $sql .= " AND s.rowid = ".((int) $user->socid);
109 }
110 if (!$user->hasRight('agenda', 'allactions', 'read')) {
111 $sql .= " AND (a.fk_user_author = ".((int) $user->id)." OR a.fk_user_action = ".((int) $user->id)." OR a.fk_user_done = ".((int) $user->id).")";
112 }
113 $sql .= " AND a.datep > '".$this->db->idate($now)."'";
114 $sql .= " ORDER BY a.datep ASC";
115 $sql .= $this->db->plimit($max, 0);
116
117 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
118 $result = $this->db->query($sql);
119 if ($result) {
120 $now = dol_now();
121 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
122
123 $num = $this->db->num_rows($result);
124
125 $line = 0;
126 while ($line < $num) {
127 $late = '';
128 $objp = $this->db->fetch_object($result);
129 $datelimite = $this->db->jdate($objp->dp);
130
131 $actionstatic->id = $objp->id;
132 $actionstatic->label = $objp->label;
133 $actionstatic->type_label = $objp->type_label;
134 $actionstatic->code = $objp->code;
135
136 $societestatic->id = $objp->socid;
137 $societestatic->name = $objp->name;
138 //$societestatic->name_alias = $objp->name_alias;
139 $societestatic->code_client = $objp->code_client;
140 $societestatic->code_compta = $objp->code_compta;
141 $societestatic->client = $objp->client;
142 $societestatic->logo = $objp->logo;
143 $societestatic->email = $objp->email;
144 $societestatic->entity = $objp->entity;
145
146 if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
147 $late = img_warning($langs->trans("Late"));
148 }
149
150 //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
151 //$label = empty($objp->label) ? $objp->type_label : $objp->label;
152
153 $this->info_box_contents[$line][0] = array(
154 'td' => 'class="tdoverflowmax200"',
155 'text' => $actionstatic->getNomUrl(1),
156 'text2'=> $late,
157 'asis' => 1
158 );
159
160 $this->info_box_contents[$line][1] = array(
161 'td' => 'class="tdoverflowmax100"',
162 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
163 'asis' => 1
164 );
165
166 $this->info_box_contents[$line][2] = array(
167 'td' => 'class="center nowraponall"',
168 'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
169 'asis' => 1
170 );
171
172 $this->info_box_contents[$line][3] = array(
173 'td' => 'class="right"',
174 'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
175 'asis' => 1
176 );
177
178 $this->info_box_contents[$line][4] = array(
179 'td' => 'class="right" width="18"',
180 'text' => $actionstatic->LibStatut($objp->percentage, 3),
181 'asis' => 1
182 );
183
184 $line++;
185 }
186
187 if ($num == 0) {
188 $this->info_box_contents[$line][0] = array(
189 'td' => 'class="center"',
190 'text'=> '<span class="opacitymedium">'.$langs->trans("NoActionsToDo").'</span>'
191 );
192 }
193
194 $this->db->free($result);
195 } else {
196 $this->info_box_contents[0][0] = array(
197 'td' => '',
198 'maxlength'=>500,
199 'text' => ($this->db->error().' sql='.$sql)
200 );
201 }
202 } else {
203 $this->info_box_contents[0][0] = array(
204 'td' => 'class="nohover left"',
205 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
206 );
207 }
208 }
209
218 public function showBox($head = null, $contents = null, $nooutput = 0)
219 {
220 global $langs, $conf;
221 $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
222
223 if (getDolGlobalString('SHOW_DIALOG_HOMEPAGE')) {
224 $actioncejour = false;
225 $contents = $this->info_box_contents;
226 if (is_countable($contents) && count($contents) > 0) {
227 $nblines = count($contents);
228 }
229 if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
230 $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
231 $out .= '<table width=100%>';
232 for ($line = 0, $n = $nblines; $line < $n; $line++) {
233 if (isset($contents[$line])) {
234 // on affiche que les évènement du jours ou passé
235 // qui ne sont pas à 100%
236 $actioncejour = true;
237
238 // TR
239 $logo = $contents[$line][0]['logo'];
240 $label = $contents[$line][1]['text'];
241 $urlevent = $contents[$line][1]['url'];
242 $logosoc = $contents[$line][2]['logo'];
243 $nomsoc = $contents[$line][3]['text'];
244 $urlsoc = $contents[$line][3]['url'];
245 $dateligne = $contents[$line][4]['text'];
246 $percentage = $contents[$line][5]['text'];
247 $out .= '<tr class="oddeven">';
248 $out .= '<td class="center">';
249 $out .= img_object("", $logo);
250 $out .= '</td>';
251 $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
252 $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
253 $out .= '<td class="center">'.$dateligne.'</td>';
254 $out .= '<td class="center">'.$percentage.'</td>';
255 $out .= '</tr>';
256 }
257 }
258 $out .= '</table>';
259 }
260 $out .= '</div>';
261 if ($actioncejour) {
262 $out .= '<script nonce="'.getNonce().'">';
263 $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
264 if (getDolGlobalInt('SHOW_DIALOG_HOMEPAGE') > 1) { // autoclose after this delay
265 $out .= 'setTimeout(function(){';
266 $out .= '$("#dialogboxaction").dialog("close");';
267 $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
268 }
269 $out .= '</script>';
270 } else {
271 $out .= '<script nonce="'.getNonce().'">';
272 $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
273 $out .= '</script>';
274 }
275 }
276
277 if ($nooutput) {
278 return $out;
279 } else {
280 print $out;
281 }
282
283 return '';
284 }
285}
Class to manage agenda events (actions)
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show events in future.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.