dolibarr 21.0.0-alpha
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 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 = "lastactions";
36 public $boximg = "object_action";
37 public $boxlabel = "BoxOldestActions";
38 public $depends = array("agenda");
39
40 public $enabled = 1;
41
48 public function __construct($db, $param)
49 {
50 global $user;
51
52 $this->db = $db;
53
54 $this->enabled = isModEnabled('agenda');
55
56 $this->hidden = !($user->hasRight('agenda', 'myactions', 'read'));
57 }
58
65 public function loadBox($max = 5)
66 {
67 global $user, $langs, $conf;
68
69 $this->max = $max;
70
71 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
72 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
73 $societestatic = new Societe($this->db);
74 $actionstatic = new ActionComm($this->db);
75
76 $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestActionsToDo", $max));
77
78 if ($user->hasRight('agenda', 'myactions', 'read')) {
79 $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
80 $sql .= ", ta.code";
81 $sql .= ", ta.libelle as type_label";
82 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
83 $sql .= ", s.code_client, s.code_compta, s.client";
84 $sql .= ", s.logo, s.email, s.entity";
85 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
86 if (!$user->hasRight('societe', 'client', 'voir')) {
87 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
88 }
89 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
90 $sql .= " WHERE a.fk_action = ta.id";
91 $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
92 $sql .= " AND a.percent >= 0 AND a.percent < 100";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
95 }
96 if ($user->socid) {
97 $sql .= " AND s.rowid = ".((int) $user->socid);
98 }
99 if (!$user->hasRight('agenda', 'allactions', 'read')) {
100 $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).")";
101 }
102 $sql .= " ORDER BY a.datep ASC";
103 $sql .= $this->db->plimit($max, 0);
104
105 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
106 $result = $this->db->query($sql);
107 if ($result) {
108 $now = dol_now();
109 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
110
111 $num = $this->db->num_rows($result);
112
113 $line = 0;
114 while ($line < $num) {
115 $late = '';
116 $objp = $this->db->fetch_object($result);
117 $datelimite = $this->db->jdate($objp->dp);
118
119 $actionstatic->id = $objp->id;
120 $actionstatic->label = $objp->label;
121 $actionstatic->type_label = $objp->type_label;
122 $actionstatic->code = $objp->code;
123
124 $societestatic->id = $objp->socid;
125 $societestatic->name = $objp->name;
126 //$societestatic->name_alias = $objp->name_alias;
127 $societestatic->code_client = $objp->code_client;
128 $societestatic->code_compta = $objp->code_compta;
129 $societestatic->client = $objp->client;
130 $societestatic->logo = $objp->logo;
131 $societestatic->email = $objp->email;
132 $societestatic->entity = $objp->entity;
133
134 if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
135 $late = img_warning($langs->trans("Late"));
136 }
137
138 //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
139 //$label = empty($objp->label) ? $objp->type_label : $objp->label;
140
141 $this->info_box_contents[$line][0] = array(
142 'td' => 'class="tdoverflowmax200"',
143 'text' => $actionstatic->getNomUrl(1),
144 'text2'=> $late,
145 'asis' => 1
146 );
147
148 $this->info_box_contents[$line][1] = array(
149 'td' => 'class="tdoverflowmax100"',
150 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
151 'asis' => 1
152 );
153
154 $this->info_box_contents[$line][2] = array(
155 'td' => 'class="center nowraponall"',
156 'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
157 'asis' => 1
158 );
159
160 $this->info_box_contents[$line][3] = array(
161 'td' => 'class="right"',
162 'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
163 'asis' => 1
164 );
165
166 $this->info_box_contents[$line][4] = array(
167 'td' => 'class="right" width="18"',
168 'text' => $actionstatic->LibStatut($objp->percentage, 3),
169 'asis' => 1
170 );
171
172 $line++;
173 }
174
175 if ($num == 0) {
176 $this->info_box_contents[$line][0] = array(
177 'td' => 'class="center"',
178 'text'=> '<span class="opacitymedium">'.$langs->trans("NoActionsToDo").'</span>'
179 );
180 }
181
182 $this->db->free($result);
183 } else {
184 $this->info_box_contents[0][0] = array(
185 'td' => '',
186 'maxlength'=>500,
187 'text' => ($this->db->error().' sql='.$sql)
188 );
189 }
190 } else {
191 $this->info_box_contents[0][0] = array(
192 'td' => 'class="nohover left"',
193 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
194 );
195 }
196 }
197
206 public function showBox($head = null, $contents = null, $nooutput = 0)
207 {
208 global $langs, $conf;
209 $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
210
211 if (getDolGlobalString('SHOW_DIALOG_HOMEPAGE')) {
212 $actioncejour = false;
213 $contents = $this->info_box_contents;
214 if (is_countable($contents) && count($contents) > 0) {
215 $nblines = count($contents);
216 }
217 if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
218 $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
219 $out .= '<table width=100%>';
220 for ($line = 0, $n = $nblines; $line < $n; $line++) {
221 if (isset($contents[$line])) {
222 // on affiche que les évènement du jours ou passé
223 // qui ne sont pas à 100%
224 $actioncejour = true;
225
226 // TR
227 $logo = $contents[$line][0]['logo'];
228 $label = $contents[$line][1]['text'];
229 $urlevent = $contents[$line][1]['url'];
230 $logosoc = $contents[$line][2]['logo'];
231 $nomsoc = $contents[$line][3]['text'];
232 $urlsoc = $contents[$line][3]['url'];
233 $dateligne = $contents[$line][4]['text'];
234 $percentage = $contents[$line][5]['text'];
235 $out .= '<tr class="oddeven">';
236 $out .= '<td class="center">';
237 $out .= img_object("", $logo);
238 $out .= '</td>';
239 $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
240 $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
241 $out .= '<td class="center">'.$dateligne.'</td>';
242 $out .= '<td class="center">'.$percentage.'</td>';
243 $out .= '</tr>';
244 }
245 }
246 $out .= '</table>';
247 }
248 $out .= '</div>';
249 if ($actioncejour) {
250 $out .= '<script nonce="'.getNonce().'">';
251 $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
252 if (getDolGlobalInt('SHOW_DIALOG_HOMEPAGE') > 1) { // autoclose after this delay
253 $out .= 'setTimeout(function(){';
254 $out .= '$("#dialogboxaction").dialog("close");';
255 $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
256 }
257 $out .= '</script>';
258 } else {
259 $out .= '<script nonce="'.getNonce().'">';
260 $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
261 $out .= '</script>';
262 }
263 }
264
265 if ($nooutput) {
266 return $out;
267 } else {
268 print $out;
269 }
270
271 return '';
272 }
273}
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.