From 34b422ff5857e4b64ea8b3b6350dfff13e1088ff Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Tue, 15 May 2018 21:54:43 +0200 Subject: [PATCH 1/4] fixed orphaned . (dot) in convert_date --- e107_handlers/date_handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e107_handlers/date_handler.php b/e107_handlers/date_handler.php index 34aa2b104..e2f404d5a 100644 --- a/e107_handlers/date_handler.php +++ b/e107_handlers/date_handler.php @@ -173,7 +173,7 @@ class convert break; case 'inputtime': - $mask .= e107::getPref('inputtime', '%H:%M'); + $mask = e107::getPref('inputtime', '%H:%M'); break; case 'forum': // DEPRECATED - temporary here from BC reasons only From 6203233f302ea7005c105960543f5549ff8162b2 Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Tue, 15 May 2018 22:00:47 +0200 Subject: [PATCH 2/4] fixed issue in strptime with wrong monthname on windows --- e107_handlers/date_handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e107_handlers/date_handler.php b/e107_handlers/date_handler.php index e2f404d5a..2afbb6d7c 100644 --- a/e107_handlers/date_handler.php +++ b/e107_handlers/date_handler.php @@ -791,7 +791,7 @@ class convert $unxTimestamp = mktime($vals['tm_hour'], $vals['tm_min'], $vals['tm_sec'], ($vals['tm_mon'] + 1), $vals['tm_mday'], ($vals['tm_year'] + 1900)); - $vals['tm_fmon'] = strftime('%B', mktime($vals['tm_hour'], $vals['tm_min'], $vals['tm_sec'], $vals['tm_mon'])); + $vals['tm_fmon'] = strftime('%B', mktime($vals['tm_hour'], $vals['tm_min'], $vals['tm_sec'], $vals['tm_mon'] + 1)); $vals['tm_wday'] = (int) strftime('%w', $unxTimestamp); // Days since Sunday (0-6) $vals['tm_yday'] = (strftime('%j', $unxTimestamp) - 1); // Days since January 1 (0-365) From fc2873f46baba3536cdb7e5cacbb2a5754e84748 Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Tue, 15 May 2018 22:21:05 +0200 Subject: [PATCH 3/4] closes e107inc/e107#3063 added option be able to set a different pattern added additional options do define step, min, max value and decimals --- e107_handlers/form_handler.php | 72 ++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index a3c267c7b..a2737b506 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -820,7 +820,22 @@ class e_form } - + /** + * Create a input [type number] + * + * Additional options: + * - decimals: default 0; defines the number of decimals allowed in this field (0 = only integers; 1 = integers & floats with 1 decimal e.g. 4.1, etc.) + * - step: default 1; defines the step for the spinner and the max. number of decimals. If decimals is given, step will be ignored + * - min: default 0; minimum value allowed + * - max: default empty; maximum value allowed + * - pattern: default empty; allows to define an complex input pattern + * + * @param string $name + * @param integer $value + * @param integer $maxlength + * @param array $options decimals, step, min, max, pattern + * @return string + */ function number($name, $value=0, $maxlength = 200, $options = array()) { if(is_string($options)) parse_str($options, $options); @@ -852,15 +867,64 @@ class e_form $mlength = vartrue($maxlength) ? "maxlength=".$maxlength : ""; - $min = isset($options['min']) ? 'min="'.$options['min'].'"' : ''; - $max = isset($options['max']) ? 'max="'.$options['max'].'"' : ''; + // Always define the min. parameter + // defaults to 0 + // setting the min option to a negative value allows negative inputs + $min = " min='".varsettrue($options['min'], '0')."'"; + $max = isset($options['max']) ? " max='".$options['max']."'" : ''; + if (varsettrue($options['pattern'])) + { + $pattern = ' pattern="'.trim($options['pattern']).'"'; + } + else + { + $options['pattern'] = '^'; + // ^\-?[0-9]*\.?[0-9]{0,2} + if (varset($options['min'], 0) < 0) + { + $options['pattern'] .= '\-?'; + } + $options['pattern'] .= '[0-9]*'; + + // Integer & Floaat/Double value handling + if (isset($options['decimals'])) + { + if (intval($options['decimals']) > 0) + { + $options['pattern'] .= '\.?[0-9]{0,'.intval($options['decimals']).'}'; + } + + // defined the step based on number of decimals + // 2 = 0.01 > allows integers and float numbers with up to 2 decimals (3.1 = OK; 3.12 = OK; 3.123 = NOK) + // 1 = 0.1 > allows integers and float numbers with up to 2 decimals (3.1 = OK; 3.12 = NOK) + // 0 = 1 > allows only integers, no float values + if (intval($options['decimals']) <= 0) + { + $step = "step='1'"; + } + else + { + $step = "step='0." . str_pad(1, intval($options['decimals']), 0, STR_PAD_LEFT) . "'"; + } + } + else + { + // decimal option not defined + // check for step option (1, 0.1, 0.01, and so on) + // or set default step 1 (integers only) + $step = "step='" . varsettrue($options['step'], '1') . "'"; + } + + $pattern = ' pattern="'.$options['pattern'].'"'; + } $options = $this->format_options('text', $name, $options); //never allow id in format name-value for text fields if(THEME_LEGACY === false) { - return "get_attributes($options, $name)." />"; + // return "get_attributes($options, $name)." />"; + return "get_attributes($options, $name)." />"; } return $this->text($name, $value, $maxlength, $options); From b1473ed9194ac9baa281078984e14d4cd139ef4d Mon Sep 17 00:00:00 2001 From: Achim Ennenbach Date: Tue, 15 May 2018 22:56:13 +0200 Subject: [PATCH 4/4] removed orphaned variable --- e107_handlers/form_handler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index a2737b506..25df0ea42 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -865,7 +865,8 @@ class e_form $options['class'] .= " form-control"; $options['type'] ='number'; - $mlength = vartrue($maxlength) ? "maxlength=".$maxlength : ""; + // Not used anymore + //$mlength = vartrue($maxlength) ? "maxlength=".$maxlength : ""; // Always define the min. parameter // defaults to 0