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 );
58 } else {
59 return array(
60 0 => 'Home',
61 1 => 'UsersHome',
62 2 => 'MembersHome',
63 3 => 'ThirdpartiesHome',
64 4 => 'productindex',
65 5 => 'productindex',
66 6 => 'mrpindex',
67 7 => 'commercialindex',
68 8 => 'projectsindex',
69 9 => 'invoiceindex',
70 10 => 'hrmindex',
71 11 => 'TicketsHome',
72 12 => 'stockindex',
73 13 => 'sendingindex',
74 14 => 'receptionindex',
75 15 => 'activityindex',
76 16 => 'proposalindex',
77 17 => 'ordersindex',
78 18 => 'orderssuppliersindex',
79 19 => 'contractindex',
80 20 => 'interventionindex',
81 21 => 'suppliersproposalsindex',
82 22 => 'donationindex',
83 23 => 'specialexpensesindex',
84 24 => 'expensereportindex',
85 25 => 'mailingindex',
86 26 => 'opensurveyindex',
87 27 => 'AccountancyHome',
88 28 => 'toolsindex'
89 );
90 }
91 }
92
104 public static function listBoxes($dbs, $mode, $zone, $user = null, $excludelist = array(), $includehidden = 1)
105 {
106 global $conf;
107
108 $boxes = array();
109
110 if ($mode == 'activated') { // activated
111 $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,";
112 $sql .= " d.rowid as box_id, d.file, d.note, d.tms";
113 $sql .= " FROM ".$dbs->prefix()."boxes as b, ".$dbs->prefix()."boxes_def as d";
114 $sql .= " WHERE b.box_id = d.rowid";
115 $sql .= " AND b.entity IN (0,".((int) $conf->entity).")";
116 if ($zone >= 0) {
117 $sql .= " AND b.position = ".((int) $zone);
118 }
119 if (is_object($user)) {
120 $sql .= " AND b.fk_user IN (0,".((int) $user->id).")";
121 } else {
122 $sql .= " AND b.fk_user = 0";
123 }
124 $sql .= " ORDER BY b.box_order, b.fk_user";
125 } else { // available
126 $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms";
127 $sql .= " FROM ".$dbs->prefix()."boxes_def as d";
128 $sql .= " WHERE d.entity IN (0, ".((int) $conf->entity).")";
129 }
130
131 dol_syslog(self::class."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user) ? $user->id : ''), LOG_DEBUG);
132 $resql = $dbs->query($sql);
133 if ($resql) {
134 $num = $dbs->num_rows($resql);
135 $j = 0;
136 while ($j < $num) {
137 $obj = $dbs->fetch_object($resql);
138
139 if (!in_array($obj->box_id, $excludelist)) {
140 $regs = array();
141 if (preg_match('/^([^@]+)@([^@]+)$/i', $obj->file, $regs)) {
142 $boxname = preg_replace('/\.php$/i', '', $regs[1]);
143 $module = $regs[2];
144 $relsourcefile = "/".$module."/core/boxes/".$boxname.".php";
145 } else {
146 $boxname = preg_replace('/\.php$/i', '', $obj->file);
147 $relsourcefile = "/core/boxes/".$boxname.".php";
148 }
149
150 //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>';
151
152 // 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
153 // the "enabled" condition for modules forbidden for external users and the depends condition can be done.
154 // Goal is to avoid to make a "new" done for each boxes returned by select.
155 dol_include_once($relsourcefile);
156 if (class_exists($boxname)) {
157 $box = new $boxname($dbs, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params.
158 '@phan-var-force ModeleBoxes $box';
159 //$box=new stdClass();
160
161 // box properties
162 $box->rowid = (empty($obj->rowid) ? '' : $obj->rowid);
163 $box->id = (empty($obj->box_id) ? '' : $obj->box_id);
164 $box->position = ((isset($obj->position) && $obj->position == '') ? '' : (isset($obj->position) ? $obj->position : '')); // '0' must stay '0'
165 $box->box_order = (empty($obj->box_order) ? '' : $obj->box_order);
166 $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user);
167 $box->sourcefile = $relsourcefile;
168 $box->class = $boxname;
169
170 if ($mode == 'activated' && !is_object($user)) { // List of activated box was not yet personalized into database
171 if (is_numeric($box->box_order)) {
172 if (((int) $box->box_order % 2) == 1) {
173 $box->box_order = 'A'.$box->box_order;
174 } elseif (((int) $box->box_order % 2) == 0) {
175 $box->box_order = 'B'.$box->box_order;
176 }
177 }
178 }
179 // box_def properties
180 $box->box_id = (empty($obj->box_id) ? '' : $obj->box_id);
181 $box->note = (empty($obj->note) ? '' : $obj->note);
182
183 // Filter on box->enabled (used for example by box_comptes)
184 // Filter also on box->depends. Example: array("product|service") or array("contrat", "service")
185 $enabled = $box->enabled;
186 if (isset($box->depends) && count($box->depends) > 0) {
187 foreach ($box->depends as $moduleelem) {
188 $arrayelem = explode('|', $moduleelem);
189 $tmpenabled = 0; // $tmpenabled is used for the '|' test (OR)
190 foreach ($arrayelem as $module) {
191 $tmpmodule = preg_replace('/@[^@]+/', '', $module);
192 if (!empty($tmpmodule) && isModEnabled($tmpmodule)) {
193 $tmpenabled = 1;
194 }
195 //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>';
196 }
197 if (empty($tmpenabled)) { // We found at least one module required that is disabled
198 $enabled = 0;
199 break;
200 }
201 }
202 }
203 //print '=>'.$boxname.'-enabled='.$enabled.'<br>';
204
205 //print 'xx module='.$module.' enabled='.$enabled;
206 if ($enabled && ($includehidden || empty($box->hidden))) {
207 $boxes[] = $box;
208 } else {
209 unset($box);
210 }
211 } else {
212 dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING);
213 }
214 }
215 $j++;
216 }
217 } else {
218 dol_syslog($dbs->lasterror(), LOG_ERR);
219 return array('error' => $dbs->lasterror());
220 }
221
222 return $boxes;
223 }
224
225
235 public static function saveboxorder($dbs, $zone, $boxorder, $userid = 0)
236 {
237 global $conf;
238
239 $error = 0;
240
241 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
242
243 dol_syslog(self::class."::saveboxorder zone=".$zone." userid=".$userid);
244
245 if (!$userid || $userid == 0) {
246 return 0;
247 }
248
249 $user = new User($dbs);
250 $user->id = $userid;
251
252 $dbs->begin();
253
254 // Save parameters to say user has a dedicated setup
255 $tab = array();
256 $confuserzone = 'MAIN_BOXES_'.$zone;
257 $tab[$confuserzone] = '1';
258 if (dol_set_user_param($dbs, $conf, $user, $tab) < 0) {
259 $error = $dbs->lasterror();
260 $dbs->rollback();
261 return -3;
262 }
263
264 if (!is_numeric($zone)) {
265 $zone = '0'; // Force $zone to a numeric value string
266 }
267
268 // Delete all lines
269 $sql = "DELETE FROM ".$dbs->prefix()."boxes";
270 $sql .= " WHERE entity = ".((int) $conf->entity);
271 $sql .= " AND fk_user = ".((int) $userid);
272 $sql .= " AND position = ".((int) $zone);
273
274 dol_syslog(self::class."::saveboxorder", LOG_DEBUG);
275 $result = $dbs->query($sql);
276 if ($result) {
277 $colonnes = explode('-', $boxorder);
278 foreach ($colonnes as $collist) {
279 $part = explode(':', $collist);
280 $colonne = $part[0];
281 $list = $part[1];
282 dol_syslog(self::class."::saveboxorder column=".$colonne.' list='.$list);
283
284 $i = 0;
285 $listarray = explode(',', $list);
286 foreach ($listarray as $id) {
287 if (is_numeric($id)) {
288 //dol_syslog("aaaaa".count($listarray));
289 $i++;
290 $ii = sprintf('%02d', $i);
291
292 $sql = "INSERT INTO ".$dbs->prefix()."boxes";
293 $sql .= "(box_id, position, box_order, fk_user, entity)";
294 $sql .= " values (";
295 $sql .= " ".((int) $id).",";
296 $sql .= " ".((int) $zone).",";
297 $sql .= " '".$dbs->escape($colonne.$ii)."',";
298 $sql .= " ".((int) $userid).",";
299 $sql .= " ".((int) $conf->entity);
300 $sql .= ")";
301
302 $result = $dbs->query($sql);
303 if ($result < 0) {
304 $error++;
305 break;
306 }
307 }
308 }
309 }
310 } else {
311 $error++;
312 }
313
314 if ($error) {
315 $dbs->rollback();
316 return -2;
317 } else {
318 $dbs->commit();
319 return 1;
320 }
321 }
322}
$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(!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.