28require
'../main.inc.php';
29include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
31include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
34$langs->loadLangs(array(
'admin',
'boxes',
'accountancy'));
41$action =
GETPOST(
'action',
'aZ09');
53if ($action ==
'addconst') {
54 dolibarr_set_const($db,
"MAIN_ACTIVATE_FILECACHE",
GETPOST(
"MAIN_ACTIVATE_FILECACHE",
'alpha'),
'chaine', 0,
'', $conf->entity);
57if ($action ==
'add') {
59 $boxids =
GETPOST(
'boxid',
'array');
62 if (is_array($boxids)) {
63 foreach ($boxids as $boxid) {
64 if (is_numeric($boxid[
'pos']) && $boxid[
'pos'] >= 0) {
68 $distinctfkuser = array();
70 $sql =
"SELECT fk_user";
71 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_param";
72 $sql .=
" WHERE param = 'MAIN_BOXES_".$db->escape($pos).
"' AND value = '1'";
73 $sql .=
" AND entity = ".$conf->entity;
74 dol_syslog(
"boxes.php search fk_user to activate box for", LOG_DEBUG);
75 $resql = $db->query($sql);
77 $num = $db->num_rows($resql);
80 $obj = $db->fetch_object($resql);
81 $distinctfkuser[$obj->fk_user] = $obj->fk_user;
90 $distinctfkuser[
'0'] =
'0';
92 foreach ($distinctfkuser as $fk_user) {
93 if (!$error && $fk_user !=
'') {
94 $arrayofexistingboxid = array();
95 $nbboxonleft = $nbboxonright = 0;
96 $sql =
"SELECT box_id, box_order FROM ".MAIN_DB_PREFIX.
"boxes";
97 $sql .=
" WHERE position = ".((int) $pos).
" AND fk_user = ".((int) $fk_user).
" AND entity = ".((int) $conf->entity);
98 dol_syslog(
"boxes.php activate box", LOG_DEBUG);
99 $resql = $db->query($sql);
101 while ($obj = $db->fetch_object($resql)) {
102 $boxorder = $obj->box_order;
103 if (preg_match(
'/A/', $boxorder)) {
106 if (preg_match(
'/B/', $boxorder)) {
109 $arrayofexistingboxid[$obj->box_id] = 1;
115 if (empty($arrayofexistingboxid[$boxid[
'value']])) {
116 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes (";
117 $sql .=
"box_id, position, box_order, fk_user, entity";
118 $sql .=
") VALUES (";
119 $sql .= ((int) $boxid[
'value']).
", ".((int) $pos).
", '".(($nbboxonleft > $nbboxonright) ?
'B01' :
'A01').
"', ".((int) $fk_user).
", ".$conf->entity;
122 dol_syslog(
"boxes.php activate box", LOG_DEBUG);
123 $resql = $db->query($sql);
129 dol_syslog(
"boxes.php activate box - already exists in database", LOG_DEBUG);
144if ($action ==
'delete') {
145 $sql =
"SELECT box_id FROM ".MAIN_DB_PREFIX.
"boxes";
146 $sql .=
" WHERE rowid=".((int) $rowid);
148 $resql = $db->query($sql);
149 $obj = $db->fetch_object($resql);
150 if (!empty($obj->box_id)) {
153 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
154 $sql .=
" WHERE entity = ".$conf->entity;
155 $sql .=
" AND box_id=".((int) $obj->box_id);
157 $resql = $db->query($sql);
163if ($action ==
'switch') {
173 $resultupdatefrom = 0;
175 if (is_object($objfrom) && is_object($objto)) {
176 $newfirst = $objto->box_order;
177 $newsecond = $objfrom->box_order;
178 if ($newfirst == $newsecond) {
179 $newsecondchar = preg_replace(
'/[0-9]+/',
'', $newsecond);
180 $newsecondnum = (int) preg_replace(
'/[a-zA-Z]+/',
'', $newsecond);
181 $newsecond = sprintf(
"%s%02d", $newsecondchar ? $newsecondchar :
'A', $newsecondnum + 1);
184 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($newfirst).
"' WHERE rowid=".((int) $objfrom->rowid);
186 $resultupdatefrom = $db->query($sql);
187 if (!$resultupdatefrom) {
191 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($newsecond).
"' WHERE rowid=".((int) $objto->rowid);
193 $resultupdateto = $db->query($sql);
194 if (!$resultupdateto) {
199 if ($resultupdatefrom && $resultupdateto) {
211$form =
new Form($db);
213llxHeader(
'', $langs->trans(
"Boxes"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-boxes');
217print
'<span class="opacitymedium">'.$langs->trans(
"BoxesDesc").
" ".$langs->trans(
"OnlyActiveElementsAreShown").
"</span><br>\n";
227$sql =
"SELECT b.rowid, b.box_id, b.position, b.box_order,";
228$sql .=
" bd.rowid as boxid";
229$sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes as b, ".MAIN_DB_PREFIX.
"boxes_def as bd";
230$sql .=
" WHERE b.box_id = bd.rowid";
231$sql .=
" AND b.entity IN (0,".$conf->entity.
")";
232$sql .=
" AND b.fk_user=0";
233$sql .=
" ORDER by b.position, b.box_order";
236dol_syslog(
"Search available boxes", LOG_DEBUG);
237$resql = $db->query($sql);
239 $num = $db->num_rows($resql);
245 $obj = $db->fetch_object($resql);
246 $boxes[$obj->position][$obj->box_id] = 1;
249 array_push($actives, $obj->box_id);
251 if ($obj->box_order ==
'' || $obj->box_order ==
'0' || $decalage) {
257 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($decalage).
"' WHERE rowid=".((int) $obj->rowid);
265 $sql =
"SELECT box_order";
266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes";
267 $sql .=
" WHERE entity = ".$conf->entity;
268 $sql .=
" AND LENGTH(box_order) <= 2";
270 dol_syslog(
"Execute requests to renumber box order", LOG_DEBUG);
271 $result = $db->query($sql);
273 while ($record = $db->fetch_array($result)) {
275 if (preg_match(
"/[13579]{1}/", substr($record[
'box_order'], -1))) {
276 $box_order =
"A0".$record[
'box_order'];
277 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order = '".$db->escape($box_order).
"' WHERE entity = ".$conf->entity.
" AND box_order = '".$db->escape($record[
'box_order']).
"'";
278 $resql = $db->query($sql);
279 } elseif (preg_match(
"/[02468]{1}/", substr($record[
'box_order'], -1))) {
280 $box_order =
"B0".$record[
'box_order'];
281 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order = '".$db->escape($box_order).
"' WHERE entity = ".$conf->entity.
" AND box_order = '".$db->escape($record[
'box_order']).
"'";
282 $resql = $db->query($sql);
284 } elseif (
dol_strlen($record[
'box_order']) == 2) {
285 if (preg_match(
"/[13579]{1}/", substr($record[
'box_order'], -1))) {
286 $box_order =
"A".$record[
'box_order'];
287 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order = '".$db->escape($box_order).
"' WHERE entity = ".$conf->entity.
" AND box_order = '".$db->escape($record[
'box_order']).
"'";
288 $resql = $db->query($sql);
289 } elseif (preg_match(
"/[02468]{1}/", substr($record[
'box_order'], -1))) {
290 $box_order =
"B".$record[
'box_order'];
291 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order = '".$db->escape($box_order).
"' WHERE entity = ".$conf->entity.
" AND box_order = '".$db->escape($record[
'box_order']).
"'";
292 $resql = $db->query($sql);
306print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
307print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
308print
'<input type="hidden" name="action" value="add">'.
"\n";
313print
'<div class="div-table-responsive-no-min">';
314print
'<table class="tagtable liste centpercent">'.
"\n";
316print
'<tr class="liste_titre">';
317print
'<td>'.$langs->trans(
"Box").
'</td>';
318print
'<td>'.$langs->trans(
"Note").
'/'.$langs->trans(
"Parameters").
'</td>';
320print
'<td class="center" width="160">'.$langs->trans(
"ActivatableOn").
'</td>';
321print
'<td class="center" width="60" colspan="2">'.$langs->trans(
"PositionByDefault").
'</td>';
322print
'<td class="center" width="80">'.$langs->trans(
"Disable").
'</td>';
325print
"\n\n".
'<!-- Boxes Available -->'.
"\n";
326foreach ($boxtoadd as $box) {
327 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $box->boximg)) {
328 $logo = $box->boximg;
330 $logo = preg_replace(
"/^object_/i",
"", $box->boximg);
333 print
"\n".
'<!-- Box '.$box->boxcode.
' -->'.
"\n";
334 print
'<tr class="oddeven" style="height:3em !important;">'.
"\n";
335 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv($box->boxlabel)).
'">'.
img_object(
"", $logo,
'class="pictofixedwidth" height="14px"').
' '.$langs->transnoentitiesnoconv($box->boxlabel);
336 if (!empty($box->class) && preg_match(
'/graph_/', $box->class)) {
337 print
img_picto(
'',
'graph',
'class="paddingleft"');
339 if (!empty($box->version)) {
340 if ($box->version ==
'experimental') {
341 print
' <span class="opacitymedium">('.$langs->trans(
"Experimental").
')</span>';
342 } elseif ($box->version ==
'development') {
343 print
' <span class="opacitymedium">('.$langs->trans(
"Development").
')</span>';
347 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($box->note).
'">';
348 if ($box->note ==
'(WarningUsingThisBoxSlowDown)') {
349 $langs->load(
"errors");
350 print $langs->trans(
"WarningUsingThisBoxSlowDown");
352 print($box->note ? $box->note :
' ');
356 print $form->textwithpicto(
'', $langs->trans(
"SourceFile").
' : '.$box->sourcefile);
360 print
'<td class="center">';
361 print $form->selectarray(
"boxid[".$box->box_id.
"][pos]", $arrayofhomepages, -1, 1, 0, 0,
'', 1, 0, 0,
'',
'minwidth75', 1).
"\n";
362 print
'<input type="hidden" name="boxid['.$box->box_id.
'][value]" value="'.$box->box_id.
'">'.
"\n";
372 print
'<input type="submit" class="button small smallpaddingimp" value="'.$langs->trans(
"Activate").
'">';
377print
"\n".
'<!-- End Boxes Available -->'.
"\n";
382foreach ($boxactivated as $key => $box) {
383 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $box->boximg)) {
384 $logo = $box->boximg;
386 $logo = preg_replace(
"/^object_/i",
"", $box->boximg);
389 print
"\n".
'<!-- Box '.$box->boxcode.
' -->'.
"\n";
390 print
'<tr class="oddeven" style="height:3em !important;">';
391 print
'<td>'.img_object(
"", $logo,
'class="pictofixedwidth" height="14px"').
' '.$langs->transnoentitiesnoconv($box->boxlabel);
392 if (!empty($box->class) && preg_match(
'/graph_/', $box->class)) {
393 print
img_picto(
'',
'graph',
'class="paddingleft"');
395 if (!empty($box->version)) {
396 if ($box->version ==
'experimental') {
397 print
' <span class="opacitymedium">('.$langs->trans(
"Experimental").
')</span>';
398 } elseif ($box->version ==
'development') {
399 print
' <span class="opacitymedium">('.$langs->trans(
"Development").
')</span>';
403 $langs->load(
"errors");
404 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($box->note ==
'(WarningUsingThisBoxSlowDown)' ? $langs->trans(
"WarningUsingThisBoxSlowDown") : $box->note).
'">';
405 if ($box->note ==
'(WarningUsingThisBoxSlowDown)') {
406 print
img_warning(
'', 0).
' '.$langs->trans(
"WarningUsingThisBoxSlowDown");
408 print($box->note ? $box->note :
' ');
412 print $form->textwithpicto(
'', $langs->trans(
"SourceFile").
' : '.$box->sourcefile);
414 print
'<td class="center">'.(empty($arrayofhomepages[$box->position]) ?
'' : $langs->trans($arrayofhomepages[$box->position])).
'</td>';
415 $hasnext = ($key < (count($boxactivated) - 1));
416 $hasprevious = ($key != 0);
417 print
'<td class="center">'.($key + 1).
'</td>';
418 print
'<td class="center nowraponall">';
419 print($hasnext ?
'<a class="reposition" href="boxes.php?action=switch&token='.
newToken().
'&switchfrom='.$box->rowid.
'&switchto='.$boxactivated[$key + 1]->rowid.
'">'.
img_down().
'</a> ' :
'');
420 print($hasprevious ?
'<a class="reposition" href="boxes.php?action=switch&token='.
newToken().
'&switchfrom='.$box->rowid.
'&switchto='.$boxactivated[$key - 1]->rowid.
'">'.
img_up().
'</a>' :
'');
422 print
'<td class="center">';
423 print
'<a class="reposition" href="boxes.php?rowid='.$box->rowid.
'&action=delete&token='.
newToken().
'">'.
img_delete().
'</a>';
438print
"\n\n".
'<!-- Other Const -->'.
"\n";
440print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
441print
'<input type="hidden" name="token" value="'.newToken().
'">';
442print
'<input type="hidden" name="action" value="addconst">';
443print
'<input type="hidden" name="page_y" value="">';
444print
'<div class="div-table-responsive-no-min">';
445print
'<table class="noborder centpercent">';
447print
'<tr class="liste_titre">';
448print
'<td class="liste_titre">'.$langs->trans(
"Parameter").
'</td>';
449print
'<td class="liste_titre">'.$langs->trans(
"Value").
'</td>';
453print
'<tr class="oddeven"><td>'.$langs->trans(
"EnableFileCache").
'</td><td>';
454print $form->selectyesno(
'MAIN_ACTIVATE_FILECACHE',
getDolGlobalInt(
'MAIN_ACTIVATE_FILECACHE', 0), 1);
461print $form->buttonsSaveCancel(
"Save",
'', array(), 0,
'reposition');
464print
"\n".
'<!-- End Other Const -->'.
"\n";
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
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)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.