dolibarr 21.0.0-beta
box_actions.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-2024 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 = "lastactions";
37 public $boximg = "object_action";
38 public $boxlabel = "BoxOldestActions";
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 $this->msgNoRecords = 'NoActionsToDo';
61 }
62
69 public function loadBox($max = 5)
70 {
71 global $user, $langs;
72
73 $this->max = $max;
74
75 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
76 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
77 $societestatic = new Societe($this->db);
78 $actionstatic = new ActionComm($this->db);
79
80 $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestActionsToDo", $max));
81
82 if ($user->hasRight('agenda', 'myactions', 'read')) {
83 $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
84 $sql .= ", ta.code";
85 $sql .= ", ta.libelle as type_label";
86 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
87 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
88 $sql .= ", s.logo, s.email, s.entity";
89 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
90 if (!$user->hasRight('societe', 'client', 'voir')) {
91 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
92 }
93 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
94 $sql .= " WHERE a.fk_action = ta.id";
95 $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
96 $sql .= " AND a.percent >= 0 AND a.percent < 100";
97 if (!$user->hasRight('societe', 'client', 'voir')) {
98 $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
99 }
100 if ($user->socid) {
101 $sql .= " AND s.rowid = ".((int) $user->socid);
102 }
103 if (!$user->hasRight('agenda', 'allactions', 'read')) {
104 $sql .= " AND (a.fk_user_author = ".((int) $user->id)." OR a.fk_user_action = ".((int) $user->id).")";
105 }
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_client = $objp->code_compta_client;
133 $societestatic->client = $objp->client;
134 $societestatic->logo = $objp->logo;
135 $societestatic->email = $objp->email;
136 $societestatic->entity = $objp->entity;
137
138 if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
139 $late = img_warning($langs->trans("Late"));
140 }
141
142 //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
143 //$label = empty($objp->label) ? $objp->type_label : $objp->label;
144
145 $this->info_box_contents[$line][0] = array(
146 'td' => 'class="tdoverflowmax200"',
147 'text' => $actionstatic->getNomUrl(1),
148 'text2' => $late,
149 'asis' => 1
150 );
151
152 $this->info_box_contents[$line][1] = array(
153 'td' => 'class="tdoverflowmax100"',
154 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
155 'asis' => 1
156 );
157
158 $this->info_box_contents[$line][2] = array(
159 'td' => 'class="center nowraponall"',
160 'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
161 'asis' => 1
162 );
163
164 $this->info_box_contents[$line][3] = array(
165 'td' => 'class="right"',
166 'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
167 'asis' => 1
168 );
169
170 $this->info_box_contents[$line][4] = array(
171 'td' => 'class="right" width="18"',
172 'text' => $actionstatic->LibStatut($objp->percentage, 3),
173 'asis' => 1
174 );
175
176 $line++;
177 }
178
179 // if ($num == 0) {
180 // $this->info_box_contents[$line][0] = array(
181 // 'td' => 'class="center"',
182 // 'text' => '<span class="opacitymedium">'.$langs->trans("NoActionsToDo").'</span>'
183 // );
184 // }
185
186 $this->db->free($result);
187 } else {
188 $this->info_box_contents[0][0] = array(
189 'td' => '',
190 'maxlength' => 500,
191 'text' => ($this->db->error().' sql='.$sql)
192 );
193 }
194 } else {
195 $this->info_box_contents[0][0] = array(
196 'td' => 'class="nohover left"',
197 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
198 );
199 }
200 }
201
202
203
212 public function showBox($head = null, $contents = null, $nooutput = 0)
213 {
214 global $langs, $conf;
215 $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
216
217 if (getDolGlobalString('SHOW_DIALOG_HOMEPAGE')) {
218 $actioncejour = false;
219 $contents = $this->info_box_contents;
220 if (is_countable($contents) && count($contents) > 0) {
221 $nblines = count($contents);
222 }
223 if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
224 $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
225 $out .= '<table width=100%>';
226 for ($line = 0, $n = $nblines; $line < $n; $line++) {
227 if (isset($contents[$line])) {
228 // on affiche que les évènement du jours ou passé
229 // qui ne sont pas à 100%
230 $actioncejour = true;
231
232 // TR
233 $logo = $contents[$line][0]['logo'];
234 $label = $contents[$line][1]['text'];
235 $urlevent = $contents[$line][1]['url'];
236 $logosoc = $contents[$line][2]['logo'];
237 $nomsoc = $contents[$line][3]['text'];
238 $urlsoc = $contents[$line][3]['url'];
239 $dateligne = $contents[$line][4]['text'];
240 $percentage = $contents[$line][5]['text'];
241 $out .= '<tr class="oddeven">';
242 $out .= '<td class="center">';
243 $out .= img_object("", $logo);
244 $out .= '</td>';
245 $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
246 $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
247 $out .= '<td class="center">'.$dateligne.'</td>';
248 $out .= '<td class="center">'.$percentage.'</td>';
249 $out .= '</tr>';
250 }
251 }
252 $out .= '</table>';
253 }
254 $out .= '</div>';
255 if ($actioncejour) {
256 $out .= '<script nonce="'.getNonce().'">';
257 $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
258 if (getDolGlobalInt('SHOW_DIALOG_HOMEPAGE') > 1) { // autoclose after this delay
259 $out .= 'setTimeout(function(){';
260 $out .= '$("#dialogboxaction").dialog("close");';
261 $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
262 }
263 $out .= '</script>';
264 } else {
265 $out .= '<script nonce="'.getNonce().'">';
266 $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
267 $out .= '</script>';
268 }
269 }
270
271 if ($nooutput) {
272 return $out;
273 } else {
274 print $out;
275 }
276
277 return '';
278 }
279}
Class to manage agenda events (actions)
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last events.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param)
Constructor.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79