Skip to content

Commit

Permalink
FIX Dolibarr#25143 Using default_values for extrafields by replacing …
Browse files Browse the repository at this point in the history
…GETPOSTISSET by GETPOST (Dolibarr#25233)

* FIX Dolibarr#25143 Using default_values for extrafields

* Update extrafields.class.php

correct the indentation error
  • Loading branch information
V-Py authored Oct 20, 2023
1 parent 19b1dd5 commit 9361b12
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions htdocs/core/class/extrafields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2252,16 +2252,17 @@ public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $ke
if (in_array($key_type, array('date'))) {
$dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start';
$dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end';
if (GETPOSTISSET($dateparamname_start . 'year') || GETPOSTISSET($dateparamname_end . 'year')) {

if (GETPOST($dateparamname_start . 'year') && GETPOST($dateparamname_end . 'year')) {
$value_key = array();
// values provided as a component year, month, day, etc.
if (GETPOSTISSET($dateparamname_start . 'year')) {
if (GETPOST($dateparamname_start . 'year')) {
$value_key['start'] = dol_mktime(0, 0, 0, GETPOST($dateparamname_start . 'month', 'int'), GETPOST($dateparamname_start . 'day', 'int'), GETPOST($dateparamname_start . 'year', 'int'));
}
if (GETPOSTISSET($dateparamname_start . 'year')) {
if (GETPOST($dateparamname_start . 'year')) {
$value_key['end'] = dol_mktime(23, 59, 59, GETPOST($dateparamname_end . 'month', 'int'), GETPOST($dateparamname_end . 'day', 'int'), GETPOST($dateparamname_end . 'year', 'int'));
}
} elseif (GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) {
} elseif (GETPOST($keysuffix."options_".$key.$keyprefix."year")) {
// Clean parameters
$value_key = dol_mktime(12, 0, 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
} else {
Expand All @@ -2270,7 +2271,7 @@ public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $ke
} elseif (in_array($key_type, array('datetime', 'datetimegmt'))) {
$dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start';
$dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end';
if (GETPOSTISSET($dateparamname_start . 'year') && GETPOSTISSET($dateparamname_end . 'year')) {
if (GETPOST($dateparamname_start . 'year') && GETPOST($dateparamname_end . 'year')) {
// values provided as a date pair (start date + end date), each date being broken down as year, month, day, etc.
$dateparamname_end_hour = GETPOST($dateparamname_end . 'hour', 'int') !='-1' ? GETPOST($dateparamname_end . 'hour', 'int') : '23';
$dateparamname_end_min = GETPOST($dateparamname_end . 'min', 'int') !='-1' ? GETPOST($dateparamname_end . 'min', 'int') : '59';
Expand All @@ -2286,7 +2287,7 @@ public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $ke
'end' => dol_mktime($dateparamname_end_hour, $dateparamname_end_min, $dateparamname_end_sec, GETPOST($dateparamname_end . 'month', 'int'), GETPOST($dateparamname_end . 'day', 'int'), GETPOST($dateparamname_end . 'year', 'int'), 'tzuserrel')
);
}
} elseif (GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) {
} elseif (GETPOST($keysuffix."options_".$key.$keyprefix."year")) {
// Clean parameters
if ($key_type == 'datetimegmt') {
$value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."sec", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'), 'gmt');
Expand All @@ -2307,15 +2308,15 @@ public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $ke
$value_key = GETPOST($keysuffix."options_".$key.$keyprefix);
}
} elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) {
if (!GETPOST($keysuffix."options_".$key.$keyprefix)) {
continue; // Value was not provided, we should not set it.
}
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
// Make sure we get an array even if there's only one checkbox
$value_arr = (array) $value_arr;
$value_key = implode(',', $value_arr);
} elseif (in_array($key_type, array('price', 'double', 'int'))) {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) {
if (!GETPOST($keysuffix."options_".$key.$keyprefix)) {
continue; // Value was not provided, we should not set it.
}
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
Expand All @@ -2325,19 +2326,19 @@ public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $ke
$value_key = $value_arr;
}
} elseif (in_array($key_type, array('boolean'))) {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) {
if (!GETPOST($keysuffix."options_".$key.$keyprefix)) {
$value_key = '';
} else {
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
$value_key = $value_arr;
}
} elseif (in_array($key_type, array('html'))) {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) {
if (!GETPOST($keysuffix."options_".$key.$keyprefix)) {
continue; // Value was not provided, we should not set it.
}
$value_key = dol_htmlcleanlastbr(GETPOST($keysuffix."options_".$key.$keyprefix, 'restricthtml'));
} else {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) {
if (!GETPOST($keysuffix."options_".$key.$keyprefix)) {
continue; // Value was not provided, we should not set it.
}
$value_key = GETPOST($keysuffix."options_".$key.$keyprefix);
Expand Down

0 comments on commit 9361b12

Please sign in to comment.