94 public static function listBoxes($dbs, $mode, $zone, $user =
null, $excludelist = array(), $includehidden = 1)
100 if ($mode ==
'activated') {
101 $sql =
"SELECT b.rowid, b.position, b.box_order, b.fk_user,";
102 $sql .=
" d.rowid as box_id, d.file, d.note, d.tms";
103 $sql .=
" FROM ".$dbs->prefix().
"boxes as b, ".$dbs->prefix().
"boxes_def as d";
104 $sql .=
" WHERE b.box_id = d.rowid";
105 $sql .=
" AND b.entity IN (0,".$conf->entity.
")";
107 $sql .=
" AND b.position = ".((int) $zone);
109 if (is_object($user)) {
110 $sql .=
" AND b.fk_user IN (0,".$user->id.
")";
112 $sql .=
" AND b.fk_user = 0";
114 $sql .=
" ORDER BY b.box_order";
116 $sql =
"SELECT d.rowid as box_id, d.file, d.note, d.tms";
117 $sql .=
" FROM ".$dbs->prefix().
"boxes_def as d";
118 $sql .=
" WHERE d.entity IN (0, ".$conf->entity.
")";
121 dol_syslog(get_class().
"::listBoxes get default box list for mode=".$mode.
" userid=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
122 $resql = $dbs->query($sql);
124 $num = $dbs->num_rows($resql);
127 $obj = $dbs->fetch_object($resql);
129 if (!in_array($obj->box_id, $excludelist)) {
131 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $obj->file, $regs)) {
132 $boxname = preg_replace(
'/\.php$/i',
'', $regs[1]);
134 $relsourcefile =
"/".$module.
"/core/boxes/".$boxname.
".php";
136 $boxname = preg_replace(
'/\.php$/i',
'', $obj->file);
137 $relsourcefile =
"/core/boxes/".$boxname.
".php";
146 if (class_exists($boxname)) {
147 $box =
new $boxname($dbs, $obj->note);
151 $box->rowid = (empty($obj->rowid) ?
'' : $obj->rowid);
152 $box->id = (empty($obj->box_id) ?
'' : $obj->box_id);
153 $box->position = ((isset($obj->position) && $obj->position ==
'') ?
'' : (isset($obj->position) ? $obj->position :
''));
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;
159 if ($mode ==
'activated' && !is_object($user)) {
160 if (is_numeric($box->box_order)) {
161 if ($box->box_order % 2 == 1) {
162 $box->box_order =
'A'.$box->box_order;
163 } elseif ($box->box_order % 2 == 0) {
164 $box->box_order =
'B'.$box->box_order;
169 $box->box_id = (empty($obj->box_id) ?
'' : $obj->box_id);
170 $box->note = (empty($obj->note) ?
'' : $obj->note);
174 $enabled = $box->enabled;
175 if (isset($box->depends) && count($box->depends) > 0) {
176 foreach ($box->depends as $moduleelem) {
177 $arrayelem = explode(
'|', $moduleelem);
179 foreach ($arrayelem as $module) {
180 $tmpmodule = preg_replace(
'/@[^@]+/',
'', $module);
181 if (!empty($conf->$tmpmodule->enabled)) {
186 if (empty($tmpenabled)) {
195 if ($enabled && ($includehidden || empty($box->hidden))) {
201 dol_syslog(
"Failed to load box '".$boxname.
"' into file '".$relsourcefile.
"'", LOG_WARNING);
208 return array(
'error'=>$dbs->lasterror());
224 public static function saveboxorder($dbs, $zone, $boxorder, $userid = 0)
230 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
232 dol_syslog(get_class().
"::saveboxorder zone=".$zone.
" userid=".$userid);
234 if (!$userid || $userid == 0) {
238 $user =
new User($dbs);
245 $confuserzone =
'MAIN_BOXES_'.$zone;
246 $tab[$confuserzone] = 1;
248 $error = $dbs->lasterror();
254 $sql =
"DELETE FROM ".$dbs->prefix().
"boxes";
255 $sql .=
" WHERE entity = ".$conf->entity;
256 $sql .=
" AND fk_user = ".((int) $userid);
257 $sql .=
" AND position = ".((int) $zone);
259 dol_syslog(get_class().
"::saveboxorder", LOG_DEBUG);
260 $result = $dbs->query($sql);
262 $colonnes = explode(
'-', $boxorder);
263 foreach ($colonnes as $collist) {
264 $part = explode(
':', $collist);
267 dol_syslog(get_class().
"::saveboxorder column=".$colonne.
' list='.$list);
270 $listarray = explode(
',', $list);
271 foreach ($listarray as $id) {
272 if (is_numeric($id)) {
275 $ii = sprintf(
'%02d', $i);
277 $sql =
"INSERT INTO ".$dbs->prefix().
"boxes";
278 $sql .=
"(box_id, position, box_order, fk_user, entity)";
280 $sql .=
" ".((int) $id).
",";
281 $sql .=
" ".((int) $zone).
",";
282 $sql .=
" '".$dbs->escape($colonne.$ii).
"',";
283 $sql .=
" ".((int) $userid).
",";
284 $sql .=
" ".((int) $conf->entity);
287 $result = $dbs->query($sql);