diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 38d34a226b9..873f67b4d14 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -1508,7 +1508,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL) { if ($this->sgqaNaming) { - $base = substr(substr($sq['jsVarName'],4),0,-1); + $base = $sq['rowdivid']."#"; $sq_name = "if(count(" . $base . "0.NAOK," . $base . "1.NAOK)==2,1,'')"; } else @@ -1594,7 +1594,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL) { if ($this->sgqaNaming) { - $base = substr(substr($sq['jsVarName'],4),0,-1); + $base = $sq['rowdivid']."#"; $sq_name = "if(count(" . $base . "0.NAOK," . $base . "1.NAOK)==2,1,'')"; } else @@ -2730,7 +2730,7 @@ private function _recursivelyFindAntecdentArrayFilters($qroot, $aflist, $afelist private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forceRefresh=false,$anonymized=false,$allOnOnePage=false) { - if (isset($_SESSION['LEMforceRefresh'])) { + if (isset($_SESSION['LEMforceRefresh']) || true) { unset($_SESSION['LEMforceRefresh']); $forceRefresh=true; } @@ -3112,7 +3112,6 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc case 'I': //Language Question case 'Y': //YES/NO radio-buttons case '*': //Equation - case '1': //Array (Flexible Labels) dual scale case 'A': //ARRAY (5 POINT CHOICE) radio-buttons case 'B': //ARRAY (10 POINT CHOICE) radio-buttons case 'C': //ARRAY (YES/UNCERTAIN/NO) radio-buttons @@ -3131,6 +3130,10 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc } $jsVarName = 'java' . $sgqa; break; + case '1': //Array (Flexible Labels) dual scale + $jsVarName = 'java' . str_replace('#','_',$sgqa); + $jsVarName_on = $jsVarName; + break; case ':': //ARRAY (Multi Flexi) 1 to 10 case ';': //ARRAY (Multi Flexi) Text $jsVarName = 'java' . $sgqa; @@ -6526,7 +6529,8 @@ static function GetRelevanceAndTailoringJavaScript() { $qrelJS .= " if(" . implode(' || ', $qrelgseqs) . "){\n ;\n }\n else"; } - $qrelJS .= " if (typeof sgqa !== 'undefined' && !LEMregexMatch('/ java' + sgqa + ' /', UsesVars)) {\n return;\n }\n"; + $qrelJS .= " if (typeof sgqa !== 'undefined' && !LEMregexMatch('/ java' + sgqa + ' /', UsesVars)) {\n"; + $qrelJS .= " return;\n }\n"; $qrelJS .= implode("",$relParts); $qrelJS .= "}\n"; $relEqns[] = $qrelJS; @@ -7029,7 +7033,7 @@ static function UnitTestRelevance() $rel = LimeExpressionManager::QuestionIsRelevant($i); $question = LimeExpressionManager::ProcessString($testArg[3], $i, NULL, true, 1, 1); - $jsVarName='java' . $testArg[0]; + $jsVarName='java' . str_replace('#','_',$testArg[0]); $argInfo[] = array( 'num' => $i, diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index 3e5987f67e8..b1de0a2cd00 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -6064,7 +6064,6 @@ function do_arraycolumns($ia) } // --------------------------------------------------------------- -// TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_dual($ia) { global $thissurvey; @@ -6075,29 +6074,43 @@ function do_array_dual($ia) $answertypeclass = ""; // Maybe not $clang = Yii::app()->lang; - $checkconditionFunction = "checkconditions"; - $inputnames=array(); $labelans1=array(); $labelans=array(); - $qquery = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."'"; - $other = dbExecuteAssoc($qquery)->read(); - $other = reset($other); //Checked + $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); + + if ($aQuestionAttributes['random_order']==1) { + $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom(); + } + else + { + $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY question_order"; + } + $ansresult = dbExecuteAssoc($ansquery); //Checked + $aSubQuestions=$ansresult->readAll(); + $anscount = count($aSubQuestions); + $lquery = "SELECT * FROM {{answers}} WHERE scale_id=0 AND qid={$ia[0]} AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ORDER BY sortorder, code"; + $lresult = dbExecuteAssoc($lquery); //Checked + $aAnswersScale0=$lresult->readAll(); + $lquery1 = "SELECT * FROM {{answers}} WHERE scale_id=1 AND qid={$ia[0]} AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ORDER BY sortorder, code"; - $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); + $lresult1 = dbExecuteAssoc($lquery1); //Checked + $aAnswersScale1=$lresult1->readAll(); if ($aQuestionAttributes['use_dropdown']==1) { $useDropdownLayout = true; $extraclass .=" dropdown-list"; $answertypeclass .=" dropdown"; + $doDualScaleFunction="doDualScaleDropDown";// javascript funtion to lauch at end of answers } else { $useDropdownLayout = false; $extraclass .=" radio-list"; $answertypeclass .=" radio"; + $doDualScaleFunction="doDualScaleRadio"; } if(ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings']!="")) { @@ -6105,7 +6118,7 @@ function do_array_dual($ia) $minrepeatheadings = 0; } if (trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='') { - $leftheader= $clang->gT($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]); + $leftheader= $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]; } else { @@ -6114,357 +6127,307 @@ function do_array_dual($ia) if (trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='') { - $rightheader= $clang->gT($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]); + $rightheader= $aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]; } else { $rightheader =''; } - - $lresult = dbExecuteAssoc($lquery); //Checked - $aAnswersScale1=$lresult->readAll(); - if ($useDropdownLayout === false && count($aAnswersScale1) > 0) + if (trim($aQuestionAttributes['answer_width'])!='') { - if (trim($aQuestionAttributes['answer_width'])!='') - { - $answerwidth=$aQuestionAttributes['answer_width']; - } - else - { - $answerwidth=20; - } - $columnswidth = 100 - $answerwidth; - - foreach ($aAnswersScale1 as $lrow) - { - $labelans[]=$lrow['answer']; - $labelcode[]=$lrow['code']; - } - - $lresult1 = dbExecuteAssoc($lquery1); //Checked - foreach ($lresult1->readAll() as $lrow1) - { - $labelans1[]=$lrow1['answer']; - $labelcode1[]=$lrow1['code']; - } - - $numrows=count($labelans) + count($labelans1); - if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) {$numrows++;} - $cellwidth=$columnswidth/$numrows; - - $cellwidth=sprintf("%02d", $cellwidth); + $answerwidth=$aQuestionAttributes['answer_width']; + } + else + { + $answerwidth=20; + } + // Find if we have rigth and center text + // TODO move "|" to attribute + $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=".$ia[0]." and scale_id=0 AND question like '%|%'"; + $rigthCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); + $rightexists= ($rigthCount>0);// $right_exists: flag to find out if there are any right hand answer parts. leaving right column but don't force with + $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=".$ia[0]." and scale_id=0 AND question like '%|%|%'"; + $centerCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); + $centerexists= ($centerCount>0);// $center_exists: flag to find out if there are any center hand answer parts. leaving center column but don't force with - $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=".$ia[0]." and scale_id=0 AND question like '%|%'"; - $iCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); - $right_exists= ($iCount>0); - // $right_exists is a flag to find out if there are any right hand answer parts. If there aren't we can leave out the right td column - if ($aQuestionAttributes['random_order']==1) { - $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom(); - } - else - { - $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY question_order"; - } - $ansresult = dbExecuteAssoc($ansquery); //Checked - $aQuestionsRight=$ansresult->readAll(); - $anscount = count($aQuestionsRight); - $fn=1; - // unselect second scale when using "no answer" - $answer = "\n"; - - // Header row and colgroups - $mycolumns = "\t\n" - ."\t\n"; - - - $answer_head_line = "\t \n\n"; - $odd_even = ''; - foreach ($labelans as $ld) - { - $answer_head_line .= "\t".$ld."\n"; - $odd_even = alternation($odd_even); - $mycolumns .= "\n"; - } - $mycolumns .= "\t\n"; + // Label and code for input + foreach ($aAnswersScale0 as $lrow) + { + $labels0[]=Array('code' => $lrow['code'], + 'title' => $lrow['answer']); + } + foreach ($aAnswersScale1 as $lrow) + { + $labels1[]=Array('code' => $lrow['code'], + 'title' => $lrow['answer']); + } - if (count($labelans1)>0) // if second label set is used + if (count($aAnswersScale0) > 0 && $anscount) + { + $answer = ""; + $fn=1;// Used by repeat_heading + if ($useDropdownLayout === false) { - $mycolumns .= "\t\n" - . "\t\n"; - $answer_head_line .= "\n\t \n\n"; // Separator - foreach ($labelans1 as $ld) + $columnswidth = 100 - $answerwidth; + foreach ($aAnswersScale0 as $lrow) + { + $labelans0[]=$lrow['answer']; + $labelcode0[]=$lrow['code']; + } + foreach ($aAnswersScale1 as $lrow) + { + $labelans1[]=$lrow['answer']; + $labelcode1[]=$lrow['code']; + } + $numrows=count($labelans0) + count($labelans1); + // Add needed row and fill some boolean: shownoanswer, rightexists, centerexists + $shownoanswer=($ia[6] != "Y" && SHOW_NO_ANSWER == 1); + if($shownoanswer) {$numrows++;} + if($rightexists) {$numrows++;} + if($centerexists) {$numrows++;} + $cellwidth=$columnswidth/$numrows; + //$cellwidth=sprintf("%02d", $cellwidth); // No reason to do this, except to leave place for seperator ? But then table can not be the same in all browser + + // Header row and colgroups + $mycolumns = "\t\n"; + $answer_head_line = "\t \n\n"; + $mycolumns .= "\t\n"; + $odd_even = ''; + foreach ($labelans0 as $ld) { $answer_head_line .= "\t".$ld."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\n"; } - - } - if ($right_exists) - { - $answer_head_line .= "\t \n"; - $mycolumns .= "\n\t\n\n"; - } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" - { - $answer_head_line .= "\t \n"; // Separator - $answer_head_line .= "\t".$clang->gT('No answer')."\n"; - $odd_even = alternation($odd_even); - $mycolumns .= "\n\t\n\n"; - $mycolumns .= "\t\n"; - } - - $mycolumns .= "\t\n"; - $answer_head2 = "\n\n" - . $answer_head_line - . "\n"; - - // build first row of header if needed - if ($leftheader != '' || $rightheader !='') - { - $answer_head1 = "\n" - . "\t \n" - . "\t$leftheader\n"; - - if (count($labelans1)>0) + $mycolumns .= "\t\n"; + if (count($labelans1)>0) // if second label set is used { - $answer_head1 .= "\t \n" // Separator - ."\t$rightheader\n"; + $seperatorwidth=($centerexists)? "width=\"$cellwidth%\" ":""; + $mycolumns .= "\t\n"; + $mycolumns .= "\t\n"; + $answer_head_line .= "\n\t \n\n"; // Separator : and No answer for accessibility for first colgroup + foreach ($labelans1 as $ld) + { + $answer_head_line .= "\t".$ld."\n"; + $odd_even = alternation($odd_even); + $mycolumns .= "\n"; + } + $mycolumns .= "\t\n"; } - if ($right_exists) + if($shownoanswer || $rightexists) { - $answer_head1 .= "\t \n"; + $rigthwidth=($rightexists)? "width=\"$cellwidth%\" ":""; + $mycolumns .= "\t\n"; + $answer_head_line .= "\n\t \n"; } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) + if($shownoanswer) { - $answer_head1 .= "\t \n"; // Separator - $answer_head1 .= "\t \n"; - } - $answer_head1 .= "\n"; - } - else - { - $answer_head1 = ''; - } - - $answer .= "\n\n" - . $mycolumns - . "\n\t\n" - . $answer_head1 - . $answer_head2 - . "\n\t\n" - . "\n"; - - $trbc = ''; - foreach ($aQuestionsRight as $ansrow) - { - // Build repeat headings if needed - if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) + $mycolumns .= "\t\n"; + $answer_head_line .= "\n\t\n"; + } + $answer_head2 = "\n\n" + . $answer_head_line + . "\n"; + // build first row of header if needed + if ($leftheader != '' || $rightheader !='') { - if ( ($anscount - $fn + 1) >= $minrepeatheadings ) + $answer_head1 = "\n" + . "\t\n" + . "\t\n"; + if (count($labelans1)>0) { - $answer .= "\n";// Close actual body and open another one - //$answer .= $answer_head1; - $answer .= "\n\n" - . $answer_head_line - . "\n"; + $answer_head1 .= "\t\n" // Separator + ."\t\n"; + } + if($shownoanswer || $rightexists) + { + $rigthclass=($rightexists)?" header_answer_text_right":""; + $answer_head1 .= "\t\n"; + if($shownoanswer) + { + $answer_head1 .= "\t\n"; + } } + $answer_head1 .= "\n"; } - - $trbc = alternation($trbc , 'row'); - $answertext=dTexts__run($ansrow['question']); - $answertextsave=$answertext; - - $dualgroup=0; - $myfname0= $ia[1].$ansrow['title']; - $myfname = $ia[1].$ansrow['title'].'#0'; - $myfname1 = $ia[1].$ansrow['title'].'#1'; // new multi-scale-answer - /* Check if this item has not been answered: the 'notanswered' variable must be an array, - containing a list of unanswered questions, the current question must be in the array, - and there must be no answer available for the item in this session. */ - if ($ia[6]=='Y' && (is_array($notanswered)) && ((array_search($myfname, $notanswered) !== FALSE) || (array_search($myfname1, $notanswered) !== FALSE)) && (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1] == '')) ) + else { - $answertext = "{$answertext}"; + $answer_head1 = ""; } + $answer .= "\n
".$clang->gT('No answer')."
 $leftheader
 $rightheader  
\n" + . $mycolumns + . "\n\t\n" + . $answer_head1 + . $answer_head2 + . "\n\t\n" + . "\n"; - // Get array_filter stuff - list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname0, $trbc, $myfname,"tr","$trbc answers-list radio-list"); + // And no each line of body + $trbc = ''; + foreach ($aSubQuestions as $ansrow) + { + // Build repeat headings if needed + if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) + { + if ( ($anscount - $fn + 1) >= $minrepeatheadings ) + { + $answer .= "\n";// Close actual body and open another one + //$answer .= $answer_head1; + $answer .= "\n\n" + . $answer_head_line + . "\n"; + } + } + $trbc = alternation($trbc , 'row'); + $answertext=$ansrow['question']; - $answer .= $htmltbody2; + // rigth and center answertext: not explode for ? Why not + if(strpos($answertext,'|')) + { + $answertextrigth=substr($answertext,strpos($answertext,'|')+1); + $answertext=substr($answertext,0, strpos($answertext,'|')); + } + else + { + $answertextrigth=""; + } + if($centerexists) + { + $answertextcenter=substr($answertextrigth,0, strpos($answertextrigth,'|')); + $answertextrigth=substr($answertextrigth,strpos($answertextrigth,'|')+1); + } + else + { + $answertextcenter=""; + } - if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} + $myfname= $ia[1].$ansrow['title']; + $myfname0 = $ia[1].$ansrow['title'].'#0'; + $myfid0 = $ia[1].$ansrow['title'].'_0'; + $myfname1 = $ia[1].$ansrow['title'].'#1'; // new multi-scale-answer + $myfid1 = $ia[1].$ansrow['title'].'_1'; + /* Check if this item has not been answered: the 'notanswered' variable must be an array, + containing a list of unanswered questions, the current question must be in the array, + and there must be no answer available for the item in this session. */ + if ($ia[6]=='Y' && (is_array($notanswered)) && ((array_search($myfname0, $notanswered) !== FALSE) || (array_search($myfname1, $notanswered) !== FALSE)) && (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1] == '')) ) + { + $answertext = "{$answertext}"; + } + // Get array_filter stuff + list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname,"tr","$trbc answers-list radio-list"); + $answer .= $htmltbody2; - array_push($inputnames,$myfname); - $answer .= "\t\n"; - $hiddenanswers=''; - $thiskey=0; - foreach ($labelcode as $ld) - { - $answer .= "\t\n"; $hiddenanswers=''; - $answer .= "\t\n"; // separator - array_push($inputnames,$myfname1); - $hiddenanswers .= "getConfig('surveyID')][$myfname1])) {$hiddenanswers .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1];} - $hiddenanswers .= "\" />\n"; $thiskey=0; - foreach ($labelcode1 as $ld) // second label set + foreach ($labelcode0 as $ld) { - $answer .= "\t\n"; + $answer .= " />\n\n"; + $answer .= "\n\t\n"; $thiskey++; } - } - if (strpos($answertextsave,'|')) - { - $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); - $answer .= "\t\n"; - $hiddenanswers = ''; - } - elseif ($right_exists) - { - $answer .= "\t\n"; - } - - if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) - { - $answer .= "\t\n"; // separator - $answer .= "\t\n"; // separator + array_push($inputnames,$myfname1); + $thiskey=0; + foreach ($labelcode1 as $ld) // second label set + { + $answer .= "\t\n"; + $thiskey++; + } } - // --> START NEW FEATURE - SAVE - $answer .= " onclick=\"noanswer_checkconditions(this.value, this.name, this.type)\" />\n" - . "\n" - . "\t\n"; - // --> END NEW FEATURE - SAVE + if ($shownoanswer || $rightexists) + { + $answer .= "\t\n"; + } + if ($shownoanswer) + { + $answer .= "\t\n"; + } + $answer .= "\n"; + $fn++; } - - $answer .= "\n"; - // $inputnames[]=$myfname; - //IF a MULTIPLE of flexi-redisplay figure, repeat the headings - $fn++; - } - $answer .= "\t\n"; - $answer .= "
\n" - . $hiddenfield - . "$answertext\n" - . "getConfig('surveyID')][$myfname])) {$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname];} - $answer .= "\" />\n\t\n" - . "\n" + . $hiddenfield + . "$answertext\n"; + // Hidden answers used by EM: sure can be added in javascript + $answer .= "getConfig('surveyID')][$myfname0])) {$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0];} + $answer .= "\" />\n"; + if (count($labelans1)>0) // if second label set is used { - $answer .= CHECKED; + $answer .= "getConfig('surveyID')][$myfname1])) {$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1];} + $answer .= "\" />\n"; } - // --> START NEW FEATURE - SAVE - $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n\n"; - // --> END NEW FEATURE - SAVE - $answer .= "\n\t\n"; - $thiskey++; - } - if (count($labelans1)>0) // if second label set is used - { - $dualgroup++; + $answer .= "\t \n"; - if ($hiddenanswers!='') - { - $answer .=$hiddenanswers; - $hiddenanswers=''; - } - $answer .= "\n" + . "\n"; - // --> END NEW FEATURE - SAVE - - $answer .= "\t$answertext  \n" - . ""; + if ($shownoanswer)// No answer for accessibility and no javascript (but hide hide even with no js: need reworking) + { + $answer .= "\n"; + } + $answer .= "{$answertextcenter}\n"; + $answer .= "\n"; + $answer .= "\t{$answertextrigth}\n"; + if (count($labelans1)>0) + { + $answer .= "\n"; + } + else + { + $answer .= "\n"; + } + $answer .= "\t
\n"; - } - elseif ($useDropdownLayout === true && count($aAnswersScale1) > 0) - { - - if (trim($aQuestionAttributes['answer_width'])!='') - { - $answerwidth=$aQuestionAttributes['answer_width']; - } else { - $answerwidth=20; - } - $separatorwidth=(100-$answerwidth)/10; - $columnswidth=100-$answerwidth-($separatorwidth*2); - - $answer = ""; - - // Get Answers - - //question atribute random_order set? - if ($aQuestionAttributes['random_order']==1) { - $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ORDER BY ".dbRandom(); - } - - //no question attributes -> order by sortorder - else - { - $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ORDER BY question_order"; + $answer.="\n"; + $answer.=""; } - $ansresult = dbExecuteAssoc($ansquery); - $aSubquestions=$ansresult->readAll(); //Checked - $anscount = count($aSubquestions); - - if ($anscount==0) + elseif($useDropdownLayout === true) { - $inputnames = array(); - $answer .="\n

