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