27require
'../main.inc.php';
28include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
30include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33$langs->loadLangs(array(
'admin',
'boxes',
'accountancy'));
39$rowid =
GETPOST(
'rowid',
'int');
40$action =
GETPOST(
'action',
'aZ09');
52if ($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') {
168 $objfrom->fetch(
GETPOST(
"switchfrom",
'int'));
171 $objto->fetch(
GETPOST(
'switchto',
'int'));
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 = 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);
217print
'<span class="opacitymedium">'.$langs->trans(
"BoxesDesc").
" ".$langs->trans(
"OnlyActiveElementsAreShown").
"</span><br>\n";
226$sql =
"SELECT b.rowid, b.box_id, b.position, b.box_order,";
227$sql .=
" bd.rowid as boxid";
228$sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes as b, ".MAIN_DB_PREFIX.
"boxes_def as bd";
229$sql .=
" WHERE b.box_id = bd.rowid";
230$sql .=
" AND b.entity IN (0,".$conf->entity.
")";
231$sql .=
" AND b.fk_user=0";
232$sql .=
" ORDER by b.position, b.box_order";
235dol_syslog(
"Search available boxes", LOG_DEBUG);
236$resql = $db->query($sql);
238 $num = $db->num_rows($resql);
244 $obj = $db->fetch_object($resql);
245 $boxes[$obj->position][$obj->box_id] = 1;
248 array_push($actives, $obj->box_id);
250 if ($obj->box_order ==
'' || $obj->box_order ==
'0' || $decalage) {
256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($decalage).
"' WHERE rowid=".((int) $obj->rowid);
264 $sql =
"SELECT box_order";
265 $sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes";
266 $sql .=
" WHERE entity = ".$conf->entity;
267 $sql .=
" AND LENGTH(box_order) <= 2";
269 dol_syslog(
"Execute requests to renumber box order", LOG_DEBUG);
270 $result = $db->query($sql);
272 while ($record = $db->fetch_array($result)) {
274 if (preg_match(
"/[13579]{1}/", substr($record[
'box_order'], -1))) {
275 $box_order =
"A0".$record[
'box_order'];
276 $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']).
"'";
277 $resql = $db->query($sql);
278 } elseif (preg_match(
"/[02468]{1}/", substr($record[
'box_order'], -1))) {
279 $box_order =
"B0".$record[
'box_order'];
280 $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']).
"'";
281 $resql = $db->query($sql);
283 } elseif (
dol_strlen($record[
'box_order']) == 2) {
284 if (preg_match(
"/[13579]{1}/", substr($record[
'box_order'], -1))) {
285 $box_order =
"A".$record[
'box_order'];
286 $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']).
"'";
287 $resql = $db->query($sql);
288 } elseif (preg_match(
"/[02468]{1}/", substr($record[
'box_order'], -1))) {
289 $box_order =
"B".$record[
'box_order'];
290 $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']).
"'";
291 $resql = $db->query($sql);
305print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
306print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
307print
'<input type="hidden" name="action" value="add">'.
"\n";
312print
'<div class="div-table-responsive-no-min">';
313print
'<table class="tagtable liste centpercent">'.
"\n";
315print
'<tr class="liste_titre">';
316print
'<td>'.$langs->trans(
"Box").
'</td>';
317print
'<td>'.$langs->trans(
"Note").
'/'.$langs->trans(
"Parameters").
'</td>';
319print
'<td class="center" width="160">'.$langs->trans(
"ActivatableOn").
'</td>';
320print
'<td class="center" width="60" colspan="2">'.$langs->trans(
"PositionByDefault").
'</td>';
321print
'<td class="center" width="80">'.$langs->trans(
"Disable").
'</td>';
324print
"\n\n".
'<!-- Boxes Available -->'.
"\n";
325foreach ($boxtoadd as $box) {
326 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $box->boximg)) {
327 $logo = $box->boximg;
329 $logo = preg_replace(
"/^object_/i",
"", $box->boximg);
332 print
"\n".
'<!-- Box '.$box->boxcode.
' -->'.
"\n";
333 print
'<tr class="oddeven" style="height:3em !important;">'.
"\n";
334 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv($box->boxlabel)).
'">'.
img_object(
"", $logo,
'class="pictofixedwidth" height="14px"').
' '.$langs->transnoentitiesnoconv($box->boxlabel);
335 if (!empty($box->class) && preg_match(
'/graph_/', $box->class)) {
336 print
img_picto(
'',
'graph',
'class="paddingleft"');
338 if (!empty($box->version)) {
339 if ($box->version ==
'experimental') {
340 print
' <span class="opacitymedium">('.$langs->trans(
"Experimental").
')</span>';
341 } elseif ($box->version ==
'development') {
342 print
' <span class="opacitymedium">('.$langs->trans(
"Development").
')</span>';
346 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($box->note).
'">';
347 if ($box->note ==
'(WarningUsingThisBoxSlowDown)') {
348 $langs->load(
"errors");
349 print $langs->trans(
"WarningUsingThisBoxSlowDown");
351 print($box->note ? $box->note :
' ');
355 print $form->textwithpicto(
'', $langs->trans(
"SourceFile").
' : '.$box->sourcefile);
359 print
'<td class="center">';
360 print $form->selectarray(
"boxid[".$box->box_id.
"][pos]", $arrayofhomepages, -1, 1, 0, 0,
'', 1, 0, 0,
'',
'minwidth75', 1).
"\n";
361 print
'<input type="hidden" name="boxid['.$box->box_id.
'][value]" value="'.$box->box_id.
'">'.
"\n";
371 print
'<input type="submit" class="button small smallpaddingimp" value="'.$langs->trans(
"Activate").
'">';
376print
"\n".
'<!-- End Boxes Available -->'.
"\n";
381foreach ($boxactivated as $key => $box) {
382 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $box->boximg)) {
383 $logo = $box->boximg;
385 $logo = preg_replace(
"/^object_/i",
"", $box->boximg);
388 print
"\n".
'<!-- Box '.$box->boxcode.
' -->'.
"\n";
389 print
'<tr class="oddeven" style="height:3em !important;">';
390 print
'<td>'.img_object(
"", $logo,
'class="pictofixedwidth" height="14px"').
' '.$langs->transnoentitiesnoconv($box->boxlabel);
391 if (!empty($box->class) && preg_match(
'/graph_/', $box->class)) {
392 print
img_picto(
'',
'graph',
'class="paddingleft"');
394 if (!empty($box->version)) {
395 if ($box->version ==
'experimental') {
396 print
' <span class="opacitymedium">('.$langs->trans(
"Experimental").
')</span>';
397 } elseif ($box->version ==
'development') {
398 print
' <span class="opacitymedium">('.$langs->trans(
"Development").
')</span>';
402 $langs->load(
"errors");
403 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($box->note ==
'(WarningUsingThisBoxSlowDown)' ? $langs->trans(
"WarningUsingThisBoxSlowDown") : $box->note).
'">';
404 if ($box->note ==
'(WarningUsingThisBoxSlowDown)') {
405 print
img_warning(
'', 0).
' '.$langs->trans(
"WarningUsingThisBoxSlowDown");
407 print($box->note ? $box->note :
' ');
411 print $form->textwithpicto(
'', $langs->trans(
"SourceFile").
' : '.$box->sourcefile);
413 print
'<td class="center">'.(empty($arrayofhomepages[$box->position]) ?
'' : $langs->trans($arrayofhomepages[$box->position])).
'</td>';
414 $hasnext = ($key < (count($boxactivated) - 1));
415 $hasprevious = ($key != 0);
416 print
'<td class="center">'.($key + 1).
'</td>';
417 print
'<td class="center nowraponall">';
418 print($hasnext ?
'<a class="reposition" href="boxes.php?action=switch&token='.newToken().
'&switchfrom='.$box->rowid.
'&switchto='.$boxactivated[$key + 1]->rowid.
'">'.
img_down().
'</a> ' :
'');
419 print($hasprevious ?
'<a class="reposition" href="boxes.php?action=switch&token='.newToken().
'&switchfrom='.$box->rowid.
'&switchto='.$boxactivated[$key - 1]->rowid.
'">'.
img_up().
'</a>' :
'');
421 print
'<td class="center">';
422 print
'<a class="reposition" href="boxes.php?rowid='.$box->rowid.
'&action=delete&token='.newToken().
'">'.
img_delete().
'</a>';
437print
"\n\n".
'<!-- Other Const -->'.
"\n";
439print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
440print
'<input type="hidden" name="token" value="'.newToken().
'">';
441print
'<input type="hidden" name="action" value="addconst">';
442print
'<input type="hidden" name="page_y" value="">';
443print
'<div class="div-table-responsive-no-min">';
444print
'<table class="noborder centpercent">';
446print
'<tr class="liste_titre">';
447print
'<td class="liste_titre">'.$langs->trans(
"Parameter").
'</td>';
448print
'<td class="liste_titre">'.$langs->trans(
"Value").
'</td>';
451print
'<tr class="oddeven">';
453print $langs->trans(
"MaxNbOfLinesForBoxes");
456print
'<input type="text" class="flat" size="6" name="MAIN_BOXES_MAXLINES" value="'.(getDolGlobalString(
'MAIN_BOXES_MAXLINES')).
'">';
461print
'<tr class="oddeven"><td>'.$langs->trans(
"EnableFileCache").
'</td><td>';
462print $form->selectyesno(
'MAIN_ACTIVATE_FILECACHE',
getDolGlobalInt(
'MAIN_ACTIVATE_FILECACHE', 0), 1);
469print $form->buttonsSaveCancel(
"Save",
'', array(), 0,
'reposition');
472print
"\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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.