dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
30
35{
36 public $boxcode = "futureactions";
37 public $boximg = "object_action";
38 public $boxlabel = "BoxTitleFutureActions";
39 public $depends = array("agenda");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param)
50 {
51 global $user;
52
53 $this->db = $db;
54
55 $this->enabled = isModEnabled('agenda');
56
57 $this->hidden = !($user->hasRight('agenda', 'myactions', 'read'));
58 }
59
66 public function loadBox($max = 5)
67 {
68 global $user, $langs, $conf;
69
70 $this->max = $max;
71
72 $now = dol_now();
73
74 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
75 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
76 $societestatic = new Societe($this->db);
77 $actionstatic = new ActionComm($this->db);
78
79 $this->info_box_head = array('text' => $langs->trans("BoxTitleFutureActions", $max));
80
81 if ($user->hasRight('agenda', 'myactions', 'read')) {
82 $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
83 $sql .= ", ta.code";
84 $sql .= ", ta.libelle as type_label";
85 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
86 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
87 $sql .= ", s.logo, s.email, s.entity";
88 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
89 if (!$user->hasRight('societe', 'client', 'voir')) {
90 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
91 }
92 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
93 $sql .= " WHERE a.fk_action = ta.id";
94 $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
95 //$sql .= " AND a.percent >= 0 AND a.percent < 100";
96 if (!$user->hasRight('societe', 'client', 'voir')) {
97 $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
98 }
99 if ($user->socid) {
100 $sql .= " AND s.rowid = ".((int) $user->socid);
101 }
102 if (!$user->hasRight('agenda', 'allactions', 'read')) {
103 $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).")";
104 }
105 $sql .= " AND a.datep > '".$this->db->idate($now)."'";
106 $sql .= " ORDER BY a.datep ASC";
107 $sql .= $this->db->plimit($max, 0);
108
109 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
110 $result = $this->db->query($sql);
111 if ($result) {
112 $now = dol_now();
113 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
114
115 $num = $this->db->num_rows($result);
116
117 $line = 0;
118 while ($line < $num) {
119 $late = '';
120 $objp = $this->db->fetch_object($result);
121 $datelimite = $this->db->jdate($objp->dp);
122
123 $actionstatic->id = $objp->id;
124 $actionstatic->label = $objp->label;
125 $actionstatic->type_label = $objp->type_label;
126 $actionstatic->code = $objp->code;
127
128 $societestatic->id = $objp->socid;
129 $societestatic->name = $objp->name;
130 //$societestatic->name_alias = $objp->name_alias;
131 $societestatic->code_client = $objp->code_client;
132 $societestatic->code_compta = $objp->code_compta;
133 $societestatic->code_compta_client = $objp->code_compta_client;
134 $societestatic->client = $objp->client;
135 $societestatic->logo = $objp->logo;
136 $societestatic->email = $objp->email;
137 $societestatic->entity = $objp->entity;
138
139 if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
140 $late = img_warning($langs->trans("Late"));
141 }
142
143 //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
144 //$label = empty($objp->label) ? $objp->type_label : $objp->label;
145
146 $this->info_box_contents[$line][0] = array(
147 'td' => 'class="tdoverflowmax200"',
148 'text' => $actionstatic->getNomUrl(1),
149 'text2' => $late,
150 'asis' => 1
151 );
152
153 $this->info_box_contents[$line][1] = array(
154 'td' => 'class="tdoverflowmax100"',
155 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
156 'asis' => 1
157 );
158
159 $this->info_box_contents[$line][2] = array(
160 'td' => 'class="center nowraponall"',
161 'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
162 'asis' => 1
163 );
164
165 $this->info_box_contents[$line][3] = array(
166 'td' => 'class="right"',
167 'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
168 'asis' => 1
169 );
170
171 $this->info_box_contents[$line][4] = array(
172 'td' => 'class="right" width="18"',
173 'text' => $actionstatic->LibStatut($objp->percentage, 3),
174 'asis' => 1
175 );
176
177 $line++;
178 }
179
180 if ($num == 0) {
181 $this->info_box_contents[$line][0] = array(
182 'td' => 'class="center"',
183 'text' => '<span class="opacitymedium">'.$langs->trans("NoActionsToDo").'</span>'
184 );
185 }
186
187 $this->db->free($result);
188 } else {
189 $this->info_box_contents[0][0] = array(
190 'td' => '',
191 'maxlength' => 500,
192 'text' => ($this->db->error().' sql='.$sql)
193 );
194 }
195 } else {
196 $this->info_box_contents[0][0] = array(
197 'td' => 'class="nohover left"',
198 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
199 );
200 }
201 }
202
203
204
213 public function showBox($head = null, $contents = null, $nooutput = 0)
214 {
215 global $langs, $conf;
216 $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
217
218 if (getDolGlobalString('SHOW_DIALOG_HOMEPAGE')) {
219 $actioncejour = false;
220 $contents = $this->info_box_contents;
221 if (is_countable($contents) && count($contents) > 0) {
222 $nblines = count($contents);
223 }
224 if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
225 $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
226 $out .= '<table width=100%>';
227 for ($line = 0, $n = $nblines; $line < $n; $line++) {
228 if (isset($contents[$line])) {
229 // on affiche que les évènement du jours ou passé
230 // qui ne sont pas à 100%
231 $actioncejour = true;
232
233 // TR
234 $logo = $contents[$line][0]['logo'];
235 $label = $contents[$line][1]['text'];
236 $urlevent = $contents[$line][1]['url'];
237 $logosoc = $contents[$line][2]['logo'];
238 $nomsoc = $contents[$line][3]['text'];
239 $urlsoc = $contents[$line][3]['url'];
240 $dateligne = $contents[$line][4]['text'];
241 $percentage = $contents[$line][5]['text'];
242 $out .= '<tr class="oddeven">';
243 $out .= '<td class="center">';
244 $out .= img_object("", $logo);
245 $out .= '</td>';
246 $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
247 $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
248 $out .= '<td class="center">'.$dateligne.'</td>';
249 $out .= '<td class="center">'.$percentage.'</td>';
250 $out .= '</tr>';
251 }
252 }
253 $out .= '</table>';
254 }
255 $out .= '</div>';
256 if ($actioncejour) {
257 $out .= '<script nonce="'.getNonce().'">';
258 $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
259 if (getDolGlobalInt('SHOW_DIALOG_HOMEPAGE') > 1) { // autoclose after this delay
260 $out .= 'setTimeout(function(){';
261 $out .= '$("#dialogboxaction").dialog("close");';
262 $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
263 }
264 $out .= '</script>';
265 } else {
266 $out .= '<script nonce="'.getNonce().'">';
267 $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
268 $out .= '</script>';
269 }
270 }
271
272 if ($nooutput) {
273 return $out;
274 } else {
275 print $out;
276 }
277
278 return '';
279 }
280}
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.