dolibarr  7.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@capnetworks.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 
40  var $db;
41  var $param;
42 
43  var $info_box_head = array();
44  var $info_box_contents = array();
45 
46 
53  function __construct($db,$param='')
54  {
55  global $user;
56 
57  $this->db = $db;
58 
59  $this->hidden = ! ($user->rights->agenda->myactions->read);
60  }
61 
68  function loadBox($max=5)
69  {
70  global $user, $langs, $db, $conf;
71 
72  $this->max=$max;
73 
74  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
75  include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
76  $societestatic = new Societe($db);
77  $actionstatic = new ActionComm($db);
78 
79  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastActionsToDo",$max));
80 
81  if ($user->rights->agenda->myactions->read) {
82  $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
83  $sql.= ", ta.code";
84  $sql.= ", ta.libelle as type_label";
85  $sql.= ", s.nom as name";
86  $sql.= ", s.rowid as socid";
87  $sql.= ", s.code_client";
88  $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm AS ta, ";
89  $sql.= MAIN_DB_PREFIX."actioncomm AS a)";
90  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";
91  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
92  $sql.= " WHERE a.fk_action = ta.id";
93  $sql.= " AND a.entity = ".$conf->entity;
94  $sql.= " AND a.percent >= 0 AND a.percent < 100";
95  if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
96  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
97  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 . ")";
98  $sql.= " ORDER BY a.datec DESC";
99  $sql.= $db->plimit($max, 0);
100 
101  dol_syslog("Box_actions::loadBox", LOG_DEBUG);
102  $result = $db->query($sql);
103  if ($result) {
104  $now=dol_now();
105  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
106 
107  $num = $db->num_rows($result);
108  $line = 0;
109  while ($line < $num) {
110  $late = '';
111  $objp = $db->fetch_object($result);
112  $datelimite = $db->jdate($objp->dp);
113  $actionstatic->id = $objp->id;
114  $actionstatic->label = $objp->label;
115  $actionstatic->type_label = $objp->type_label;
116  $actionstatic->code = $objp->code;
117  $societestatic->id = $objp->socid;
118  $societestatic->name = $objp->name;
119  $societestatic->code_client = $objp->code_client;
120 
121  if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning))
122  $late=img_warning($langs->trans("Late"));
123 
124  //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
125  $label = empty($objp->label)?$objp->type_label:$objp->label;
126 
127  $this->info_box_contents[$line][] = array(
128  'td' => '',
129  'text' => $actionstatic->getNomUrl(1),
130  'text2'=> $late,
131  'asis' => 1,
132  );
133 
134  $this->info_box_contents[$line][] = array(
135  'td' => '',
136  'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
137  'asis' => 1,
138  );
139 
140  $this->info_box_contents[$line][] = array(
141  'td' => 'align="left" class="nowrap"',
142  'text' => dol_print_date($datelimite, "dayhour"),
143  );
144 
145  $this->info_box_contents[$line][] = array(
146  'td' => 'class="right"',
147  'text' => ($objp->percentage>= 0?$objp->percentage.'%':''),
148  );
149 
150  $this->info_box_contents[$line][] = array(
151  'td' => 'align="right" width="18"',
152  'text' => $actionstatic->LibStatut($objp->percentage,3),
153  );
154 
155  $line++;
156  }
157 
158  if ($num==0)
159  $this->info_box_contents[$line][0] = array(
160  'td' => 'align="center"',
161  'text'=>$langs->trans("NoActionsToDo"),
162  );
163 
164  $db->free($result);
165  } else {
166  $this->info_box_contents[0][0] = array(
167  'td' => '',
168  'maxlength'=>500,
169  'text' => ($db->error().' sql='.$sql),
170  );
171  }
172  } else {
173  $this->info_box_contents[0][0] = array(
174  'td' => 'align="left" class="nohover opacitymedium"',
175  'text' => $langs->trans("ReadPermissionNotAllowed")
176  );
177  }
178  }
179 
188  function showBox($head = null, $contents = null, $nooutput=0)
189  {
190  global $langs, $conf;
191  $out = parent::showBox($this->info_box_head, $this->info_box_contents);
192 
193  if (! empty($conf->global->SHOW_DIALOG_HOMEPAGE))
194  {
195  $actioncejour=false;
196  $contents=$this->info_box_contents;
197  $nblines=count($contents);
198  if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo"))
199  {
200  $out.= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
201  $out.= '<table width=100%>';
202  for ($line=0, $n=$nblines; $line < $n; $line++)
203  {
204  if (isset($contents[$line]))
205  {
206  // on affiche que les évènement du jours ou passé
207  // qui ne sont pas à 100%
208  $actioncejour=true;
209 
210  // TR
211  $logo=$contents[$line][0]['logo'];
212  $label=$contents[$line][1]['text'];
213  $urlevent=$contents[$line][1]['url'];
214  $logosoc=$contents[$line][2]['logo'];
215  $nomsoc=$contents[$line][3]['text'];
216  $urlsoc=$contents[$line][3]['url'];
217  $dateligne=$contents[$line][4]['text'];
218  $percentage=$contents[$line][5]['text'];
219  $out.= '<tr class="oddeven">';
220  $out.= '<td align=center>';
221  $out.= img_object("",$logo);
222  $out.= '</td>';
223  $out.= '<td align=center><a href="'.$urlevent.'">'.$label.'</a></td>';
224  $out.= '<td align=center><a href="'.$urlsoc.'">'.img_object("",$logosoc)." ".$nomsoc.'</a></td>';
225  $out.= '<td align=center>'.$dateligne.'</td>';
226  $out.= '<td align=center>'.$percentage.'</td>';
227  $out.= '</tr>';
228  }
229  }
230  $out.= '</table>';
231 
232  }
233  $out.= '</div>';
234  if ($actioncejour)
235  {
236  $out.= '<script>';
237  $out.= '$("#dialogboxaction").dialog({ autoOpen: true });';
238  if ($conf->global->SHOW_DIALOG_HOMEPAGE > 1) // autoclose after this delay
239  {
240  $out.= 'setTimeout(function(){';
241  $out.= '$("#dialogboxaction").dialog("close");';
242  $out.= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE*1000).');';
243  }
244  $out.= '</script>';
245  }
246  else
247  {
248  $out.= '<script>';
249  $out.= '$("#dialogboxaction").dialog({ autoOpen: false });';
250  $out.= '</script>';
251  }
252  }
253 
254  if ($nooutput) return $out;
255  else print $out;
256 
257  return '';
258  }
259 
260 }
261 
__construct($db, $param='')
Constructor.
Definition: box_actions.php:53
loadBox($max=5)
Load data for box to show them later.
Definition: box_actions.php:68
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...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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).
print
Draft customers invoices.
Definition: index.php:91