From bdbb2a278f4d9a5d8bb209b8e6203bf55a8cc41d Mon Sep 17 00:00:00 2001 From: mfaber Date: Sat, 19 Oct 2013 23:48:58 +0200 Subject: [PATCH] Updated feature: min/max date fields - codes/expressions should be entered without curly braces Dev: question codes or expressions had to Dev: be entered with curly braces in min/max Dev: date fields, which confused EM. Now, Dev: min/max dates (yyyy-mm-dd), question codes, Dev: expressions should alle be entered w/o braces. Dev: Will update wiki accordingly --- application/helpers/qanda_helper.php | 98 ++++++++++++++++------------ 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index 907decac0de..29419eb9184 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -1000,6 +1000,58 @@ function do_date($ia) $dateformatdetails = getDateFormatDataForQID($aQuestionAttributes,$thissurvey); $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']); + + $date_min_dynvars=false; + $date_max_dynvars=false; + + // date_min: Determine whether we have an expression, a full date (YYYY-MM-DD) or only a year(YYYY) + if (trim($aQuestionAttributes['date_min'])!='') + { + $date_min=$aQuestionAttributes['date_min']; + if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/",$date_min)) + { + $mindate=$date_min; + } + elseif ((strlen($date_min)==4) && ($date_min>=1900) && ($date_min<=2037)) + { + // backward compatibility: if only a year is given, add month and day + $mindate=$date_min.'-01-01'; + } + else + { + $date_min_dynvars=true; + $mindate='{'.$aQuestionAttributes['date_min'].'}'; + } + } + else + { + $mindate='1900-01-01'; + } + + // date_max: Determine whether we have an expression, a full date (YYYY-MM-DD) or only a year(YYYY) + if (trim($aQuestionAttributes['date_max'])!='') + { + $date_max=$aQuestionAttributes['date_max']; + if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/",$date_max)) + { + $maxdate=$date_max; + } + elseif ((strlen($date_max)==4) && ($date_max>=1900) && ($date_max<=2037)) + { + // backward compatibility: if only a year is given, add month and day + $maxdate=$date_max.'-12-31'; + } + else + { + $date_max_dynvars=true; + $maxdate='{'.$aQuestionAttributes['date_max'].'}'; + } + } + else + { + $maxdate='2037-12-31'; + } + if (trim($aQuestionAttributes['dropdown_dates'])==1) { if (!empty($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])) { @@ -1072,6 +1124,7 @@ function do_date($ia) $answer .= ''; break; // Show year select box + case 'y': case 'Y': $answer .= '