dolibarr  16.0.5
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 
28 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29 
33 class box_actions extends ModeleBoxes
34 {
35  public $boxcode = "lastactions";
36  public $boximg = "object_action";
37  public $boxlabel = "BoxLastActions";
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 $conf, $user;
60 
61  $this->db = $db;
62 
63  $this->enabled = $conf->agenda->enabled;
64 
65  $this->hidden = empty($user->rights->agenda->myactions->read);
66  }
67 
74  public function loadBox($max = 5)
75  {
76  global $user, $langs, $conf;
77 
78  $this->max = $max;
79 
80  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
81  include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
82  $societestatic = new Societe($this->db);
83  $actionstatic = new ActionComm($this->db);
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastActionsToDo", $max));
86 
87  if ($user->rights->agenda->myactions->read) {
88  $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
89  $sql .= ", ta.code";
90  $sql .= ", ta.libelle as type_label";
91  $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
92  $sql .= ", s.code_client, s.code_compta, s.client";
93  $sql .= ", s.logo, s.email, s.entity";
94  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
95  if (empty($user->rights->societe->client->voir) && !$user->socid) {
96  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
97  }
98  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
99  $sql .= " WHERE a.fk_action = ta.id";
100  $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
101  $sql .= " AND a.percent >= 0 AND a.percent < 100";
102  if (empty($user->rights->societe->client->voir) && !$user->socid) {
103  $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
104  }
105  if ($user->socid) {
106  $sql .= " AND s.rowid = ".((int) $user->socid);
107  }
108  if (empty($user->rights->agenda->allactions->read)) {
109  $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).")";
110  }
111  $sql .= " ORDER BY a.datec DESC";
112  $sql .= $this->db->plimit($max, 0);
113 
114  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
115  $result = $this->db->query($sql);
116  if ($result) {
117  $now = dol_now();
118  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
119 
120  $num = $this->db->num_rows($result);
121 
122  $line = 0;
123  while ($line < $num) {
124  $late = '';
125  $objp = $this->db->fetch_object($result);
126  $datelimite = $this->db->jdate($objp->dp);
127 
128  $actionstatic->id = $objp->id;
129  $actionstatic->label = $objp->label;
130  $actionstatic->type_label = $objp->type_label;
131  $actionstatic->code = $objp->code;
132 
133  $societestatic->id = $objp->socid;
134  $societestatic->name = $objp->name;
135  //$societestatic->name_alias = $objp->name_alias;
136  $societestatic->code_client = $objp->code_client;
137  $societestatic->code_compta = $objp->code_compta;
138  $societestatic->client = $objp->client;
139  $societestatic->logo = $objp->logo;
140  $societestatic->email = $objp->email;
141  $societestatic->entity = $objp->entity;
142 
143  if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
144  $late = img_warning($langs->trans("Late"));
145  }
146 
147  //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
148  $label = empty($objp->label) ? $objp->type_label : $objp->label;
149 
150  $this->info_box_contents[$line][0] = array(
151  'td' => 'class="tdoverflowmax200"',
152  'text' => $actionstatic->getNomUrl(1),
153  'text2'=> $late,
154  'asis' => 1
155  );
156 
157  $this->info_box_contents[$line][1] = array(
158  'td' => 'class="tdoverflowmax100"',
159  'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
160  'asis' => 1
161  );
162 
163  $this->info_box_contents[$line][2] = array(
164  'td' => 'class="center nowraponall"',
165  'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
166  'asis' => 1
167  );
168 
169  $this->info_box_contents[$line][3] = array(
170  'td' => 'class="right"',
171  'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
172  'asis' => 1
173  );
174 
175  $this->info_box_contents[$line][4] = array(
176  'td' => 'class="right" width="18"',
177  'text' => $actionstatic->LibStatut($objp->percentage, 3),
178  'asis' => 1
179  );
180 
181  $line++;
182  }
183 
184  if ($num == 0) {
185  $this->info_box_contents[$line][0] = array(
186  'td' => 'class="center opacitymedium"',
187  'text'=>$langs->trans("NoActionsToDo")
188  );
189  }
190 
191  $this->db->free($result);
192  } else {
193  $this->info_box_contents[0][0] = array(
194  'td' => '',
195  'maxlength'=>500,
196  'text' => ($this->db->error().' sql='.$sql)
197  );
198  }
199  } else {
200  $this->info_box_contents[0][0] = array(
201  'td' => 'class="nohover opacitymedium left"',
202  'text' => $langs->trans("ReadPermissionNotAllowed")
203  );
204  }
205  }
206 
215  public function showBox($head = null, $contents = null, $nooutput = 0)
216  {
217  global $langs, $conf;
218  $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
219 
220  if (!empty($conf->global->SHOW_DIALOG_HOMEPAGE)) {
221  $actioncejour = false;
222  $contents = $this->info_box_contents;
223  $nblines = count($contents);
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>';
258  $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
259  if ($conf->global->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>';
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 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
db
$conf db
API class for accounts.
Definition: inc.php:41
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
box_actions\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_actions.php:215
box_actions\loadBox
loadBox($max=5)
Load data for box to show them later.
Definition: box_actions.php:74
box_actions\__construct
__construct($db, $param)
Constructor.
Definition: box_actions.php:57
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
box_actions
Class to manage the box to show last events.
Definition: box_actions.php:33
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34