'."\n";
+}
print '';
print '';
diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php
index 60684c1520b..b8beec3111a 100644
--- a/htdocs/core/ajax/constantonoff.php
+++ b/htdocs/core/ajax/constantonoff.php
@@ -1,5 +1,6 @@
+/* Copyright (C) 2011-2015 Regis Houssin
+ * Copyright (C) 2021 Laurent Destailleur
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,6 +48,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$action = GETPOST('action', 'aZ09'); // set or del
$name = GETPOST('name', 'alpha');
+$entity = GETPOST('entity', 'int');
+$value = ((GETPOST('value', 'int') || GETPOST('value', 'int') == '0') ? GETPOST('value', 'int') : 1);
/*
@@ -64,9 +67,6 @@ top_httphead();
// Registering the new value of constant
if (!empty($action) && !empty($name)) {
- $entity = GETPOST('entity', 'int');
- $value = (GETPOST('value') ?GETPOST('value') : 1);
-
if ($user->admin) {
if ($action == 'set') {
dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php
index db63b1a75d4..0d5905b4351 100644
--- a/htdocs/core/js/lib_head.js.php
+++ b/htdocs/core/js/lib_head.js.php
@@ -549,20 +549,27 @@ function hideMessage(fieldId,message) {
* @param int strict Strict
* @param int forcereload Force reload
* @param int userid User id
+ * @param int value Value to set
* @param string token Token
*/
-function setConstant(url, code, input, entity, strict, forcereload, userid, token) {
+function setConstant(url, code, input, entity, strict, forcereload, userid, token, value) {
var saved_url = url; /* avoid undefined url */
$.post( url, {
action: "set",
name: code,
entity: entity,
- token: token
+ token: token,
+ value: value
},
function() { /* handler for success of post */
- console.log("url request success forcereload="+forcereload);
- $("#set_" + code).hide();
- $("#del_" + code).show();
+ console.log("url request success forcereload="+forcereload+" value="+value);
+ if (value == 0) {
+ $("#set_" + code).show();
+ $("#del_" + code).hide();
+ } else {
+ $("#set_" + code).hide();
+ $("#del_" + code).show();
+ }
$.each(input, function(type, data) {
// Enable another element
if (type == "disabled" && strict != 1) {
@@ -610,7 +617,7 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke
if (forcereload) {
location.reload();
}
- }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMEssage in session visible */
+ }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */
}
/*
@@ -681,7 +688,7 @@ function delConstant(url, code, input, entity, strict, forcereload, userid, toke
if (forcereload) {
location.reload();
}
- }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMEssage in session visible */
+ }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */
}
/*
@@ -716,7 +723,7 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
text : yesButton,
click : function() {
if (action == "set") {
- setConstant(url, code, input, entity, strict, 0, userid, token);
+ setConstant(url, code, input, entity, strict, 0, userid, token, 1);
} else if (action == "del") {
delConstant(url, code, input, entity, strict, 0, userid, token);
}
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 99cf4e4f8d1..b59b40b8c9d 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -540,14 +540,15 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
* @param string $code Name of constant
* @param array $input Array of complementary actions to do if success ("disabled"|"enabled'|'set'|'del') => CSS element to switch, 'alert' => message to show, ... Example: array('disabled'=>array(0=>'cssid'))
* @param int $entity Entity. Current entity is used if null.
- * @param int $revertonoff Revert on/off
+ * @param int $revertonoff 1=Revert on/off
* @param int $strict Use only "disabled" with delConstant and "enabled" with setConstant
* @param int $forcereload Force to reload page if we click/change value (this is supported only when there is no 'alert' option in input)
* @param string $marginleftonlyshort 1 = Add a short left margin on picto, 2 = Add a larger left margin on picto, 0 = No left margin. Works for fontawesome picto only.
* @param int $forcenoajax 1 = Force to use a ahref link instead of ajax code.
+ * @param int $setzeroinsteadofdel 1 = Set constantto '0' instead of deleting it
* @return string
*/
-function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0, $forcereload = 0, $marginleftonlyshort = 2, $forcenoajax = 0)
+function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0, $forcereload = 0, $marginleftonlyshort = 2, $forcenoajax = 0, $setzeroinsteadofdel = 0)
{
global $conf, $langs, $user;
@@ -593,9 +594,13 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof
if (input.alert.del.yesButton) yesButton = input.alert.del.yesButton;
if (input.alert.del.noButton) noButton = input.alert.del.noButton;
confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict, userid, token);
- } else {
- delConstant(url, code, input, entity, 0, '.$forcereload.', userid, token);
- }
+ } else {';
+ if (empty($setzeroinsteadofdel)) {
+ $out .=' delConstant(url, code, input, entity, 0, '.$forcereload.', userid, token);';
+ } else {
+ $out .=' setConstant(url, code, input, entity, 0, '.$forcereload.', userid, token, 0);';
+ }
+ $out .= ' }
});
});
'."\n";
diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php
index fe21071901a..8fe9352457b 100644
--- a/htdocs/core/lib/date.lib.php
+++ b/htdocs/core/lib/date.lib.php
@@ -668,15 +668,16 @@ function getGMTEasterDatetime($year)
*
* @param int $timestampStart Timestamp start (UTC with hour, min, sec = 0)
* @param int $timestampEnd Timestamp end (UTC with hour, min, sec = 0)
- * @param string $country_code Country code
- * @param int $lastday Last day is included, 0: no, 1:yes
+ * @param string $country_code Country code
+ * @param int $lastday Last day is included, 0: no, 1:yes
* @param int $includesaturday Include saturday as non working day (-1=use setup, 0=no, 1=yes)
* @param int $includesunday Include sunday as non working day (-1=use setup, 0=no, 1=yes)
* @param int $includefriday Include friday as non working day (-1=use setup, 0=no, 1=yes)
- * @return int|string Number of non working days or error message string if error
+ * @param int $includemonday Include monday as non working day (-1=use setup, 0=no, 1=yes)
+ * @return int|string Number of non working days or error message string if error
* @see num_between_day(), num_open_day()
*/
-function num_public_holiday($timestampStart, $timestampEnd, $country_code = '', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1)
+function num_public_holiday($timestampStart, $timestampEnd, $country_code = '', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
{
global $db, $conf, $mysoc;
@@ -690,6 +691,9 @@ function num_public_holiday($timestampStart, $timestampEnd, $country_code = '',
if (empty($country_code)) {
$country_code = $mysoc->country_code;
}
+ if ($includemonday < 0) {
+ $includemonday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY : 0);
+ }
if ($includefriday < 0) {
$includefriday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY : 0);
}
diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang
index 0e6b1d69b36..dfbd97cdbdc 100644
--- a/htdocs/langs/en_US/holiday.lang
+++ b/htdocs/langs/en_US/holiday.lang
@@ -133,3 +133,4 @@ WatermarkOnDraftHolidayCards=Watermarks on draft leave requests
HolidaysToApprove=Holidays to approve
NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays
HolidayBalanceMonthlyUpdate=Monthly update of holiday balance
+XIsAUsualNonWorkingDay=%s is usualy a NON working day
\ No newline at end of file