dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
32{
38 public static function getListOfPagesForBoxes()
39 {
40 global $conf;
41
42 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
43 return array(
44 0 => 'Home',
45 1 => 'UsersHome',
46 2 => 'MembersHome',
47 3 => 'ThirdpartiesHome',
48 4 => 'productindex',
49 6 => 'mrpindex',
50 8 => 'projectsindex',
51 9 => 'invoiceindex',
52 10 => 'hrmindex',
53 11 => 'TicketsHome',
54 20 => 'interventionindex',
55 27 => 'AccountancyHome',
56 28 => 'toolsindex',
57 29 => 'bankindex'
58 );
59 } else {
60 return array(
61 0 => 'Home',
62 1 => 'UsersHome',
63 2 => 'MembersHome',
64 3 => 'ThirdpartiesHome',
65 4 => 'productindex',
66 5 => 'productindex',
67 6 => 'mrpindex',
68 7 => 'commercialindex',
69 8 => 'projectsindex',
70 9 => 'invoiceindex',
71 10 => 'hrmindex',
72 11 => 'TicketsHome',
73 12 => 'stockindex',
74 13 => 'sendingindex',
75 14 => 'receptionindex',
76 15 => 'activityindex',
77 16 => 'proposalindex',
78 17 => 'ordersindex',
79 18 => 'orderssuppliersindex',
80 19 => 'contractindex',
81 20 => 'interventionindex',
82 21 => 'suppliersproposalsindex',
83 22 => 'donationindex',
84 23 => 'specialexpensesindex',
85 24 => 'expensereportindex',
86 25 => 'mailingindex',
87 26 => 'opensurveyindex',
88 27 => 'AccountancyHome',
89 28 => 'toolsindex',
90 29 => 'bankindex'
91 );
92 }
93 }
94
106 public static function listBoxes($dbs, $mode, $zone, $user = null, $excludelist = array(), $includehidden = 1)
107 {
108 global $conf;
109
110 $boxes = array();
111
112 if ($mode == 'activated') { // activated
113 $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,";
114 $sql .= " d.rowid as box_id, d.file, d.note, d.tms";
115 $sql .= " FROM ".$dbs->prefix()."boxes as b, ".$dbs->prefix()."boxes_def as d";
116 $sql .= " WHERE b.box_id = d.rowid";
117 $sql .= " AND b.entity IN (0,".((int) $conf->entity).")";
118 if ($zone >= 0) {
119 $sql .= " AND b.position = ".((int) $zone);
120 }
121 if (is_object($user)) {
122 $sql .= " AND b.fk_user IN (0,".((int) $user->id).")";
123 } else {
124 $sql .= " AND b.fk_user = 0";
125 }
126 $sql .= " ORDER BY b.box_order, b.fk_user";
127 } else { // available
128 $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms";
129 $sql .= " FROM ".$dbs->prefix()."boxes_def as d";
130 $sql .= " WHERE d.entity IN (0, ".((int) $conf->entity).")";
131 }
132
133 dol_syslog(self::class."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user) ? $user->id : ''), LOG_DEBUG);
134 $resql = $dbs->query($sql);
135 if ($resql) {
136 $num = $dbs->num_rows($resql);
137 $j = 0;
138 while ($j < $num) {
139 $obj = $dbs->fetch_object($resql);
140
141 if (!in_array($obj->box_id, $excludelist)) {
142 $regs = array();
143 if (preg_match('/^([^@]+)@([^@]+)$/i', $obj->file, $regs)) {
144 $boxname = preg_replace('/\.php$/i', '', $regs[1]);
145 $module = $regs[2];
146 $relsourcefile = "/".$module."/core/boxes/".$boxname.".php";
147 } else {
148 $boxname = preg_replace('/\.php$/i', '', $obj->file);
149 $relsourcefile = "/core/boxes/".$boxname.".php";
150 }
151
152 //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>';
153
154 // 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
155 // the "enabled" condition for modules forbidden for external users and the depends condition can be done.
156 // Goal is to avoid to make a "new" done for each boxes returned by select.
157 dol_include_once($relsourcefile);
158 if (class_exists($boxname)) {
159 $box = new $boxname($dbs, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params.
160 '@phan-var-force ModeleBoxes $box';
161 //$box=new stdClass();
162
163 // box properties
164 $box->rowid = (empty($obj->rowid) ? '' : $obj->rowid);
165 $box->id = (empty($obj->box_id) ? '' : $obj->box_id);
166 $box->position = ((isset($obj->position) && $obj->position == '') ? '' : (isset($obj->position) ? $obj->position : '')); // '0' must stay '0'
167 $box->box_order = (empty($obj->box_order) ? '' : $obj->box_order);
168 $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user);
169 $box->sourcefile = $relsourcefile;
170 $box->class = $boxname;
171
172 if ($mode == 'activated' && !is_object($user)) { // List of activated box was not yet personalized into database
173 if (is_numeric($box->box_order)) {
174 if (((int) $box->box_order % 2) == 1) {
175 $box->box_order = 'A'.$box->box_order;
176 } elseif (((int) $box->box_order % 2) == 0) {
177 $box->box_order = 'B'.$box->box_order;
178 }
179 }
180 }
181 // box_def properties
182 $box->box_id = (empty($obj->box_id) ? '' : $obj->box_id);
183 $box->note = (empty($obj->note) ? '' : $obj->note);
184
185 // Filter on box->enabled (used for example by box_comptes)
186 // Filter also on box->depends. Example: array("product|service") or array("contrat", "service")
187 $enabled = $box->enabled;
188 if (isset($box->depends) && count($box->depends) > 0) {
189 foreach ($box->depends as $moduleelem) {
190 $arrayelem = explode('|', $moduleelem);
191 $tmpenabled = 0; // $tmpenabled is used for the '|' test (OR)
192 foreach ($arrayelem as $module) {
193 $tmpmodule = preg_replace('/@[^@]+/', '', $module);
194 if (!empty($tmpmodule) && isModEnabled($tmpmodule)) {
195 $tmpenabled = 1;
196 }
197 //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>';
198 }
199 if (empty($tmpenabled)) { // We found at least one module required that is disabled
200 $enabled = 0;
201 break;
202 }
203 }
204 }
205 //print '=>'.$boxname.'-enabled='.$enabled.'<br>';
206
207 //print 'xx module='.$module.' enabled='.$enabled;
208 if ($enabled && ($includehidden || empty($box->hidden))) {
209 $boxes[] = $box;
210 } else {
211 unset($box);
212 }
213 } else {
214 dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING);
215 }
216 }
217 $j++;
218 }
219 } else {
220 dol_syslog($dbs->lasterror(), LOG_ERR);
221 return array('error' => $dbs->lasterror());
222 }
223
224 return $boxes;
225 }
226
227
237 public static function saveboxorder($dbs, $zone, $boxorder, $userid = 0)
238 {
239 global $conf;
240
241 $error = 0;
242
243 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
244
245 dol_syslog(self::class."::saveboxorder zone=".$zone." userid=".$userid);
246
247 if (!$userid || $userid == 0) {
248 return 0;
249 }
250
251 $user = new User($dbs);
252 $user->id = $userid;
253
254 $dbs->begin();
255
256 // Save parameters to say user has a dedicated setup
257 $tab = array();
258 $confuserzone = 'MAIN_BOXES_'.$zone;
259 $tab[$confuserzone] = '1';
260 if (dol_set_user_param($dbs, $conf, $user, $tab) < 0) {
261 $error = $dbs->lasterror();
262 $dbs->rollback();
263 return -3;
264 }
265
266 if (!is_numeric($zone)) {
267 $zone = '0'; // Force $zone to a numeric value string
268 }
269
270 // Delete all lines
271 $sql = "DELETE FROM ".$dbs->prefix()."boxes";
272 $sql .= " WHERE entity = ".((int) $conf->entity);
273 $sql .= " AND fk_user = ".((int) $userid);
274 $sql .= " AND position = ".((int) $zone);
275
276 dol_syslog(self::class."::saveboxorder", LOG_DEBUG);
277 $result = $dbs->query($sql);
278 if ($result) {
279 $colonnes = explode('-', $boxorder);
280 foreach ($colonnes as $collist) {
281 $part = explode(':', $collist);
282 $colonne = $part[0];
283 $list = $part[1];
284 dol_syslog(self::class."::saveboxorder column=".$colonne.' list='.$list);
285
286 $i = 0;
287 $listarray = explode(',', $list);
288 foreach ($listarray as $id) {
289 if (is_numeric($id)) {
290 //dol_syslog("aaaaa".count($listarray));
291 $i++;
292 $ii = sprintf('%02d', $i);
293
294 $sql = "INSERT INTO ".$dbs->prefix()."boxes";
295 $sql .= "(box_id, position, box_order, fk_user, entity)";
296 $sql .= " values (";
297 $sql .= " ".((int) $id).",";
298 $sql .= " ".((int) $zone).",";
299 $sql .= " '".$dbs->escape($colonne.$ii)."',";
300 $sql .= " ".((int) $userid).",";
301 $sql .= " ".((int) $conf->entity);
302 $sql .= ")";
303
304 $result = $dbs->query($sql);
305 if ($result < 0) {
306 $error++;
307 break;
308 }
309 }
310 }
311 }
312 } else {
313 $error++;
314 }
315
316 if ($error) {
317 $dbs->rollback();
318 return -2;
319 } else {
320 $dbs->commit();
321 return 1;
322 }
323 }
324}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
Class to manage boxes on pages.
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
static listBoxes($dbs, $mode, $zone, $user=null, $excludelist=array(), $includehidden=1)
Return array of boxes qualified for area and user.
static getListOfPagesForBoxes()
Name of positions (See below)
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_set_user_param($db, $conf, &$user, $tab, $entity=-1)
Save personal parameter.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.