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