dolibarr  13.0.2
infobox.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
29 class InfoBox
30 {
36  public static function getListOfPagesForBoxes()
37  {
38  global $conf;
39 
40  if (empty($conf->global->MAIN_FEATURES_LEVEL) || $conf->global->MAIN_FEATURES_LEVEL < 2)
41  {
42  return array(
43  0 => 'Home',
44  27 => 'AccountancyHome'
45  );
46  } else {
47  return array(
48  0 => 'Home',
49  1 => 'userhome',
50  2 => 'membersindex',
51  3 => 'thirdpartiesindex',
52  4 => 'productindex',
53  5 => 'productindex',
54  6 => 'mrpindex',
55  7 => 'commercialindex',
56  8 => 'projectsindex',
57  9 => 'invoiceindex',
58  10 => 'hrmindex',
59  11 => 'ticketsindex',
60  12 => 'stockindex',
61  13 => 'sendingindex',
62  14 => 'receptionindex',
63  15 => 'activityindex',
64  16 => 'proposalindex',
65  17 => 'ordersindex',
66  18 => 'orderssuppliersindex',
67  19 => 'contractindex',
68  20 => 'interventionindex',
69  21 => 'suppliersproposalsindex',
70  22 => 'donationindex',
71  23 => 'specialexpensesindex',
72  24 => 'expensereportindex',
73  25 => 'mailingindex',
74  26 => 'opensurveyindex',
75  27 => 'AccountancyHome'
76  );
77  }
78  }
79 
91  public static function listBoxes($db, $mode, $zone, $user = null, $excludelist = array(), $includehidden = 1)
92  {
93  global $conf;
94 
95  $boxes = array();
96 
97  $confuserzone = 'MAIN_BOXES_'.$zone;
98  if ($mode == 'activated') // activated
99  {
100  $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,";
101  $sql .= " d.rowid as box_id, d.file, d.note, d.tms";
102  $sql .= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d";
103  $sql .= " WHERE b.box_id = d.rowid";
104  $sql .= " AND b.entity IN (0,".$conf->entity.")";
105  if ($zone >= 0) $sql .= " AND b.position = ".$zone;
106  if (is_object($user)) $sql .= " AND b.fk_user IN (0,".$user->id.")";
107  else $sql .= " AND b.fk_user = 0";
108  $sql .= " ORDER BY b.box_order";
109  } else // available
110  {
111  $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms";
112  $sql .= " FROM ".MAIN_DB_PREFIX."boxes_def as d";
113  $sql .= " WHERE d.entity IN (0,".$conf->entity.")";
114  }
115 
116  dol_syslog(get_class()."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user) ? $user->id : '')."", LOG_DEBUG);
117  $resql = $db->query($sql);
118  if ($resql)
119  {
120  $num = $db->num_rows($resql);
121  $j = 0;
122  while ($j < $num)
123  {
124  $obj = $db->fetch_object($resql);
125 
126  if (!in_array($obj->box_id, $excludelist))
127  {
128  $regs = array();
129  if (preg_match('/^([^@]+)@([^@]+)$/i', $obj->file, $regs))
130  {
131  $boxname = preg_replace('/\.php$/i', '', $regs[1]);
132  $module = $regs[2];
133  $relsourcefile = "/".$module."/core/boxes/".$boxname.".php";
134  } else {
135  $boxname = preg_replace('/\.php$/i', '', $obj->file);
136  $relsourcefile = "/core/boxes/".$boxname.".php";
137  }
138 
139  //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>';
140 
141  // TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then
142  // the "enabled" condition for modules forbidden for external users and the depends condition can be done.
143  // Goal is to avoid making a "new" done for each boxes returned by select.
144  dol_include_once($relsourcefile);
145  if (class_exists($boxname))
146  {
147  $box = new $boxname($db, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params.
148  //$box=new stdClass();
149 
150  // box properties
151  $box->rowid = (empty($obj->rowid) ? '' : $obj->rowid);
152  $box->id = (empty($obj->box_id) ? '' : $obj->box_id);
153  $box->position = ($obj->position == '' ? '' : $obj->position); // '0' must stay '0'
154  $box->box_order = (empty($obj->box_order) ? '' : $obj->box_order);
155  $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user);
156  $box->sourcefile = $relsourcefile;
157  $box->class = $boxname;
158 
159  if ($mode == 'activated' && !is_object($user)) // List of activated box was not yet personalized into database
160  {
161  if (is_numeric($box->box_order))
162  {
163  if ($box->box_order % 2 == 1) $box->box_order = 'A'.$box->box_order;
164  elseif ($box->box_order % 2 == 0) $box->box_order = 'B'.$box->box_order;
165  }
166  }
167  // box_def properties
168  $box->box_id = (empty($obj->box_id) ? '' : $obj->box_id);
169  $box->note = (empty($obj->note) ? '' : $obj->note);
170 
171  // Filter on box->enabled (used for example by box_comptes)
172  // Filter also on box->depends. Example: array("product|service") or array("contrat", "service")
173  $enabled = $box->enabled;
174  if (isset($box->depends) && count($box->depends) > 0)
175  {
176  foreach ($box->depends as $moduleelem)
177  {
178  $arrayelem = explode('|', $moduleelem);
179  $tmpenabled = 0; // $tmpenabled is used for the '|' test (OR)
180  foreach ($arrayelem as $module)
181  {
182  $tmpmodule = preg_replace('/@[^@]+/', '', $module);
183  if (!empty($conf->$tmpmodule->enabled)) $tmpenabled = 1;
184  //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>';
185  }
186  if (empty($tmpenabled)) // We found at least one module required that is disabled
187  {
188  $enabled = 0;
189  break;
190  }
191  }
192  }
193  //print '=>'.$boxname.'-enabled='.$enabled.'<br>';
194 
195  //print 'xx module='.$module.' enabled='.$enabled;
196  if ($enabled && ($includehidden || empty($box->hidden))) $boxes[] = $box;
197  else unset($box);
198  } else {
199  dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING);
200  }
201  }
202  $j++;
203  }
204  } else {
205  dol_syslog($db->lasterror(), LOG_ERR);
206  return array('error'=>$db->lasterror());
207  }
208 
209  return $boxes;
210  }
211 
212 
222  public static function saveboxorder($db, $zone, $boxorder, $userid = 0)
223  {
224  global $conf;
225 
226  $error = 0;
227 
228  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
229 
230  dol_syslog(get_class()."::saveboxorder zone=".$zone." userid=".$userid);
231 
232  if (!$userid || $userid == 0) return 0;
233 
234  $user = new User($db);
235  $user->id = $userid;
236 
237  $db->begin();
238 
239  // Save parameters to say user has a dedicated setup
240  $tab = array();
241  $confuserzone = 'MAIN_BOXES_'.$zone;
242  $tab[$confuserzone] = 1;
243  if (dol_set_user_param($db, $conf, $user, $tab) < 0)
244  {
245  $error = $db->lasterror();
246  $db->rollback();
247  return -3;
248  }
249 
250  // Delete all lines
251  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
252  $sql .= " WHERE entity = ".$conf->entity;
253  $sql .= " AND fk_user = ".$userid;
254  $sql .= " AND position = ".$zone;
255 
256  dol_syslog(get_class()."::saveboxorder", LOG_DEBUG);
257  $result = $db->query($sql);
258  if ($result)
259  {
260  $colonnes = explode('-', $boxorder);
261  foreach ($colonnes as $collist)
262  {
263  $part = explode(':', $collist);
264  $colonne = $part[0];
265  $list = $part[1];
266  dol_syslog(get_class()."::saveboxorder column=".$colonne.' list='.$list);
267 
268  $i = 0;
269  $listarray = explode(',', $list);
270  foreach ($listarray as $id)
271  {
272  if (is_numeric($id))
273  {
274  //dol_syslog("aaaaa".count($listarray));
275  $i++;
276  $ii = sprintf('%02d', $i);
277 
278  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes";
279  $sql .= "(box_id, position, box_order, fk_user, entity)";
280  $sql .= " values (";
281  $sql .= " ".$id.",";
282  $sql .= " ".$zone.",";
283  $sql .= " '".$db->escape($colonne.$ii)."',";
284  $sql .= " ".$userid.",";
285  $sql .= " ".$conf->entity;
286  $sql .= ")";
287 
288  dol_syslog(get_class()."::saveboxorder", LOG_DEBUG);
289  $result = $db->query($sql);
290  if ($result < 0)
291  {
292  $error++;
293  break;
294  }
295  }
296  }
297  }
298  } else {
299  $error++;
300  }
301 
302  if ($error)
303  {
304  $db->rollback();
305  return -2;
306  } else {
307  $db->commit();
308  return 1;
309  }
310  }
311 }
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
static getListOfPagesForBoxes()
Name of positions (See below)
Class to manage Dolibarr users.
Definition: user.class.php:44
static saveboxorder($db, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
static listBoxes($db, $mode, $zone, $user=null, $excludelist=array(), $includehidden=1)
Return array of boxes qualified for area and user.
Class to manage boxes on pages.
dol_set_user_param($db, $conf, &$user, $tab)
Save personnal parameter.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232