29require
'../main.inc.php';
30include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
32include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
35$langs->loadLangs(array(
'admin',
'boxes',
'accountancy'));
42$action =
GETPOST(
'action',
'aZ09');
54if ($action ==
'addconst') {
55 dolibarr_set_const($db,
"MAIN_ACTIVATE_FILECACHE",
GETPOST(
"MAIN_ACTIVATE_FILECACHE",
'alpha'),
'chaine', 0,
'', $conf->entity);
58if ($action ==
'add') {
60 $boxids =
GETPOST(
'boxid',
'array');
63 if (is_array($boxids)) {
64 foreach ($boxids as $boxid) {
65 if (is_numeric($boxid[
'pos']) && $boxid[
'pos'] >= 0) {
69 $distinctfkuser = array();
71 $sql =
"SELECT fk_user";
72 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_param";
73 $sql .=
" WHERE param = 'MAIN_BOXES_".$db->escape($pos).
"' AND value = '1'";
74 $sql .=
" AND entity = ".$conf->entity;
75 dol_syslog(
"boxes.php search fk_user to activate box for", LOG_DEBUG);
76 $resql = $db->query($sql);
78 $num = $db->num_rows($resql);
81 $obj = $db->fetch_object($resql);
82 $distinctfkuser[$obj->fk_user] = $obj->fk_user;
91 $distinctfkuser[
'0'] =
'0';
93 foreach ($distinctfkuser as $fk_user) {
94 if (!$error && $fk_user !=
'') {
95 $arrayofexistingboxid = array();
96 $nbboxonleft = $nbboxonright = 0;
97 $sql =
"SELECT box_id, box_order FROM ".MAIN_DB_PREFIX.
"boxes";
98 $sql .=
" WHERE position = ".((int) $pos).
" AND fk_user = ".((int) $fk_user).
" AND entity = ".((int) $conf->entity);
99 dol_syslog(
"boxes.php activate box", LOG_DEBUG);
100 $resql = $db->query($sql);
102 while ($obj = $db->fetch_object($resql)) {
103 $boxorder = $obj->box_order;
104 if (preg_match(
'/A/', $boxorder)) {
107 if (preg_match(
'/B/', $boxorder)) {
110 $arrayofexistingboxid[$obj->box_id] = 1;
116 if (empty($arrayofexistingboxid[$boxid[
'value']])) {
117 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes (";
118 $sql .=
"box_id, position, box_order, fk_user, entity";
119 $sql .=
") VALUES (";
120 $sql .= ((int) $boxid[
'value']).
", ".((int) $pos).
", '".(($nbboxonleft > $nbboxonright) ?
'B01' :
'A01').
"', ".((int) $fk_user).
", ".$conf->entity;
123 dol_syslog(
"boxes.php activate box", LOG_DEBUG);
124 $resql = $db->query($sql);
130 dol_syslog(
"boxes.php activate box - already exists in database", LOG_DEBUG);
145if ($action ==
'delete') {
146 $sql =
"SELECT box_id FROM ".MAIN_DB_PREFIX.
"boxes";
147 $sql .=
" WHERE rowid=".((int) $rowid);
149 $resql = $db->query($sql);
150 $obj = $db->fetch_object($resql);
151 if (!empty($obj->box_id)) {
154 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
155 $sql .=
" WHERE entity = ".$conf->entity;
156 $sql .=
" AND box_id=".((int) $obj->box_id);
158 $resql = $db->query($sql);
164if ($action ==
'switch') {
174 $resultupdatefrom = 0;
176 if (is_object($objfrom) && is_object($objto)) {
177 $newfirst = $objto->box_order;
178 $newsecond = $objfrom->box_order;
179 if ($newfirst == $newsecond) {
180 $newsecondchar = preg_replace(
'/[0-9]+/',
'', $newsecond);
181 $newsecondnum = (int) preg_replace(
'/[a-zA-Z]+/',
'', $newsecond);
182 $newsecond = sprintf(
"%s%02d", $newsecondchar ? $newsecondchar :
'A', $newsecondnum + 1);
185 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($newfirst).
"' WHERE rowid=".((int) $objfrom->rowid);
187 $resultupdatefrom = $db->query($sql);
188 if (!$resultupdatefrom) {
192 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($newsecond).
"' WHERE rowid=".((int) $objto->rowid);
194 $resultupdateto = $db->query($sql);
195 if (!$resultupdateto) {
200 if ($resultupdatefrom && $resultupdateto) {
212$form =
new Form($db);
214llxHeader(
'', $langs->trans(
"Boxes"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-boxes');
218print
'<span class="opacitymedium">'.$langs->trans(
"BoxesDesc").
" ".$langs->trans(
"OnlyActiveElementsAreShown").
"</span><br>\n";
228$sql =
"SELECT b.rowid, b.box_id, b.position, b.box_order,";
229$sql .=
" bd.rowid as boxid";
230$sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes as b, ".MAIN_DB_PREFIX.
"boxes_def as bd";
231$sql .=
" WHERE b.box_id = bd.rowid";
232$sql .=
" AND b.entity IN (0,".$conf->entity.
")";
233$sql .=
" AND b.fk_user=0";
234$sql .=
" ORDER by b.position, b.box_order";
237dol_syslog(
"Search available boxes", LOG_DEBUG);
238$resql = $db->query($sql);
240 $num = $db->num_rows($resql);
246 $obj = $db->fetch_object($resql);
247 $boxes[$obj->position][$obj->box_id] = 1;
250 array_push($actives, $obj->box_id);
252 if ($obj->box_order ==
'' || $obj->box_order ==
'0' || $decalage) {
258 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"boxes SET box_order='".$db->escape($decalage).
"' WHERE rowid=".((int) $obj->rowid);
266 $sql =
"SELECT box_order";
267 $sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes";
268 $sql .=
" WHERE entity = ".$conf->entity;
269 $sql .=
" AND LENGTH(box_order) <= 2";
271 dol_syslog(
"Execute requests to renumber box order", LOG_DEBUG);
272 $result = $db->query($sql);
274 while ($record = $db->fetch_array($result)) {
276 if (preg_match(
"/[13579]{1}/", substr($record[
'box_order'], -1))) {
277 $box_order =
"A0".$record[
'box_order'];
278 $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']).
"'";
279 $resql = $db->query($sql);
280 } elseif (preg_match(
"/[02468]{1}/", substr($record[
'box_order'], -1))) {
281 $box_order =
"B0".$record[
'box_order'];
282 $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']).
"'";
283 $resql = $db->query($sql);
285 } elseif (
dol_strlen($record[
'box_order']) == 2) {
286 if (preg_match(
"/[13579]{1}/", substr($record[
'box_order'], -1))) {
287 $box_order =
"A".$record[
'box_order'];
288 $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']).
"'";
289 $resql = $db->query($sql);
290 } elseif (preg_match(
"/[02468]{1}/", substr($record[
'box_order'], -1))) {
291 $box_order =
"B".$record[
'box_order'];
292 $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']).
"'";
293 $resql = $db->query($sql);
307print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
308print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
309print
'<input type="hidden" name="action" value="add">'.
"\n";
314print
'<div class="div-table-responsive-no-min">';
315print
'<table class="tagtable liste centpercent">'.
"\n";
317print
'<tr class="liste_titre">';
318print
'<td>'.$langs->trans(
"Box").
'</td>';
319print
'<td>'.$langs->trans(
"Note").
'/'.$langs->trans(
"Parameters").
'</td>';
321print
'<td class="center" width="160">'.$langs->trans(
"ActivatableOn").
'</td>';
322print
'<td class="center" width="60" colspan="2">'.$langs->trans(
"PositionByDefault").
'</td>';
323print
'<td class="center" width="80">'.$langs->trans(
"Disable").
'</td>';
326print
"\n\n".
'<!-- Boxes Available -->'.
"\n";
327foreach ($boxtoadd as $box) {
328 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $box->boximg)) {
329 $logo = $box->boximg;
331 $logo = preg_replace(
"/^object_/i",
"", $box->boximg);
334 print
"\n".
'<!-- Box '.$box->boxcode.
' -->'.
"\n";
335 print
'<tr class="oddeven" style="height:3em !important;">'.
"\n";
336 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv($box->boxlabel)).
'">'.
img_object(
"", $logo,
'class="pictofixedwidth" height="14px"').
' '.$langs->transnoentitiesnoconv($box->boxlabel);
337 if (!empty($box->class) && preg_match(
'/graph_/', $box->class)) {
338 print
img_picto(
'',
'graph',
'class="paddingleft"');
340 if (!empty($box->version)) {
341 if ($box->version ==
'experimental') {
342 print
' <span class="opacitymedium">('.$langs->trans(
"Experimental").
')</span>';
343 } elseif ($box->version ==
'development') {
344 print
' <span class="opacitymedium">('.$langs->trans(
"Development").
')</span>';
348 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($box->note).
'">';
349 if ($box->note ==
'(WarningUsingThisBoxSlowDown)') {
350 $langs->load(
"errors");
351 print $langs->trans(
"WarningUsingThisBoxSlowDown");
353 print($box->note ? $box->note :
' ');
357 print $form->textwithpicto(
'', $langs->trans(
"SourceFile").
' : '.$box->sourcefile);
361 print
'<td class="center">';
362 print $form->selectarray(
"boxid[".$box->box_id.
"][pos]", $arrayofhomepages, -1, 1, 0, 0,
'', 1, 0, 0,
'',
'minwidth75', 1).
"\n";
363 print
'<input type="hidden" name="boxid['.$box->box_id.
'][value]" value="'.$box->box_id.
'">'.
"\n";
373 print
'<input type="submit" class="button small smallpaddingimp" value="'.$langs->trans(
"Activate").
'">';
378print
"\n".
'<!-- End Boxes Available -->'.
"\n";
383foreach ($boxactivated as $key => $box) {
384 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $box->boximg)) {
385 $logo = $box->boximg;
387 $logo = preg_replace(
"/^object_/i",
"", $box->boximg);
390 print
"\n".
'<!-- Box '.$box->boxcode.
' -->'.
"\n";
391 print
'<tr class="oddeven" style="height:3em !important;">';
392 print
'<td>'.img_object(
"", $logo,
'class="pictofixedwidth" height="14px"').
' '.$langs->transnoentitiesnoconv($box->boxlabel);
393 if (!empty($box->class) && preg_match(
'/graph_/', $box->class)) {
394 print
img_picto(
'',
'graph',
'class="paddingleft"');
396 if (!empty($box->version)) {
397 if ($box->version ==
'experimental') {
398 print
' <span class="opacitymedium">('.$langs->trans(
"Experimental").
')</span>';
399 } elseif ($box->version ==
'development') {
400 print
' <span class="opacitymedium">('.$langs->trans(
"Development").
')</span>';
404 $langs->load(
"errors");
405 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($box->note ==
'(WarningUsingThisBoxSlowDown)' ? $langs->trans(
"WarningUsingThisBoxSlowDown") : $box->note).
'">';
406 if ($box->note ==
'(WarningUsingThisBoxSlowDown)') {
407 print
img_warning(
'',
'').
' '.$langs->trans(
"WarningUsingThisBoxSlowDown");
409 print($box->note ? $box->note :
' ');
413 print $form->textwithpicto(
'', $langs->trans(
"SourceFile").
' : '.$box->sourcefile);
415 print
'<td class="center">'.(empty($arrayofhomepages[$box->position]) ?
'' : $langs->trans($arrayofhomepages[$box->position])).
'</td>';
416 $hasnext = ($key < (count($boxactivated) - 1));
417 $hasprevious = ($key != 0);
418 print
'<td class="center">'.($key + 1).
'</td>';
419 print
'<td class="center nowraponall">';
420 print($hasnext ?
'<a class="reposition" href="boxes.php?action=switch&token='.
newToken().
'&switchfrom='.$box->rowid.
'&switchto='.$boxactivated[$key + 1]->rowid.
'">'.
img_down().
'</a> ' :
'');
421 print($hasprevious ?
'<a class="reposition" href="boxes.php?action=switch&token='.
newToken().
'&switchfrom='.$box->rowid.
'&switchto='.$boxactivated[$key - 1]->rowid.
'">'.
img_up().
'</a>' :
'');
423 print
'<td class="center">';
424 print
'<a class="reposition" href="boxes.php?rowid='.$box->rowid.
'&action=delete&token='.
newToken().
'">'.
img_delete().
'</a>';
439print
"\n\n".
'<!-- Other Const -->'.
"\n";
441print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
442print
'<input type="hidden" name="token" value="'.newToken().
'">';
443print
'<input type="hidden" name="action" value="addconst">';
444print
'<input type="hidden" name="page_y" value="">';
445print
'<div class="div-table-responsive-no-min">';
446print
'<table class="noborder centpercent">';
448print
'<tr class="liste_titre">';
449print
'<td class="liste_titre">'.$langs->trans(
"Parameter").
'</td>';
450print
'<td class="liste_titre"></td>';
454print
'<tr class="oddeven"><td>'.$langs->trans(
"EnableFileCache").
'</td><td>';
455if ($conf->use_javascript_ajax) {
456 print ajax_constantonoff(
'MAIN_ACTIVATE_FILECACHE', array(),
null, 0, 0, 0, 2, 0, 1);
458 print $form->selectyesno(
'MAIN_ACTIVATE_FILECACHE',
getDolGlobalInt(
'MAIN_ACTIVATE_FILECACHE', 0), 1);
466print $form->buttonsSaveCancel(
"Save",
'', array(), 0,
'reposition');
469print
"\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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.