From 9b1f04209dacf7d2478a88601fc5a149f46f534c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 6 Feb 2022 22:11:44 +0100 Subject: [PATCH] NEW Change in theme colors does not need to use the refresh button --- htdocs/admin/ihm.php | 6 ++++++ htdocs/core/js/lib_head.js.php | 32 ++++++++++++++++++++++++------ htdocs/core/lib/ajax.lib.php | 18 ++++++++--------- htdocs/core/lib/usergroups.lib.php | 2 ++ htdocs/main.inc.php | 8 +++++--- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php index e70e6a4cdd7..2c997d746d9 100644 --- a/htdocs/admin/ihm.php +++ b/htdocs/admin/ihm.php @@ -280,6 +280,10 @@ if ($action == 'update') { $_SESSION["mainmenu"] = ""; // The menu manager may have changed + if (GETPOST('dol_resetcache')) { + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", ((int) $conf->global->MAIN_IHM_PARAMS_REV) + 1, 'chaine', 0, '', $conf->entity); + } + header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup".'&mode='.$mode.(GETPOSTISSET('page_y') ? '&page_y='.GETPOST('page_y', 'int') : '')); exit; } @@ -309,6 +313,7 @@ print ''; print ''; print ''; print ''; +print ''; $head = ihm_prepare_head(); @@ -649,6 +654,7 @@ if ($mode == 'login') { print '
'; print ''; +print ''; print '
'; print ''; diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index ce139601ff1..1e9b53b1424 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -562,7 +562,7 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke value: value }, function() { /* handler for success of post */ - console.log("Ajax url request to set constant is a success. forcereload="+forcereload+" value="+value); + console.log("Ajax url request to set constant is a success. Make complementary actions and then forcereload="+forcereload+" value="+value); if (value == 0) { $("#set_" + code).show(); $("#del_" + code).hide(); @@ -615,9 +615,19 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke } }); if (forcereload) { - location.reload(); + var url = window.location.href; + if (url.indexOf('dol_resetcache') < 0) { + if (url.indexOf('?') > -1) { + url = url + "&dol_resetcache=1"; + } else { + url = url + "?dol_resetcache=1"; + } + } + window.location.href = url; + //location.reload(); + return false; } - }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ + }).fail(function(error) { console.log("Error, we force reload"); location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ } /* @@ -642,7 +652,7 @@ function delConstant(url, code, input, entity, strict, forcereload, userid, toke token: token }, function() { - console.log("Ajax url request to delete constant is success forcereload="+forcereload); + console.log("Ajax url request to delete constant is success. Make complementary actions and then forcereload="+forcereload); $("#del_" + code).hide(); $("#set_" + code).show(); $.each(input, function(type, data) { @@ -686,9 +696,19 @@ function delConstant(url, code, input, entity, strict, forcereload, userid, toke } }); if (forcereload) { - location.reload(); + var url = window.location.href; + if (url.indexOf('dol_resetcache') < 0) { + if (url.indexOf('?') > -1) { + url = url + "&dol_resetcache=1"; + } else { + url = url + "?dol_resetcache=1"; + } + } + window.location.href = url; + //location.reload(); + return false; } - }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ + }).fail(function(error) { console.log("Error, we force reload"); location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ } /* diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 903bb08f655..e7bea722e0c 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -563,9 +563,9 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof if (empty($conf->use_javascript_ajax) || $forcenoajax) { if (empty($conf->global->$code)) { - print ''.img_picto($langs->trans("Disabled"), 'off').''; + print ''.img_picto($langs->trans("Disabled"), 'off').''; } else { - print ''.img_picto($langs->trans("Enabled"), 'on').''; + print ''.img_picto($langs->trans("Enabled"), 'on').''; } } else { $out = "\n".' @@ -573,10 +573,10 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof $(document).ready(function() { var input = '.json_encode($input).'; var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\'; - var code = \''.$code.'\'; - var entity = \''.$entity.'\'; - var strict = \''.$strict.'\'; - var userid = \''.$user->id.'\'; + var code = \''.dol_escape_js($code).'\'; + var entity = \''.dol_escape_js($entity).'\'; + var strict = \''.dol_escape_js($strict).'\'; + var userid = \''.dol_escape_js($user->id).'\'; var yesButton = \''.dol_escape_js($langs->transnoentities("Yes")).'\'; var noButton = \''.dol_escape_js($langs->transnoentities("No")).'\'; var token = \''.currentToken().'\'; @@ -588,7 +588,7 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof if (input.alert.set.noButton) noButton = input.alert.set.noButton; confirmConstantAction("set", url, code, input, input.alert.set, entity, yesButton, noButton, strict, userid, token); } else { - setConstant(url, code, input, entity, 0, '.$forcereload.', userid, token); + setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token); } }); @@ -600,9 +600,9 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict, userid, token); } else {'; if (empty($setzeroinsteadofdel)) { - $out .=' delConstant(url, code, input, entity, 0, '.$forcereload.', userid, token);'; + $out .=' delConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token);'; } else { - $out .=' setConstant(url, code, input, entity, 0, '.$forcereload.', userid, token, 0);'; + $out .=' setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token, 0);'; } $out .= ' } }); diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index c963c74c8b6..2792b6d9997 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -507,6 +507,7 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) } // BorderTableActive + /* Disabled because not supported by md theme if ($foruserprofile) { } else { $default = $langs->trans('No'); @@ -524,6 +525,7 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) print ''; print ''; } + */ // Background color THEME_ELDY_BACKBODY if ($foruserprofile) { diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 5cfe859f2df..0547eba7782 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1512,12 +1512,14 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr if (GETPOST('version', 'int')) { $ext = 'version='.GETPOST('version', 'int'); // usefull to force no cache on css/js } + // Refresh value of MAIN_IHM_PARAMS_REV before forging the parameter line. + if (GETPOST('dol_resetcache')) { + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", ((int) $conf->global->MAIN_IHM_PARAMS_REV) + 1, 'chaine', 0, '', $conf->entity); + } $themeparam = '?lang='.$langs->defaultlang.'&theme='.$conf->theme.(GETPOST('optioncss', 'aZ09') ? '&optioncss='.GETPOST('optioncss', 'aZ09', 1) : '').'&userid='.$user->id.'&entity='.$conf->entity; + $themeparam .= ($ext ? '&'.$ext : '').'&revision='.getDolGlobalInt("MAIN_IHM_PARAMS_REV"); - if (!empty($_SESSION['dol_resetcache'])) { - $themeparam .= '&dol_resetcache='.$_SESSION['dol_resetcache']; - } if (GETPOSTISSET('dol_hide_topmenu')) { $themeparam .= '&dol_hide_topmenu='.GETPOST('dol_hide_topmenu', 'int'); }