dolibarr  9.0.0
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 <http://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  var $boxcode="lastactions";
36  var $boximg="object_action";
37  var $boxlabel="BoxLastActions";
38  var $depends = array("agenda");
39 
43  public $db;
44 
45  var $param;
46 
47  var $info_box_head = array();
48  var $info_box_contents = array();
49 
50 
57  function __construct($db,$param='')
58  {
59  global $user;
60 
61  $this->db = $db;
62 
63  $this->hidden = ! ($user->rights->agenda->myactions->read);
64  }
65 
72  function loadBox($max=5)
73  {
74  global $user, $langs, $db, $conf;
75 
76  $this->max=$max;
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($db);
81  $actionstatic = new ActionComm($db);
82 
83  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastActionsToDo",$max));
84 
85  if ($user->rights->agenda->myactions->read) {
86  $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
87  $sql.= ", ta.code";
88  $sql.= ", ta.libelle as type_label";
89  $sql.= ", s.nom as name";
90  $sql.= ", s.rowid as socid";
91  $sql.= ", s.code_client";
92  $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm AS ta, ";
93  $sql.= MAIN_DB_PREFIX."actioncomm AS a)";
94  if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
95  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
96  $sql.= " WHERE a.fk_action = ta.id";
97  $sql.= " AND a.entity = ".$conf->entity;
98  $sql.= " AND a.percent >= 0 AND a.percent < 100";
99  if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
100  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
101  if (! $user->rights->agenda->allactions->read) $sql.= " AND (a.fk_user_author = ".$user->id . " OR a.fk_user_action = ".$user->id . " OR a.fk_user_done = ".$user->id . ")";
102  $sql.= " ORDER BY a.datec DESC";
103  $sql.= $db->plimit($max, 0);
104 
105  dol_syslog("Box_actions::loadBox", LOG_DEBUG);
106  $result = $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 = $db->num_rows($result);
112  $line = 0;
113  while ($line < $num) {
114  $late = '';
115  $objp = $db->fetch_object($result);
116  $datelimite = $db->jdate($objp->dp);
117  $actionstatic->id = $objp->id;
118  $actionstatic->label = $objp->label;
119  $actionstatic->type_label = $objp->type_label;
120  $actionstatic->code = $objp->code;
121  $societestatic->id = $objp->socid;
122  $societestatic->name = $objp->name;
123  $societestatic->code_client = $objp->code_client;
124 
125  if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning))
126  $late=img_warning($langs->trans("Late"));
127 
128  //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
129  $label = empty($objp->label)?$objp->type_label:$objp->label;
130 
131  $this->info_box_contents[$line][] = array(
132  'td' => '',
133  'text' => $actionstatic->getNomUrl(1),
134  'text2'=> $late,
135  'asis' => 1,
136  );
137 
138  $this->info_box_contents[$line][] = array(
139  'td' => '',
140  'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
141  'asis' => 1,
142  );
143 
144  $this->info_box_contents[$line][] = array(
145  'td' => 'align="left" class="nowrap"',
146  'text' => dol_print_date($datelimite, "dayhour"),
147  );
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'class="right"',
151  'text' => ($objp->percentage>= 0?$objp->percentage.'%':''),
152  );
153 
154  $this->info_box_contents[$line][] = array(
155  'td' => 'align="right" width="18"',
156  'text' => $actionstatic->LibStatut($objp->percentage,3),
157  );
158 
159  $line++;
160  }
161 
162  if ($num==0)
163  $this->info_box_contents[$line][0] = array(
164  'td' => 'align="center"',
165  'text'=>$langs->trans("NoActionsToDo"),
166  );
167 
168  $db->free($result);
169  } else {
170  $this->info_box_contents[0][0] = array(
171  'td' => '',
172  'maxlength'=>500,
173  'text' => ($db->error().' sql='.$sql),
174  );
175  }
176  } else {
177  $this->info_box_contents[0][0] = array(
178  'td' => 'align="left" class="nohover opacitymedium"',
179  'text' => $langs->trans("ReadPermissionNotAllowed")
180  );
181  }
182  }
183 
192  function showBox($head = null, $contents = null, $nooutput=0)
193  {
194  global $langs, $conf;
195  $out = parent::showBox($this->info_box_head, $this->info_box_contents);
196 
197  if (! empty($conf->global->SHOW_DIALOG_HOMEPAGE))
198  {
199  $actioncejour=false;
200  $contents=$this->info_box_contents;
201  $nblines=count($contents);
202  if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo"))
203  {
204  $out.= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
205  $out.= '<table width=100%>';
206  for ($line=0, $n=$nblines; $line < $n; $line++)
207  {
208  if (isset($contents[$line]))
209  {
210  // on affiche que les évènement du jours ou passé
211  // qui ne sont pas à 100%
212  $actioncejour=true;
213 
214  // TR
215  $logo=$contents[$line][0]['logo'];
216  $label=$contents[$line][1]['text'];
217  $urlevent=$contents[$line][1]['url'];
218  $logosoc=$contents[$line][2]['logo'];
219  $nomsoc=$contents[$line][3]['text'];
220  $urlsoc=$contents[$line][3]['url'];
221  $dateligne=$contents[$line][4]['text'];
222  $percentage=$contents[$line][5]['text'];
223  $out.= '<tr class="oddeven">';
224  $out.= '<td align=center>';
225  $out.= img_object("",$logo);
226  $out.= '</td>';
227  $out.= '<td align=center><a href="'.$urlevent.'">'.$label.'</a></td>';
228  $out.= '<td align=center><a href="'.$urlsoc.'">'.img_object("",$logosoc)." ".$nomsoc.'</a></td>';
229  $out.= '<td align=center>'.$dateligne.'</td>';
230  $out.= '<td align=center>'.$percentage.'</td>';
231  $out.= '</tr>';
232  }
233  }
234  $out.= '</table>';
235  }
236  $out.= '</div>';
237  if ($actioncejour)
238  {
239  $out.= '<script>';
240  $out.= '$("#dialogboxaction").dialog({ autoOpen: true });';
241  if ($conf->global->SHOW_DIALOG_HOMEPAGE > 1) // autoclose after this delay
242  {
243  $out.= 'setTimeout(function(){';
244  $out.= '$("#dialogboxaction").dialog("close");';
245  $out.= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE*1000).');';
246  }
247  $out.= '</script>';
248  }
249  else
250  {
251  $out.= '<script>';
252  $out.= '$("#dialogboxaction").dialog({ autoOpen: false });';
253  $out.= '</script>';
254  }
255  }
256 
257  if ($nooutput) return $out;
258  else print $out;
259 
260  return '';
261  }
262 }
263 
img_warning($titlealt='default', $moreatt='')
Show warning logo.
print
Draft customers invoices.
Definition: index.php:91
__construct($db, $param='')
Constructor.
Definition: box_actions.php:57
loadBox($max=5)
Load data for box to show them later.
Definition: box_actions.php:72
Class to manage the box to show last events.
Definition: box_actions.php:33
Class to manage agenda events (actions)
Class ModeleBoxes.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_now($mode='gmt')
Return date for now.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)