diff --git a/application/controllers/admin/dataentry.php b/application/controllers/admin/dataentry.php index 21d318af6ea..42b072fd62a 100644 --- a/application/controllers/admin/dataentry.php +++ b/application/controllers/admin/dataentry.php @@ -1247,7 +1247,6 @@ public function view($surveyid, $lang=NULL) $cdata['qidattributes'] = $qidattributes; $hidden = (isset($qidattributes['hidden']) ? $qidattributes['hidden'] : 0); // TODO - can questions be hidden? Are JavaScript variables names used? Consistently with everywhere else? - // LimeExpressionManager::ProcessRelevance($qidattributes['relevance'],$deqrow['qid'],NULL,$deqrow['type'],$hidden); // TMSW Conditions->Relevance: Show relevance equation instead of conditions here - better yet, have data entry use survey-at-a-time but with different view diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 1c200a3dd93..4c77cfbd744 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -2542,7 +2542,6 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc 'qcode'=>$varName, 'qseq'=>$q->questioncount, 'gseq'=>$q->groupcount, - 'type'=>$type, //AJS 'q'=>$q, 'sgqa'=>$q->fieldname, 'ansList'=>$ansList, @@ -2852,10 +2851,10 @@ static function ProcessString($string, $questionNum=NULL, $replacementFields=arr * @param $hidden - whether question should always be hidden * @return */ - static function ProcessRelevance($eqn,$questionNum=NULL,$jsResultVar=NULL,$type=NULL,$hidden=0) + static function ProcessRelevance($eqn,$questionNum=NULL,$jsResultVar=NULL,$q=NULL,$hidden=0) { $LEM =& LimeExpressionManager::singleton(); - return $LEM->_ProcessRelevance($eqn,$questionNum,NULL,$jsResultVar,$type,$hidden); + return $LEM->_ProcessRelevance($eqn,$questionNum,NULL,$jsResultVar,$q,$hidden); } /** @@ -5902,7 +5901,7 @@ static function UnitTestRelevance() { $args = explode("~",$test); $q = (($args[1]=='expr') ? new EquationQuestion : ($args[1]=='message') ? new DisplayQuestion : newShortTextQuestion); - $vars[$args[0]] = array('sgqa'=>$args[0], 'code'=>'', 'jsName'=>'java' . $args[0], 'jsName_on'=>'java' . $args[0], 'readWrite'=>'Y', 'type'=>$type, 'relevanceStatus'=>'1', 'gid'=>1, 'gseq'=>1, 'qseq'=>$i, 'qid'=>$i); + $vars[$args[0]] = array('sgqa'=>$args[0], 'code'=>'', 'jsName'=>'java' . $args[0], 'jsName_on'=>'java' . $args[0], 'readWrite'=>'Y', 'q'=>$q, 'relevanceStatus'=>'1', 'gid'=>1, 'gseq'=>1, 'qseq'=>$i, 'qid'=>$i); $varSeq[] = $args[0]; $testArgs[] = $args; $LEM->questionId2questionSeq[$i] = $i; @@ -6362,6 +6361,7 @@ static function ProcessCurrentResponses() foreach ($LEM->currentQset as $qinfo) { $relevant=false; + $q = $qinfo['info']['q']; $qid = $qinfo['info']['qid']; $gseq = $qinfo['info']['gseq']; $relevant = (isset($_POST['relevance' . $qid]) ? ($_POST['relevance' . $qid] == 1) : false); @@ -6380,8 +6380,6 @@ static function ProcessCurrentResponses() $_SESSION[$LEM->sessid]['relevanceStatus'][$rowdivid] = $sqrelevant; } } - $type = $qinfo['info']['type']; - $q = $qinfo['q']; if ($relevant && $grelevant && $sqrelevant) { if ($qinfo['info']['hidden'] && !isset($_POST[$sq])) @@ -6397,69 +6395,9 @@ static function ProcessCurrentResponses() // convert from comma back to decimal $value = implode('.',explode(',',$value)); } - switch($type) - { - case 'D': //DATE - if (trim($value)=="") - { - $value = ""; - } - else - { - $dateformatdatat=getDateFormatData($LEM->surveyOptions['surveyls_dateformat']); - $datetimeobj = new Date_Time_Converter($value, $dateformatdatat['phpdate']); - $value=$datetimeobj->convert("Y-m-d"); - } - break; - case 'N': //NUMERICAL QUESTION TYPE - case 'K': //MULTIPLE NUMERICAL QUESTION - if (trim($value)=="") { - $value = ""; - } - else { - $value = sanitize_float($value); - } - break; - case '|': //File Upload - if (!preg_match('/_filecount$/', $sq)) - { - $json = $value; - $phparray = json_decode(stripslashes($json)); - - // if the files have not been saved already, - // move the files from tmp to the files folder - - $tmp = $LEM->surveyOptions['tempdir'] . '/upload/'; - if (!is_null($phparray) && count($phparray) > 0) - { - // Move the (unmoved, temp) files from temp to files directory. - // Check all possible file uploads - for ($i = 0; $i < count($phparray); $i++) - { - if (file_exists($tmp . $phparray[$i]->filename)) - { - $sDestinationFileName = 'fu_' . randomChars(15); - if (!is_dir($LEM->surveyOptions['target'])) - { - mkdir($LEM->surveyOptions['target'], 0777, true); - } - if (!rename($tmp . $phparray[$i]->filename, $LEM->surveyOptions['target'] . $sDestinationFileName)) - { - echo "Error moving file to target destination"; - } - $phparray[$i]->filename = $sDestinationFileName; - } - } - $value = ls_json_encode($phparray); // so that EM doesn't try to parse it. - } - } - break; - } + $value = $q->filter($value, 'post'); $_SESSION[$LEM->sessid][$sq] = $value; - $_update = array ( - 'q'=>$q, - 'value'=>$value, - ); + $_update = array ('q'=>$q, 'value'=>$value); $updatedValues[$sq] = $_update; $LEM->updatedValues[$sq] = $_update; } @@ -6764,8 +6702,6 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL $moveResult = LimeExpressionManager::NavigateForwards(); } - $qtypes=getQuestionTypeList(); - if (is_null($moveResult) || is_null($LEM->currentQset) || count($LEM->currentQset) == 0) { return array( 'errors'=>1, @@ -6812,11 +6748,12 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL $out .= "#".$LEM->gT('Name [ID]')."".$LEM->gT('Relevance [Validation] (Default)')."".$LEM->gT('Text [Help] (Tip)')."\n"; $_gseq=-1; - foreach ($LEM->currentQset as $q) { - $gseq = $q['info']['gseq']; - $gid = $q['info']['gid']; - $qid = $q['info']['qid']; - $qseq = $q['info']['qseq']; + foreach ($LEM->currentQset as $qStatus) { + $gseq = $qStatus['info']['gseq']; + $gid = $qStatus['info']['gid']; + $qid = $qStatus['info']['qid']; + $qseq = $qStatus['info']['qseq']; + $q = $qStatus['info']['q']; $errorCount=0; @@ -6849,14 +6786,12 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL ////// // SHOW QUESTION-LEVEL INFO ////// - $mandatory = (($q['info']['mandatory']=='Y') ? "*" : ''); - $type = $q['info']['type']; - $typedesc = $qtypes[$type]['description']; + $mandatory = (($qStatus['info']['mandatory']=='Y') ? "*" : ''); - $sgqas = explode('|',$q['sgqa']); - if (count($sgqas) == 1 && !is_null($q['info']['default'])) + $sgqas = explode('|',$qStatus['sgqa']); + if (count($sgqas) == 1 && !is_null($qStatus['info']['default'])) { - $LEM->ProcessString($q['info']['default'], $qid,NULL,false,1,1,false,false); + $LEM->ProcessString($qStatus['info']['default'], $qid,NULL,false,1,1,false,false); $_default = $LEM->GetLastPrettyPrintExpression(); if ($LEM->em->HasErrors()) { ++$errorCount; @@ -6868,9 +6803,9 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL $default = ''; } - $qtext = (($q['info']['qtext'] != '') ? $q['info']['qtext'] : ' '); - $help = (($q['info']['help'] != '') ? '
[' . $LEM->gT("Help:") . ' ' . $q['info']['help'] . ']': ''); - $prettyValidTip = (($q['prettyValidTip'] == '') ? '' : '
(' . $LEM->gT("Tip:") . ' ' . $q['prettyValidTip'] . ')'); + $qtext = (($qStatus['info']['qtext'] != '') ? $qStatus['info']['qtext'] : ' '); + $help = (($qStatus['info']['help'] != '') ? '
[' . $LEM->gT("Help:") . ' ' . $qStatus['info']['help'] . ']': ''); + $prettyValidTip = (($qStatus['prettyValidTip'] == '') ? '' : '
(' . $LEM->gT("Tip:") . ' ' . $qStatus['prettyValidTip'] . ')'); ////// // SHOW QUESTION ATTRIBUTES THAT ARE PROCESSED BY EM @@ -6959,7 +6894,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL // SHOW RELEVANCE ////// // Must parse Relevance this way, otherwise if try to first split expressions, regex equations won't work - $relevanceEqn = (($q['info']['relevance'] == '') ? 1 : $q['info']['relevance']); + $relevanceEqn = (($qStatus['info']['relevance'] == '') ? 1 : $qStatus['info']['relevance']); if (!isset($LEM->ParseResultCache[$relevanceEqn])) { $result = $LEM->em->ProcessBooleanExpression($relevanceEqn, $gseq, $qseq); @@ -6981,8 +6916,8 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL ////// // Must parse Validation this way so that regex (preg) works $prettyValidEqn = ''; - if ($q['prettyValidEqn'] != '') { - $validationEqn = $q['validEqn']; + if ($qStatus['prettyValidEqn'] != '') { + $validationEqn = $qStatus['validEqn']; if (!isset($LEM->ParseResultCache[$validationEqn])) { $result = $LEM->em->ProcessBooleanExpression($validationEqn, $gseq, $qseq); @@ -7003,7 +6938,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL ////// // TEST VALIDITY OF ROOT VARIABLE NAME AND WHETHER HAS BEEN USED ////// - $rootVarName = $q['info']['rootVarName']; + $rootVarName = $qStatus['info']['rootVarName']; $varNameErrorMsg = ''; $varNameError = NULL; if (isset($varNamesUsed[$rootVarName])) @@ -7053,7 +6988,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL } $rowdivid=$sgqa; $varName=$LEM->knownVars[$sgqa]['qcode']; - switch ($q['info']['type']) + switch ($qStatus['info']['type']) { case '1': if (preg_match('/#1$/',$sgqa)) { @@ -7143,7 +7078,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL $subQeqn = ''; $rowdivid = $sgqas[0] . $ansInfo[1]; - if ($q['info']['type'] == 'R') + if ($qStatus['info']['type'] == 'R') { $rowdivid = $LEM->sid . 'X' . $gid . 'X' . $qid . $ansInfo[1]; } @@ -7176,7 +7111,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL $errclass = ($errorCount > 0) ? "class='LEMerror' title='" . sprintf($LEM->ngT("This question has at least %s error.","This question has at least %s errors.",$errorCount), $errorCount) . "'" : ''; $questionRow = "" - . "Q-" . $q['info']['qseq'] . "" + . "Q-" . $qStatus['info']['qseq'] . "" . "" . $mandatory; if ($varNameErrorMsg == '') @@ -7191,7 +7126,9 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL . $rootVarName . ""; } $editlink = Yii::app()->getController()->createUrl('/admin/survey/view/surveyid/' . $sid . '/gid/' . $gid . '/qid/' . $qid); - $questionRow .= "
[QID $qid]
$typedesc [$type]" + $description = $q->questionProperties('description'); + $class = substr(get_class($q),0,-8); + $questionRow .= "
[QID $qid]
$description [$class]" . "" . $relevance . $prettyValidEqn . $default . "" . "" . $qdetails . "" . "\n"; @@ -7432,10 +7369,10 @@ static public function &ExcelSurveyExport($sid) } $_gseq=-1; - foreach ($LEM->currentQset as $q) { - $gseq = $q['info']['gseq']; - $gid = $q['info']['gid']; - $qid = $q['info']['qid']; + foreach ($LEM->currentQset as $qStatus) { + $gseq = $qStatus['info']['gseq']; + $gid = $qStatus['info']['gid']; + $qid = $qStatus['info']['qid']; ////// // SHOW GROUP-LEVEL INFO @@ -7464,21 +7401,20 @@ static public function &ExcelSurveyExport($sid) ////// $row = array(); - $mandatory = (($q['info']['mandatory']=='Y') ? 'Y' : ''); - $type = $q['info']['type']; + $mandatory = (($qStatus['info']['mandatory']=='Y') ? 'Y' : ''); - $sgqas = explode('|',$q['sgqa']); - if (count($sgqas) == 1 && !is_null($q['info']['default'])) + $sgqas = explode('|',$qStatus['sgqa']); + if (count($sgqas) == 1 && !is_null($qStatus['info']['default'])) { - $default = $q['info']['default']; + $default = $qStatus['info']['default']; } else { $default = ''; } - $qtext = (($q['info']['qtext'] != '') ? $q['info']['qtext'] : ''); - $help = (($q['info']['help'] != '') ? $q['info']['help']: ''); + $qtext = (($qStatus['info']['qtext'] != '') ? $qStatus['info']['qtext'] : ''); + $help = (($qStatus['info']['help'] != '') ? $qStatus['info']['help']: ''); ////// // SHOW QUESTION ATTRIBUTES THAT ARE PROCESSED BY EM @@ -7510,14 +7446,14 @@ static public function &ExcelSurveyExport($sid) } // if relevance equation is using SGQA coding, convert to qcoding - $relevanceEqn = (($q['info']['relevance'] == '') ? 1 : $q['info']['relevance']); - $LEM->em->ProcessBooleanExpression($relevanceEqn, $gseq, $q['info']['qseq']); // $qseq + $relevanceEqn = (($qStatus['info']['relevance'] == '') ? 1 : $qStatus['info']['relevance']); + $LEM->em->ProcessBooleanExpression($relevanceEqn, $gseq, $qStatus['info']['qseq']); // $qseq $relevanceEqn = trim(strip_tags($LEM->em->GetPrettyPrintString())); - $rootVarName = $q['info']['rootVarName']; + $rootVarName = $qStatus['info']['rootVarName']; $preg = ''; - if (isset($LEM->q2subqInfo[$q['info']['qid']]['preg'])) + if (isset($LEM->q2subqInfo[$qStatus['info']['qid']]['preg'])) { - $preg = $LEM->q2subqInfo[$q['info']['qid']]['preg']; + $preg = $LEM->q2subqInfo[$qStatus['info']['qid']]['preg']; if (is_null($preg)) { $preg = ''; @@ -7525,7 +7461,8 @@ static public function &ExcelSurveyExport($sid) } $row['class'] = 'Q'; - $row['type/scale'] = $type; + $qclass = substr(get_class($q),0,-8); + $row['type/scale'] = $class; $row['name'] = $rootVarName; $row['relevance'] = $relevanceEqn; $row['text'] = $qtext; @@ -7533,9 +7470,9 @@ static public function &ExcelSurveyExport($sid) $row['language'] = $lang; $row['validation'] = $preg; $row['mandatory'] = $mandatory; - $row['other'] = $q['info']['other']; + $row['other'] = $qStatus['info']['other']; $row['default'] = $default; - $row['same_default'] = 1; // TODO - need this: $q['info']['same_default']; + $row['same_default'] = 1; // TODO - need this: $qStatus['info']['same_default']; $rows[] = $row; @@ -7551,7 +7488,7 @@ static public function &ExcelSurveyExport($sid) $rowdivid=$sgqa; $varName=$LEM->knownVars[$sgqa]['qcode']; - switch ($q['info']['type']) + switch ($qStatus['info']['type']) { case '1': if (preg_match('/#1$/',$sgqa)) { @@ -7625,7 +7562,7 @@ static public function &ExcelSurveyExport($sid) } $row = array(); - if ($type == ':' || $type == ';') + if ($q->questionProperties('subquestions') == 2) { $row['class'] = 'SQ'; } diff --git a/application/modules/CommentCheckQuestion.php b/application/modules/CommentCheckQuestion.php index 23e1c0ea483..53b189ef4d4 100644 --- a/application/modules/CommentCheckQuestion.php +++ b/application/modules/CommentCheckQuestion.php @@ -296,7 +296,7 @@ public function getCommentMandatorySQ() public function getAdditionalValParts() { - $othervar = 'amswer' . $this->fieldname; + $othervar = 'answer' . $this->fieldname; $valParts[] = "\n if(isValidOtherComment" . $this->id . "){\n"; $valParts[] = " $('#" . $othervar . "').addClass('em_sq_validation').removeClass('error').addClass('good');\n"; $valParts[] = " }\n else {\n"; diff --git a/application/modules/DateQuestion.php b/application/modules/DateQuestion.php index 0fae17cd4c7..b9936c39e29 100644 --- a/application/modules/DateQuestion.php +++ b/application/modules/DateQuestion.php @@ -264,6 +264,7 @@ public function filter($value, $type) switch ($type) { case 'get': + case 'post': global $thissurvey; $dateformatdatat=getDateFormatData($thissurvey['surveyls_dateformat']); $datetimeobj = new Date_Time_Converter($value, $dateformatdatat['phpdate']); diff --git a/application/modules/FileQuestion.php b/application/modules/FileQuestion.php index 7181323ce18..3afa63bed17 100644 --- a/application/modules/FileQuestion.php +++ b/application/modules/FileQuestion.php @@ -263,6 +263,7 @@ public function filter($value, $type) } case 'db': return $value; + case 'post': case 'dataentryinsert': if (!strpos($this->fieldname, "_filecount")) { diff --git a/application/modules/NumericalQuestion.php b/application/modules/NumericalQuestion.php index c4ecb68067f..e686177ed65 100644 --- a/application/modules/NumericalQuestion.php +++ b/application/modules/NumericalQuestion.php @@ -173,6 +173,16 @@ public function getPregSQ($sgqaNaming, $sq) } } + public function getAdditionalValParts() + { + $valParts[] = "\n if(isValidOther" . $this->id . "){\n"; + $valParts[] = " $('#question" . $this->id . " :input').addClass('em_sq_validation').removeClass('error').addClass('good');\n"; + $valParts[] = " }\n else {\n"; + $valParts[] = " $('#question" . $this->id . " :input').addClass('em_sq_validation').removeClass('good').addClass('error');\n"; + $valParts[] = " }\n"; + return $valParts; + } + public function availableAttributes($attr = false) { $attrs=array("em_validation_q","em_validation_q_tip","em_validation_sq","em_validation_sq_tip","statistics_showgraph","statistics_graphtype","hide_tip","hidden","max_num_value_n","maximum_chars","min_num_value_n","num_value_int_only","page_break","prefix","public_statistics","suffix","text_input_width","random_group"); diff --git a/application/modules/TextQuestion.php b/application/modules/TextQuestion.php index 25c90e8af3e..84ff36130dd 100644 --- a/application/modules/TextQuestion.php +++ b/application/modules/TextQuestion.php @@ -70,10 +70,10 @@ public function generateSQInfo($ansArray) public function getAdditionalValParts() { - $valParts[] = "\n if(isValidSum" . $this->id . "){\n"; - $valParts[] = " $('#totalvalue_" . $this->id . "').removeClass('error').addClass('good');\n"; + $valParts[] = "\n if(isValidOther" . $this->id . "){\n"; + $valParts[] = " $('#question" . $this->id . " :input').addClass('em_sq_validation').removeClass('error').addClass('good');\n"; $valParts[] = " }\n else {\n"; - $valParts[] = " $('#totalvalue_" . $this->id . "').removeClass('good').addClass('error');\n"; + $valParts[] = " $('#question" . $this->id . " :input').addClass('em_sq_validation').removeClass('good').addClass('error');\n"; $valParts[] = " }\n"; return $valParts; }