".$clang->gT('Error: This question has no answers.')."

\n"; - } - else - { - - //already done $lresult = dbExecuteAssoc($lquery); - foreach ($aAnswersScale1 as $lrow) - { - $labels0[]=Array('code' => $lrow['code'], - 'title' => $lrow['answer']); - } - $lresult1 = dbExecuteAssoc($lquery1); //Checked - foreach ($lresult1->readAll() as $lrow1) - { - $labels1[]=Array('code' => $lrow1['code'], - 'title' => $lrow1['answer']); - } + $separatorwidth=(100-$answerwidth)/10; + $cellwidth=(100-$answerwidth-$separatorwidth)/2; + $answer = ""; // Get attributes for Headers and Prefix/Suffix - if (trim($aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='') { list ($ddprefix, $ddsuffix) =explode("|",$aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]); $ddprefix = $ddprefix; @@ -6477,101 +6440,113 @@ function do_array_dual($ia) } if (trim($aQuestionAttributes['dropdown_separators'])!='') { list ($postanswSep, $interddSep) =explode('|',$aQuestionAttributes['dropdown_separators']); - $postanswSep = $postanswSep; - $interddSep = $interddSep; + $postanswSep = $postanswSep;// Not used, nether in 2.0 or 1.92: category ? + $interddSep = $interddSep;// it's in seperator .... replace by $rigth/center like before are the best solution } else { $postanswSep = ''; $interddSep = ''; } - $colspan_1 = ''; $colspan_2 = ''; $suffix_cell = ''; $answer .= "\n\n\n" . "\t\n"; + + if($ddprefix != '' || $ddsuffix != '') + { + $answer .= "\t\n"; + } if($ddprefix != '') { - $answer .= "\t\n"; + $answer .= "\t\t\n"; $colspan_1 = ' colspan="2"'; } - $answer .= "\t\n"; + $headcolwidth=($ddprefix != '' || $ddsuffix != '')?"":" width=\"$cellwidth%\""; + $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; - if(!empty($colspan_1)) - { - $colspan_2 = ' colspan="3"'; - } - $suffix_cell = "\t\n"; // suffix } - $answer .= "\t\n"; + if($ddprefix != '' || $ddsuffix != '') + { + $answer .= "\t\n"; + } + $answer .= "\t\n"; + if($ddprefix != '' || $ddsuffix != '') + { + $answer .= "\t\n"; + } if($ddprefix != '') { - $answer .= "\t\n"; + $answer .= "\t\t\n"; } - $answer .= "\t\n"; + $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; - }; + } + if($ddprefix != '' || $ddsuffix != '') + { + $answer .= "\t\n"; + } + // colspan : for header only + if($ddprefix != '' && $ddsuffix != '') + $colspan=' colspan="3"'; + elseif($ddprefix != '' || $ddsuffix != '') + $colspan=' colspan="2"'; + else + $colspan=""; // headers $answer .= "\n\t\n" . "\n" - . "\t \n" // prefix - . "\n" - // . "\t\n" - . "\t\n" - . "\n" - . "\t \n" // suffix // Inter DD separator // prefix - // . "\t\n" - . "\t\n" - . $suffix_cell."\n" - . "\t\n\n"; + . "\t\n" + . "\t$leftheader\n" + . "\t\n" + . "\t$rightheader\n"; + $answer .="\t\n" + . "\t\n"; $answer .= "\n\n"; $trbc = ''; - foreach ($aSubquestions as $ansrow) + foreach ($aSubQuestions as $ansrow) { - $rowname = $ia[1].$ansrow['title']; - $dualgroup=0; - $myfname = $ia[1].$ansrow['title']."#".$dualgroup; - $dualgroup1=1; - $myfname1 = $ia[1].$ansrow['title']."#".$dualgroup1; + $myfname = $ia[1].$ansrow['title']; + $myfname0 = $ia[1].$ansrow['title']."#0"; + $myfid0 = $ia[1].$ansrow['title']."_0"; + $myfname1 = $ia[1].$ansrow['title']."#1"; + $myfid1 = $ia[1].$ansrow['title']."_1"; - if ($ia[6]=='Y' && (is_array($notanswered)) && ((array_search($myfname, $notanswered) !== FALSE) || (array_search($myfname1, $notanswered) !== FALSE)) && (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1] == '')) ) + if ($ia[6]=='Y' && (is_array($notanswered)) && ((array_search($myfname0, $notanswered) !== FALSE) || (array_search($myfname1, $notanswered) !== FALSE)) && (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1] == '')) ) { - $answertext="".dTexts__run($ansrow['question']).""; + $answertext="".$ansrow['question'].""; } else { - $answertext=dTexts__run($ansrow['question']); + $answertext=$ansrow['question']; } - - $trbc = alternation($trbc , 'row'); - - // Get array_filter stuff - list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $rowname, $trbc, $myfname,"tr","$trbc subquestion-list questions-list dropdown-list"); - + list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname,"tr","$trbc subquestion-list questions-list dropdown-list"); $answer .= $htmltbody2; - $answer .= "\t\n"; - - // Label0 - - // prefix + . "\n"; + // Hidden answers used by EM: sure can be added in javascript + $answer .= "getConfig('surveyID')][$myfname0])) {$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0];} + $answer .= "\" />\n"; + $answer .= "getConfig('surveyID')][$myfname1])) {$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1];} + $answer .= "\" />\n"; + $answer . "\t\n"; + // Selector 0 if($ddprefix != '') { $answer .= "\t\n"; } $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; } - $answer .= "getConfig('surveyID')][$myfname])) - { - $answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]; - } - $answer .= "\" />\n" - . "\t\n"; - - $inputnames[]=$myfname; + $inputnames[]=$myfname0; $answer .= "\t\n"; //Separator - // Label1 - - // prefix + // Selector 1 if($ddprefix != '') { $answer .= "\t\n"; } - // $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; } - $answer .= "getConfig('surveyID')][$myfname1])) - { - $answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1]; - } - $answer .= "\" />\n" - . "\t\n"; $inputnames[]=$myfname1; $answer .= "\n"; } - } // End there are answers - $answer .= "\t\n"; - $answer .= "
 
