dolibarr  19.0.0-dev
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 = "BoxOldestActions";
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 $user;
60 
61  $this->db = $db;
62 
63  $this->enabled = isModEnabled('agenda');
64 
65  $this->hidden = !($user->hasRight('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("BoxTitleOldestActionsToDo", $max));
86 
87  if ($user->hasRight('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 (!$user->hasRight('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.datep ASC";
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  if (is_countable($contents) && count($contents) > 0) {
224  $nblines = count($contents);
225  }
226  if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
227  $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
228  $out .= '<table width=100%>';
229  for ($line = 0, $n = $nblines; $line < $n; $line++) {
230  if (isset($contents[$line])) {
231  // on affiche que les évènement du jours ou passé
232  // qui ne sont pas à 100%
233  $actioncejour = true;
234 
235  // TR
236  $logo = $contents[$line][0]['logo'];
237  $label = $contents[$line][1]['text'];
238  $urlevent = $contents[$line][1]['url'];
239  $logosoc = $contents[$line][2]['logo'];
240  $nomsoc = $contents[$line][3]['text'];
241  $urlsoc = $contents[$line][3]['url'];
242  $dateligne = $contents[$line][4]['text'];
243  $percentage = $contents[$line][5]['text'];
244  $out .= '<tr class="oddeven">';
245  $out .= '<td class="center">';
246  $out .= img_object("", $logo);
247  $out .= '</td>';
248  $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
249  $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
250  $out .= '<td class="center">'.$dateligne.'</td>';
251  $out .= '<td class="center">'.$percentage.'</td>';
252  $out .= '</tr>';
253  }
254  }
255  $out .= '</table>';
256  }
257  $out .= '</div>';
258  if ($actioncejour) {
259  $out .= '<script nonce="'.getNonce().'">';
260  $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
261  if ($conf->global->SHOW_DIALOG_HOMEPAGE > 1) { // autoclose after this delay
262  $out .= 'setTimeout(function(){';
263  $out .= '$("#dialogboxaction").dialog("close");';
264  $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
265  }
266  $out .= '</script>';
267  } else {
268  $out .= '<script nonce="'.getNonce().'">';
269  $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
270  $out .= '</script>';
271  }
272  }
273 
274  if ($nooutput) {
275  return $out;
276  } else {
277  print $out;
278  }
279 
280  return '';
281  }
282 }
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.
Definition: box_actions.php:34
loadBox($max=5)
Load data for box to show them later.
Definition: box_actions.php:74
__construct($db, $param)
Constructor.
Definition: box_actions.php:57
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.