dolibarr 23.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-2025 Frédéric 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 $this->urltoaddentry = DOL_URL_ROOT.'/comm/action/card.php?action=create';
60
61 $this->msgNoRecords = 'NoUpcomingEvent';
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $user, $langs;
73
74 $this->max = $max;
75
76 $now = dol_now();
77
78 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
79 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
80 $societestatic = new Societe($this->db);
81 $actionstatic = new ActionComm($this->db);
82
83 $text = $langs->trans("BoxTitleFutureActions", $max);
84 $this->info_box_head = array(
85 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/comm/action/list.php?sortfield=a.datep&datestart_dtstartday='.dol_print_date($now, '%d').'&datestart_dtstartmonth='.dol_print_date($now, '%m').'&datestart_dtstartyear='.dol_print_date($now, '%Y').'&sortorder=ASC"><span class="badge">...</span></a>'
86 );
87
88 if ($user->hasRight('agenda', 'myactions', 'read')) {
89 $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
90 $sql .= ", ta.code";
91 $sql .= ", ta.libelle as type_label";
92 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
93 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
94 $sql .= ", s.logo, s.email, s.entity";
95 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
96 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
97 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
98 }
99 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
100 $sql .= " WHERE a.fk_action = ta.id";
101 $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
102 //$sql .= " AND a.percent >= 0 AND a.percent < 100";
103 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
104 $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
105 }
106 if ($user->socid) {
107 $sql .= " AND s.rowid = ".((int) $user->socid);
108 }
109 if (!$user->hasRight('agenda', 'allactions', 'read')) {
110 $sql .= " AND (a.fk_user_author = ".((int) $user->id)." OR a.fk_user_action = ".((int) $user->id).")";
111 }
112 $sql .= " AND a.datep > '".$this->db->idate($now)."'";
113 $sql .= " ORDER BY a.datep ASC";
114 $sql .= $this->db->plimit($max, 0);
115
116 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
117 $result = $this->db->query($sql);
118 if ($result) {
119 $now = dol_now();
120 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
121
122 $num = $this->db->num_rows($result);
123
124 $line = 0;
125 while ($line < $num) {
126 $late = '';
127 $objp = $this->db->fetch_object($result);
128 $datelimite = $this->db->jdate($objp->dp);
129
130 $actionstatic->id = $objp->id;
131 $actionstatic->label = $objp->label;
132 $actionstatic->type_label = $objp->type_label;
133 $actionstatic->code = $objp->code;
134
135 $societestatic->id = $objp->socid;
136 $societestatic->name = $objp->name;
137 //$societestatic->name_alias = $objp->name_alias;
138 $societestatic->code_client = $objp->code_client;
139 $societestatic->code_compta = $objp->code_compta_client;
140 $societestatic->code_compta_client = $objp->code_compta_client;
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 $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 $nblines = 0;
222 if (is_countable($contents) && count($contents) > 0) {
223 $nblines = count($contents);
224 }
225 if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
226 $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
227 $out .= '<table width=100%>';
228 for ($line = 0, $n = $nblines; $line < $n; $line++) {
229 if (isset($contents[$line])) {
230 // on affiche que les évènement du jours ou passé
231 // qui ne sont pas à 100%
232 $actioncejour = true;
233
234 // TR
235 $logo = $contents[$line][0]['logo'];
236 $label = $contents[$line][1]['text'];
237 $urlevent = $contents[$line][1]['url'];
238 $logosoc = $contents[$line][2]['logo'];
239 $nomsoc = $contents[$line][3]['text'];
240 $urlsoc = $contents[$line][3]['url'];
241 $dateligne = $contents[$line][4]['text'];
242 $percentage = $contents[$line][5]['text'];
243 $out .= '<tr class="oddeven">';
244 $out .= '<td class="center">';
245 $out .= img_object("", $logo);
246 $out .= '</td>';
247 $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
248 $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
249 $out .= '<td class="center">'.$dateligne.'</td>';
250 $out .= '<td class="center">'.$percentage.'</td>';
251 $out .= '</tr>';
252 }
253 }
254 $out .= '</table>';
255 }
256 $out .= '</div>';
257 if ($actioncejour) {
258 $out .= '<script nonce="'.getNonce().'">';
259 $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
260 if (getDolGlobalInt('SHOW_DIALOG_HOMEPAGE') > 1) { // autoclose after this delay
261 $out .= 'setTimeout(function(){';
262 $out .= '$("#dialogboxaction").dialog("close");';
263 $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
264 }
265 $out .= '</script>';
266 } else {
267 $out .= '<script nonce="'.getNonce().'">';
268 $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
269 $out .= '</script>';
270 }
271 }
272
273 if ($nooutput) {
274 return $out;
275 } else {
276 print $out;
277 }
278
279 return '';
280 }
281}
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.
dol_now($mode='gmt')
Return date for now.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.