$leftheader$leftheader$rightheader$rightheader
  
\n" - . "$ddprefix\n" - . "\n"; - if (!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] =='') + if (!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0] =='') { $answer .= "\t\n"; } @@ -6579,7 +6554,7 @@ function do_array_dual($ia) foreach ($labels0 as $lrow) { $answer .= "\t\n"; } $answer .= "\n"; - - // suffix + $answer .= "$ddsuffix$interddSep$ddprefix\n" $answer .= "\t\n" - . "\n"; if (empty($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname])) { $answer .= "\t\n"; } - foreach ($labels1 as $lrow1) { $answer .= "\t\n"; } $answer .= "\n"; - - // suffix + $answer .= "$ddsuffix
\n"; + $answer .= "\t\n"; + $answer .= "\n"; + } } else { $answer = "

".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."

\n"; $inputnames=""; } + header_includes("dualscale.js"); + $answer .= "\n"; return array($answer, $inputnames); } diff --git a/scripts/dualscale.js b/scripts/dualscale.js new file mode 100644 index 00000000000..568801d3a99 --- /dev/null +++ b/scripts/dualscale.js @@ -0,0 +1,61 @@ +/* + * @license This file is part of LimeSurvey + * Copyright (C) 2007-2013 The LimeSurvey Project Team / Carsten Schmitz / Denis Chenu + * All rights reserved. + * License: GNU/GPL License v2 or later, see LICENSE.php + * LimeSurvey is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * See COPYRIGHT.php for copyright notices and details. + * + * + */ + +/** + * Update answers part for a dual scale radio question and lauch EM + * + * @author Denis Chenu (Shnoulle) + * @param {number} qId The qid of the question where apply. + */ +function doDualScaleRadio(qID) { + // We can do it before document ready, because function come after answers and we use delegate + $("#question"+qID+" .jshide").hide(); + + // Lauch EM with hidden input + $("#question"+qID+" table.question").delegate(".noanswer-item","click",function(){ + $(this).closest("tr").find(".answer-item :radio").removeAttr("checked"); + $(this).closest("tr").find(".noanswer-item :radio").attr("checked","checked"); + name=$(this).find(":radio").attr("name"); + name0=name.replace("#1","_0"); + name1=name.replace('#','_'); + $("#java"+name0).val(""); + $("#java"+name1).val(""); + ExprMgr_process_relevance_and_tailoring('change',name0,'hidden'); + ExprMgr_process_relevance_and_tailoring('change',name1,'hidden'); + }); + $("#question"+qID+" table.question").delegate(".answer-item:not(.noanswer-item)","click",function(){// Don't attach to radio because prepareCellAdapters don't throw click ... + name=$(this).find(":radio").attr("name"); + name=name.replace('#','_'); + value=""+$(this).find(":radio").val(); + $(this).closest("tr").find(".noanswer-item :radio").removeAttr("checked"); + $("#java"+name).val(value); + ExprMgr_process_relevance_and_tailoring('change',name,'radio'); + }); +} + +/** + * Update answers part for a dual scale dropdown question and lauch EM + * + * @author Denis Chenu (Shnoulle) + * @param {number} qId The qid of the question where apply. + */ +function doDualScaleDropDown(qID) { + $("#question"+qID+" table.question").delegate("select","change",function(){ + name=$(this).attr("name"); + name=name.replace('#','_'); + value=""+$(this).val(); + $("#java"+name).val(value); + ExprMgr_process_relevance_and_tailoring('change',name,'select'); + }); +} diff --git a/scripts/survey_runtime.js b/scripts/survey_runtime.js index a6384a68cca..e27a9eb1b6e 100644 --- a/scripts/survey_runtime.js +++ b/scripts/survey_runtime.js @@ -939,17 +939,22 @@ function multi_set(ids,_radix) } //Special function for array dual scale in drop down layout to check conditions -function array_dual_dd_checkconditions(value, name, type, rank, condfunction) -{ - if (value == '') { - //If value is set to empty, reset both drop downs and check conditions - if (rank == 0) { dualname = name.replace(/#0/g,"#1"); } - else if (rank == 1) { dualname = name.replace(/#1/g,"#0"); } - document.getElementsByName(dualname)[0].value=value; - condfunction(value, dualname, type); - } - condfunction(value, name, type); -} +/* +Deactivated 20130221 +Why do this: a user can answer one select and not another one +Never change default behaviour if it's not good for respondant +*/ +//function array_dual_dd_checkconditions(value, name, type, rank, condfunction) +//{ +// if (value == '') { +// //If value is set to empty, reset both drop downs and check conditions +// if (rank == 0) { dualname = name.replace(/#0/g,"#1"); } +// else if (rank == 1) { dualname = name.replace(/#1/g,"#0"); } +// document.getElementsByName(dualname)[0].value=value; +// condfunction(value, dualname, type); +// } +// condfunction(value, name, type); +//} /* Maxlengt on textarea */ function maxlengthtextarea(){