95 public static function listBoxes($dbs, $mode, $zone, $user =
null, $excludelist = array(), $includehidden = 1)
101 if ($mode ==
'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.
")";
108 $sql .=
" AND b.position = ".((int) $zone);
110 if (is_object($user)) {
111 $sql .=
" AND b.fk_user IN (0,".$user->id.
")";
113 $sql .=
" AND b.fk_user = 0";
115 $sql .=
" ORDER BY b.box_order";
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.
")";
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);
125 $num = $dbs->num_rows($resql);
128 $obj = $dbs->fetch_object($resql);
130 if (!in_array($obj->box_id, $excludelist)) {
132 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $obj->file, $regs)) {
133 $boxname = preg_replace(
'/\.php$/i',
'', $regs[1]);
135 $relsourcefile =
"/".$module.
"/core/boxes/".$boxname.
".php";
137 $boxname = preg_replace(
'/\.php$/i',
'', $obj->file);
138 $relsourcefile =
"/core/boxes/".$boxname.
".php";
147 if (class_exists($boxname)) {
148 $box =
new $boxname($dbs, $obj->note);
149 '@phan-var-force ModeleBoxes $box';
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 :
''));
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;
161 if ($mode ==
'activated' && !is_object($user)) {
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;
171 $box->box_id = (empty($obj->box_id) ?
'' : $obj->box_id);
172 $box->note = (empty($obj->note) ?
'' : $obj->note);
176 $enabled = $box->enabled;
177 if (isset($box->depends) && count($box->depends) > 0) {
178 foreach ($box->depends as $moduleelem) {
179 $arrayelem = explode(
'|', $moduleelem);
181 foreach ($arrayelem as $module) {
182 $tmpmodule = preg_replace(
'/@[^@]+/',
'', $module);
183 if (!empty($tmpmodule) && isModEnabled($tmpmodule)) {
188 if (empty($tmpenabled)) {
197 if ($enabled && ($includehidden || empty($box->hidden))) {
203 dol_syslog(
"Failed to load box '".$boxname.
"' into file '".$relsourcefile.
"'", LOG_WARNING);
210 return array(
'error' => $dbs->lasterror());
226 public static function saveboxorder($dbs, $zone, $boxorder, $userid = 0)
232 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
234 dol_syslog(self::class.
"::saveboxorder zone=".$zone.
" userid=".$userid);
236 if (!$userid || $userid == 0) {
240 $user =
new User($dbs);
247 $confuserzone =
'MAIN_BOXES_'.$zone;
248 $tab[$confuserzone] =
'1';
250 $error = $dbs->lasterror();
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);
261 dol_syslog(self::class.
"::saveboxorder", LOG_DEBUG);
262 $result = $dbs->query($sql);
264 $colonnes = explode(
'-', $boxorder);
265 foreach ($colonnes as $collist) {
266 $part = explode(
':', $collist);
269 dol_syslog(self::class.
"::saveboxorder column=".$colonne.
' list='.$list);
272 $listarray = explode(
',', $list);
273 foreach ($listarray as
$id) {
274 if (is_numeric(
$id)) {
277 $ii = sprintf(
'%02d', $i);
279 $sql =
"INSERT INTO ".$dbs->prefix().
"boxes";
280 $sql .=
"(box_id, position, box_order, fk_user, entity)";
282 $sql .=
" ".((int)
$id).
",";
283 $sql .=
" ".((int) $zone).
",";
284 $sql .=
" '".$dbs->escape($colonne.$ii).
"',";
285 $sql .=
" ".((int) $userid).
",";
286 $sql .=
" ".((int)
$conf->entity);
289 $result = $dbs->query($sql);