Beispiel #1
0
function do_array_dual($ia)
{
    global $thissurvey;
    $aLastMoveResult = LimeExpressionManager::GetLastMoveResult();
    $aMandatoryViolationSubQ = $aLastMoveResult['mandViolation'] && $ia[6] == 'Y' ? explode("|", $aLastMoveResult['unansweredSQs']) : array();
    $repeatheadings = Yii::app()->getConfig("repeatheadings");
    $minrepeatheadings = Yii::app()->getConfig("minrepeatheadings");
    $extraclass = "";
    $answertypeclass = "";
    // Maybe not
    $caption = "";
    // Just leave empty, are replaced after
    $inputnames = array();
    $labelans1 = array();
    $labelans = array();
    $aQuestionAttributes = getQuestionAttributeValues($ia[0]);
    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";
    $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
        $caption = gT("An array with sub-question on each line, with 2 answers to provide on each line. You have to select the answer.");
    } else {
        $useDropdownLayout = false;
        $extraclass .= " radio-list";
        $answertypeclass .= " radio";
        $doDualScaleFunction = "doDualScaleRadio";
        $caption = gT("An array with sub-question on each line, with 2 answers to provide on each line. The answers are contained in the table header. ");
    }
    if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) {
        $repeatheadings = intval($aQuestionAttributes['repeat_headings']);
        $minrepeatheadings = 0;
    }
    if (trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $leftheader = $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
    } else {
        $leftheader = '';
    }
    if (trim($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 = '';
    }
    if (trim($aQuestionAttributes['answer_width']) != '') {
        $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
    // 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($aAnswersScale0) > 0 && $anscount) {
        $answer = "";
        $fn = 1;
        // Used by repeat_heading
        if ($useDropdownLayout === false) {
            $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++;
                $caption .= gT("The last cell are for no answer. ");
            }
            if ($rightexists) {
                $numrows++;
            }
            if ($centerexists) {
                $numrows++;
            }
            $cellwidth = $columnswidth / $numrows;
            //$cellwidth=sprintf("%02d", $cellwidth); // No reason to do this, except to leave place for separator ?  But then table can not be the same in all browser
            // Header row and colgroups
            $mycolumns = "\t<col class=\"col-answers\" width=\"{$answerwidth}%\" />\n";
            $answer_head_line = "\t<th class=\"header_answer_text\">&nbsp;</th>\n\n";
            $mycolumns .= "\t<colgroup class=\"col-responses group-1\">\n";
            $odd_even = '';
            foreach ($labelans0 as $ld) {
                $answer_head_line .= "\t<th>" . $ld . "</th>\n";
                $odd_even = alternation($odd_even);
                $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n";
            }
            $mycolumns .= "\t</colgroup>\n";
            if (count($labelans1) > 0) {
                $separatorwidth = $centerexists ? "width=\"{$cellwidth}%\" " : "";
                $mycolumns .= "\t<col class=\"separator\" {$separatorwidth}/>\n";
                $mycolumns .= "\t<colgroup class=\"col-responses group-2\">\n";
                $answer_head_line .= "\n\t<td class=\"header_separator\">&nbsp;</td>\n\n";
                // Separator : and No answer for accessibility for first colgroup
                foreach ($labelans1 as $ld) {
                    $answer_head_line .= "\t<th>" . $ld . "</th>\n";
                    $odd_even = alternation($odd_even);
                    $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n";
                }
                $mycolumns .= "\t</colgroup>\n";
            }
            if ($shownoanswer || $rightexists) {
                $rigthwidth = $rightexists ? "width=\"{$cellwidth}%\" " : "";
                $mycolumns .= "\t<col class=\"separator rigth_separator\" {$rigthwidth}/>\n";
                $answer_head_line .= "\n\t<td class=\"header_separator rigth_separator\">&nbsp;</td>\n";
            }
            if ($shownoanswer) {
                $mycolumns .= "\t<col class=\"col-no-answer\"  width=\"{$cellwidth}%\" />\n";
                $answer_head_line .= "\n\t<th class=\"header_no_answer\">" . gT('No answer') . "</th>\n";
            }
            $answer_head2 = "\n<tr class=\"array1 header_row dontread\">\n" . $answer_head_line . "</tr>\n";
            // build first row of header if needed
            if ($leftheader != '' || $rightheader != '') {
                $answer_head1 = "<tr class=\"array1 groups header_row\">\n" . "\t<th class=\"header_answer_text\">&nbsp;</th>\n" . "\t<th colspan=\"" . count($labelans0) . "\" class=\"dsheader\">{$leftheader}</th>\n";
                if (count($labelans1) > 0) {
                    $answer_head1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n" . "\t<th colspan=\"" . count($labelans1) . "\" class=\"dsheader\">{$rightheader}</th>\n";
                }
                if ($shownoanswer || $rightexists) {
                    $rigthclass = $rightexists ? " header_answer_text_right" : "";
                    $answer_head1 .= "\t<td class=\"header_separator {$rigthclass}\">&nbsp;</td>\n";
                    if ($shownoanswer) {
                        $answer_head1 .= "\t<th class=\"header_no_answer\">&nbsp;</th>\n";
                    }
                }
                $answer_head1 .= "</tr>\n";
            } else {
                $answer_head1 = "";
            }
            $answer .= "\n<table class=\"question subquestions-list questions-list\" summary=\"{$caption}\">\n" . $mycolumns . "\n\t<thead>\n" . $answer_head1 . $answer_head2 . "\n\t</thead>\n" . "<tbody>\n";
            // 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 .= "</tbody>\n<tbody>";
                        // Close actual body and open another one
                        //$answer .= $answer_head1;
                        $answer .= "\n<tr class=\"repeat headings\">\n" . $answer_head_line . "</tr>\n";
                    }
                }
                $trbc = alternation($trbc, 'row');
                $answertext = $ansrow['question'];
                // 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 = "";
                }
                $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 the Sub Q mandatory violation */
                if ($ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ))) {
                    $answertext = "<span class='errormandatory'>{$answertext}</span>";
                }
                // 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, $myfname0);
                $answer .= "\t<th class=\"answertext\">\n" . $hiddenfield . "{$answertext}\n";
                // Hidden answers used by EM: sure can be added in javascript
                $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid0}\" id=\"java{$myfid0}\" value=\"";
                if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0])) {
                    $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0];
                }
                $answer .= "\" />\n";
                if (count($labelans1) > 0) {
                    $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid1}\" id=\"java{$myfid1}\" value=\"";
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) {
                        $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1];
                    }
                    $answer .= "\" />\n";
                }
                $answer .= "\t</th>\n";
                $hiddenanswers = '';
                $thiskey = 0;
                foreach ($labelcode0 as $ld) {
                    $answer .= "\t<td class=\"answer_cell_1_00{$ld} answer-item {$answertypeclass}-item\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname0}\" value=\"{$ld}\" id=\"answer{$myfid0}-{$ld}\" ";
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == $ld) {
                        $answer .= CHECKED;
                    }
                    $answer .= "  />\n" . "<label class=\"hide read\" for=\"answer{$myfid0}-{$ld}\">{$labelans0[$thiskey]}</label>\n" . "\n\t</td>\n";
                    $thiskey++;
                }
                if (count($labelans1) > 0) {
                    $answer .= "\t<td class=\"dual_scale_separator information-item\">";
                    if ($shownoanswer) {
                        $answer .= "\t<input class='radio jshide read' type='radio' name='{$myfname0}' value='' id='answer{$myfid0}-' ";
                        if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") {
                            $answer .= CHECKED;
                        }
                        $answer .= " />\n";
                    }
                    $answer .= "<label for='answer{$myfid0}-' class= \"hide read\">" . gT("No answer") . "</label>";
                    $answer .= "\t{$answertextcenter}</td>\n";
                    // separator
                    array_push($inputnames, $myfname1);
                    $thiskey = 0;
                    foreach ($labelcode1 as $ld) {
                        $answer .= "\t<td class=\"answer_cell_2_00{$ld}  answer-item radio-item\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname1}\" value=\"{$ld}\" id=\"answer{$myfid1}-{$ld}\" ";
                        if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $ld) {
                            $answer .= CHECKED;
                        }
                        $answer .= " />\n" . "<label class=\"hide read\" for=\"answer{$myfid1}-{$ld}\">{$labelans1[$thiskey]}</label>\n" . "\t</td>\n";
                        $thiskey++;
                    }
                }
                if ($shownoanswer || $rightexists) {
                    $answer .= "\t<td class=\"answertextright dual_scale_separator information-item\">{$answertextrigth}</td>\n";
                }
                if ($shownoanswer) {
                    $answer .= "\t<td class=\"dual_scale_no_answer answer-item radio-item noanswer-item\">\n";
                    if (count($labelans1) > 0) {
                        $answer .= "\t<input class='radio' type='radio' name='{$myfname1}' value='' id='answer{$myfid1}-' ";
                        if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == "") {
                            $answer .= CHECKED;
                        }
                        // --> START NEW FEATURE - SAVE
                        $answer .= " />\n";
                        $answer .= "<label class='hide read' for='answer{$myfid1}-'>" . gT("No answer") . "</label>";
                    } else {
                        $answer .= "\t<input class='radio' type='radio' name='{$myfname0}' value='' id='answer{$myfid0}-' ";
                        if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") {
                            $answer .= CHECKED;
                        }
                        $answer .= "<label class='hide read' for='answer{$myfid0}-'>" . gT("No answer") . "<label>\n";
                        $answer .= " />\n";
                    }
                    $answer .= "\t</td>\n";
                }
                $answer .= "</tr>\n";
                $fn++;
            }
            $answer .= "</tbody>\n";
            $answer .= "</table>";
        } elseif ($useDropdownLayout === true) {
            $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;
                $ddsuffix = $ddsuffix;
            } else {
                $ddprefix = '';
                $ddsuffix = '';
            }
            if (trim($aQuestionAttributes['dropdown_separators']) != '') {
                $aSeparator = explode('|', $aQuestionAttributes['dropdown_separators']);
                if (isset($aSeparator[1])) {
                    $interddSep = $aSeparator[1];
                } else {
                    $interddSep = $aSeparator[0];
                }
            } else {
                $interddSep = '';
            }
            $colspan_1 = '';
            $colspan_2 = '';
            $suffix_cell = '';
            $answer .= "\n<table class=\"question subquestion-list questions-list dropdown-list\" summary=\"{$caption}\">\n" . "\t<col class=\"answertext\" width=\"{$answerwidth}%\" />\n";
            if ($ddprefix != '' || $ddsuffix != '') {
                $answer .= "\t<colgroup width=\"{$cellwidth}%\">\n";
            }
            if ($ddprefix != '') {
                $answer .= "\t\t<col class=\"ddprefix\" />\n";
                $colspan_1 = ' colspan="2"';
            }
            $headcolwidth = $ddprefix != '' || $ddsuffix != '' ? "" : " width=\"{$cellwidth}%\"";
            $answer .= "\t<col class=\"dsheader\"{$headcolwidth} />\n";
            if ($ddsuffix != '') {
                $answer .= "\t<col class=\"ddsuffix\" />\n";
            }
            if ($ddprefix != '' || $ddsuffix != '') {
                $answer .= "\t</colgroup>\n";
            }
            $answer .= "\t<col class=\"ddarrayseparator\" width=\"{$separatorwidth}%\" />\n";
            if ($ddprefix != '' || $ddsuffix != '') {
                $answer .= "\t<colgroup width=\"{$cellwidth}%\">\n";
            }
            if ($ddprefix != '') {
                $answer .= "\t\t<col class=\"ddprefix\" />\n";
            }
            $answer .= "\t<col class=\"dsheader\"{$headcolwidth} />\n";
            if ($ddsuffix != '') {
                $answer .= "\t<col class=\"ddsuffix\" />\n";
            }
            if ($ddprefix != '' || $ddsuffix != '') {
                $answer .= "\t</colgroup>\n";
            }
            // colspan : for header only
            if ($ddprefix != '' && $ddsuffix != '') {
                $colspan = ' colspan="3"';
            } elseif ($ddprefix != '' || $ddsuffix != '') {
                $colspan = ' colspan="2"';
            } else {
                $colspan = "";
            }
            // headers
            $answer .= "\n\t<thead>\n" . "<tr>\n" . "\t<td>&nbsp;</td>\n" . "\t<th{$colspan}>{$leftheader}</th>\n" . "\t<td>&nbsp;</td>\n" . "\t<th{$colspan}>{$rightheader}</th>\n";
            $answer .= "\t</tr>\n" . "\t</thead>\n";
            $answer .= "\n<tbody>\n";
            $trbc = '';
            foreach ($aSubQuestions as $ansrow) {
                $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";
                $sActualAnswer0 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] : "";
                $sActualAnswer1 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] : "";
                if ($ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ))) {
                    $answertext = "<span class='errormandatory'>" . $ansrow['question'] . "</span>";
                } else {
                    $answertext = $ansrow['question'];
                }
                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<th class=\"answertext\">\n" . "<label for=\"answer{$myfid0}\">{$answertext}</label>\n";
                // Hidden answers used by EM: sure can be added in javascript
                $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid0}\" id=\"java{$myfid0}\" value=\"{$sActualAnswer0}\" />\n";
                $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid1}\" id=\"java{$myfid1}\" value=\"{$sActualAnswer1}\" />\n";
                $answer . "\t</th>\n";
                // Selector 0
                if ($ddprefix != '') {
                    $answer .= "\t<td class=\"ddprefix information-item\">{$ddprefix}</td>\n";
                }
                $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<select name=\"{$myfname0}\" id=\"answer{$myfid0}\">\n";
                // Show the 'Please choose' if there are no answer actually
                if ($sActualAnswer0 == '') {
                    $answer .= "\t<option value=\"\" " . SELECTED . ">" . gT('Please choose...') . "</option>\n";
                }
                foreach ($labels0 as $lrow) {
                    $answer .= "\t<option value=\"" . $lrow['code'] . '" ';
                    if ($sActualAnswer0 == $lrow['code']) {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . flattenText($lrow['title']) . "</option>\n";
                }
                if ($sActualAnswer0 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER) {
                    $answer .= "\t<option value=\"\">" . gT('No answer') . "</option>\n";
                }
                $answer .= "</select>\n";
                $answer .= "</td>\n";
                if ($ddsuffix != '') {
                    $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n";
                }
                $inputnames[] = $myfname0;
                $answer .= "\t<td class=\"ddarrayseparator information-item\">{$interddSep}</td>\n";
                //Separator
                // Selector 1
                if ($ddprefix != '') {
                    $answer .= "\t<td class='ddprefix information-item'>{$ddprefix}</td>\n";
                }
                $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<label class=\"hide read\" for=\"answer{$myfid1}\">{$answertext}</label>" . "<select name=\"{$myfname1}\" id=\"answer{$myfid1}\">\n";
                // Show the 'Please choose' if there are no answer actually
                if ($sActualAnswer1 == '') {
                    $answer .= "\t<option value=\"\" " . SELECTED . ">" . gT('Please choose...') . "</option>\n";
                }
                foreach ($labels1 as $lrow1) {
                    $answer .= "\t<option value=\"" . $lrow1['code'] . '" ';
                    if ($sActualAnswer1 == $lrow1['code']) {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . flattenText($lrow1['title']) . "</option>\n";
                }
                if ($sActualAnswer1 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER) {
                    $answer .= "\t<option value=\"\">" . gT('No answer') . "</option>\n";
                }
                $answer .= "</select>\n";
                $answer .= "</td>\n";
                if ($ddsuffix != '') {
                    $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n";
                }
                $inputnames[] = $myfname1;
                $answer .= "</tr>\n";
            }
            $answer .= "\t</tbody>\n";
            $answer .= "</table>\n";
        }
    } else {
        $answer = "<p class='error'>" . gT("Error: There are no answer options for this question and/or they don't exist in this language.") . "</p>\n";
        $inputnames = "";
    }
    Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "dualscale.js");
    $answer .= "<script type='text/javascript'>\n" . "  <!--\n" . " {$doDualScaleFunction}({$ia[0]});\n" . " -->\n" . "</script>\n";
    return array($answer, $inputnames);
}
Beispiel #2
0
function do_array_dual($ia)
{
    global $thissurvey;
    $aLastMoveResult = LimeExpressionManager::GetLastMoveResult();
    $aMandatoryViolationSubQ = $aLastMoveResult['mandViolation'] && $ia[6] == 'Y' ? explode("|", $aLastMoveResult['unansweredSQs']) : array();
    $repeatheadings = Yii::app()->getConfig("repeatheadings");
    $minrepeatheadings = Yii::app()->getConfig("minrepeatheadings");
    $extraclass = "";
    $answertypeclass = "";
    // Maybe not
    $caption = "";
    // Just leave empty, are replaced after
    $inputnames = array();
    $labelans1 = array();
    $labelans = array();
    /*
     * Get Question Attributes
     */
    $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
    // Get questions and answers by defined order
    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";
    $lresult1 = dbExecuteAssoc($lquery1);
    //Checked
    $aAnswersScale1 = $lresult1->readAll();
    // Set attributes
    if ($aQuestionAttributes['use_dropdown'] == 1) {
        $useDropdownLayout = true;
        $extraclass .= " dropdown-list";
        $answertypeclass .= " dropdown";
        $doDualScaleFunction = "doDualScaleDropDown";
        // javascript funtion to lauch at end of answers
        $caption = gT("A table with a subquestion on each row, with two answers to provide on each line.  Please select the answers.");
    } else {
        $useDropdownLayout = false;
        $extraclass .= " radio-list";
        $answertypeclass .= " radio";
        $doDualScaleFunction = "doDualScaleRadio";
        $caption = gT("A table with one subquestion on each row and two answers to provide on each row. The related answer options are in the top table header row.");
    }
    if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) {
        $repeatheadings = intval($aQuestionAttributes['repeat_headings']);
        $minrepeatheadings = 0;
    }
    $leftheader = trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? $leftheader = $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] : '';
    $rightheader = trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? $aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] : '';
    $answerwidth = trim($aQuestionAttributes['answer_width']) != '' ? $aQuestionAttributes['answer_width'] : 20;
    // Find if we have rigth and center text
    $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
    // 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($aAnswersScale0) > 0 && $anscount) {
        $answer = "";
        $fn = 1;
        // Used by repeat_heading
        // No drop-down
        if ($useDropdownLayout === false) {
            $aData = array();
            $aData['answertypeclass'] = $answertypeclass;
            $columnswidth = 100 - $answerwidth;
            $labelans0 = array();
            $labelans1 = array();
            $labelcode0 = array();
            $labelcode1 = array();
            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++;
                $caption .= gT("The last cell is for 'No answer'.");
            }
            if ($rightexists) {
                $numrows++;
            }
            if ($centerexists) {
                $numrows++;
            }
            $cellwidth = $columnswidth / $numrows;
            $cellwidth = sprintf("%02d", $cellwidth);
            // No reason to do this, except to leave place for separator ?  But then table can not be the same in all browser
            // Header row and colgroups
            $aData['answerwidth'] = $answerwidth;
            $aData['cellwidth'] = $cellwidth;
            $aData['labelans0'] = $labelans0;
            $aData['labelcode0'] = $labelcode0;
            $aData['labelans1'] = $labelans1;
            $aData['labelcode1'] = $labelcode1;
            $aData['separatorwidth'] = $centerexists ? "style='width: {$cellwidth}%;' " : "";
            $aData['shownoanswer'] = $shownoanswer;
            $aData['rightexists'] = $rightexists;
            $aData['rigthwidth'] = $rightexists ? "style='width: {$cellwidth}%;' " : "";
            // build first row of header if needed
            $aData['leftheader'] = $leftheader;
            $aData['rightheader'] = $rightheader;
            $aData['rigthclass'] = $rightexists ? " header_answer_text_right" : "";
            // And no each line of body
            $trbc = '';
            $aData['aSubQuestions'] = $aSubQuestions;
            foreach ($aSubQuestions as $i => $ansrow) {
                // Build repeat headings if needed
                if (isset($repeatheadings) && $repeatheadings > 0 && $fn - 1 > 0 && ($fn - 1) % $repeatheadings == 0) {
                    if ($anscount - $fn + 1 >= $minrepeatheadings) {
                        $aData['aSubQuestions'][$i]['repeatheadings'] = true;
                    }
                } else {
                    $aData['aSubQuestions'][$i]['repeatheadings'] = false;
                }
                $trbc = alternation($trbc, 'row');
                $answertext = $ansrow['question'];
                // rigth and center answertext: not explode for ? Why not
                if (strpos($answertext, '|')) {
                    $answertextright = substr($answertext, strpos($answertext, '|') + 1);
                    $answertext = substr($answertext, 0, strpos($answertext, '|'));
                } else {
                    $answertextright = "";
                }
                if ($centerexists) {
                    $answertextcenter = substr($answertextright, 0, strpos($answertextright, '|'));
                    $answertextright = substr($answertextright, strpos($answertextright, '|') + 1);
                } else {
                    $answertextcenter = "";
                }
                $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';
                $aData['aSubQuestions'][$i]['myfname'] = $myfname;
                $aData['aSubQuestions'][$i]['myfname0'] = $myfname0;
                $aData['aSubQuestions'][$i]['myfid0'] = $myfid0;
                $aData['aSubQuestions'][$i]['myfname1'] = $myfname1;
                $aData['aSubQuestions'][$i]['myfid1'] = $myfid1;
                $aData['aSubQuestions'][$i]['answertext'] = $ansrow['question'];
                /* Check the Sub Q mandatory violation */
                if ($ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ))) {
                    $aData['aSubQuestions'][$i]['showmandatoryviolation'] = true;
                } else {
                    $aData['aSubQuestions'][$i]['showmandatoryviolation'] = false;
                }
                // Get array_filter stuff
                list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "tr", "{$trbc} answers-list radio-list");
                $aData['aSubQuestions'][$i]['htmltbody2'] = $htmltbody2;
                $aData['aSubQuestions'][$i]['hiddenfield'] = $hiddenfield;
                array_push($inputnames, $myfname0);
                if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0])) {
                    $aData['aSubQuestions'][$i]['sessionfname0'] = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0];
                } else {
                    $aData['aSubQuestions'][$i]['sessionfname0'] = '';
                }
                if (count($labelans1) > 0) {
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) {
                        //$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1];
                        $aData['aSubQuestions'][$i]['sessionfname1'] = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1];
                    } else {
                        $aData['aSubQuestions'][$i]['sessionfname1'] = '';
                    }
                }
                foreach ($labelcode0 as $j => $ld) {
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == $ld) {
                        $aData['labelcode0_checked'][$ansrow['title']][$ld] = CHECKED;
                    } else {
                        $aData['labelcode0_checked'][$ansrow['title']][$ld] = "";
                    }
                }
                if (count($labelans1) > 0) {
                    if ($shownoanswer) {
                        if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") {
                            $answer .= CHECKED;
                            $aData['myfname0_notset'] = CHECKED;
                        } else {
                            $aData['myfname0_notset'] = "";
                        }
                    }
                    array_push($inputnames, $myfname1);
                    foreach ($labelcode1 as $j => $ld) {
                        if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $ld) {
                            $aData['labelcode1_checked'][$ansrow['title']][$ld] = CHECKED;
                        } else {
                            $aData['labelcode1_checked'][$ansrow['title']][$ld] = "";
                        }
                    }
                }
                $aData['answertextright'] = $answertextright;
                if ($shownoanswer) {
                    if (count($labelans1) > 0) {
                        if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == "") {
                            $answer .= CHECKED;
                            $aData['myfname1_notset'] = CHECKED;
                        } else {
                            $aData['myfname1_notset'] = "";
                        }
                    } else {
                        if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") {
                            $answer .= CHECKED;
                            $aData['myfname0_notset'] = CHECKED;
                        } else {
                            $aData['myfname0_notset'] = '';
                        }
                    }
                }
                $fn++;
            }
            $answer = doRender('/survey/questions/arrays/dualscale/answer', $aData, true);
        } elseif ($useDropdownLayout === true) {
            $aData = array();
            $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;
                $ddsuffix = $ddsuffix;
            } else {
                $ddprefix = '';
                $ddsuffix = '';
            }
            if (trim($aQuestionAttributes['dropdown_separators']) != '') {
                $aSeparator = explode('|', $aQuestionAttributes['dropdown_separators']);
                if (isset($aSeparator[1])) {
                    $interddSep = $aSeparator[1];
                } else {
                    $interddSep = $aSeparator[0];
                }
            } else {
                $interddSep = '';
            }
            $aData['answerwidth'] = $answerwidth;
            $aData['ddprefix'] = $ddprefix;
            $aData['ddsuffix'] = $ddsuffix;
            $aData['cellwidth'] = $cellwidth;
            ////// TODO: check in prev headcolwidth if style='width:$cellwidth' and not style='width:\"$cellwidth\"'
            $headcolwidth = $ddprefix != '' || $ddsuffix != '' ? "" : " style='width: {$cellwidth}%';";
            $aData['headcolwidth'] = $headcolwidth;
            $aData['separatorwidth'] = $separatorwidth;
            // colspan : for header only
            if ($ddprefix != '' && $ddsuffix != '') {
                $colspan = ' colspan="3"';
            } elseif ($ddprefix != '' || $ddsuffix != '') {
                $colspan = ' colspan="2"';
            } else {
                $colspan = "";
            }
            $aData['colspan'] = $colspan;
            $aData['leftheader'] = $leftheader;
            $aData['rightheader'] = $rightheader;
            $trbc = '';
            $aData['aSubQuestions'] = $aSubQuestions;
            foreach ($aSubQuestions as $i => $ansrow) {
                $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";
                $sActualAnswer0 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] : "";
                $sActualAnswer1 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] : "";
                $aData['aSubQuestions'][$i]['myfname'] = $myfname;
                $aData['aSubQuestions'][$i]['myfname0'] = $myfname0;
                $aData['aSubQuestions'][$i]['myfid0'] = $myfid0;
                $aData['aSubQuestions'][$i]['myfname1'] = $myfname1;
                $aData['aSubQuestions'][$i]['myfid1'] = $myfid1;
                $aData['aSubQuestions'][$i]['sActualAnswer0'] = $sActualAnswer0;
                $aData['aSubQuestions'][$i]['sActualAnswer1'] = $sActualAnswer1;
                // Set mandatory alert
                $aData['aSubQuestions'][$i]['alert'] = $ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ));
                list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "tr", "{$trbc} subquestion-list questions-list dropdown-list");
                $aData['aSubQuestions'][$i]['htmltbody2'] = $htmltbody2;
                $aData['aSubQuestions'][$i]['hiddenfield'] = $hiddenfield;
                $aData['labels0'] = $labels0;
                $aData['labels1'] = $labels1;
                $aData['aSubQuestions'][$i]['showNoAnswer0'] = $sActualAnswer0 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER;
                $aData['aSubQuestions'][$i]['showNoAnswer1'] = $sActualAnswer1 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER;
                $aData['interddSep'] = $interddSep;
                $inputnames[] = $myfname0;
                $inputnames[] = $myfname1;
            }
            $answer = doRender('/survey/questions/arrays/dualscale/answer_dropdown', $aData, true);
        }
    } else {
        $answer = "<p class='error'>" . gT("Error: There are no answer options for this question and/or they don't exist in this language.") . "</p>\n";
        $inputnames = "";
    }
    Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "dualscale.js");
    $answer .= "<script type='text/javascript'>\n" . "  <!--\n" . " {$doDualScaleFunction}({$ia[0]});\n" . " -->\n" . "</script>\n";
    return array($answer, $inputnames);
}
Beispiel #3
0
 public function doQuestion($ia)
 {
     global $thissurvey;
     if ($thissurvey['nokeyboard'] == 'Y') {
         includeKeypad();
         $kpclass = "text-keypad";
     } else {
         $kpclass = "";
     }
     $checkconditionFunction = "checkconditions";
     $aQuestionAttributes = getQuestionAttributeValues($ia[0]);
     $query = "SELECT other FROM {{questions}} WHERE qid=" . $ia[0] . " AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ";
     $result = Yii::app()->db->createCommand($query)->query();
     foreach ($result->readAll() as $row) {
         $other = $row['other'];
     }
     //question attribute random order set?
     if ($aQuestionAttributes['random_order'] == 1) {
         $ansquery = "SELECT * FROM {{answers}} WHERE qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY " . dbRandom();
     } elseif ($aQuestionAttributes['alphasort'] == 1) {
         $ansquery = "SELECT * FROM {{answers}} WHERE qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY answer";
     } else {
         $ansquery = "SELECT * FROM {{answers}} WHERE qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY sortorder, answer";
     }
     $ansresult = dbExecuteAssoc($ansquery)->readAll();
     //Checked
     $anscount = count($ansresult);
     if (trim($aQuestionAttributes['display_columns']) != '') {
         $dcols = $aQuestionAttributes['display_columns'];
     } else {
         $dcols = 1;
     }
     if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
         $othertext = $aQuestionAttributes['other_replace_text'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
     } else {
         $othertext = gT('Other:');
     }
     if (isset($other) && $other == 'Y') {
         $anscount++;
     }
     //Count up for the Other answer
     if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
         $anscount++;
     }
     //Count up if "No answer" is showing
     $wrapper = setupColumns($dcols, $anscount, "answers-list radio-list", "answer-item radio-item");
     $iBootCols = round(12 / $dcols);
     $ansByCol = round($anscount / $dcols);
     $ansByCol = $ansByCol > 0 ? $ansByCol : 1;
     //$answer = 'IKI: '.$iBootCols.' '.$ansByCol.' '.$wrapper['whole-start'];
     $answer = '<div class="row">';
     $answer .= '    <div class="col-xs-' . $iBootCols . '">AAAAAAAAAAAAAA';
     //Time Limit Code
     if (trim($aQuestionAttributes['time_limit']) != '') {
         $answer .= return_timer_script($aQuestionAttributes, $ia);
     }
     //End Time Limit Code
     // Get array_filter stuff
     $rowcounter = 0;
     $colcounter = 1;
     $trbc = '';
     foreach ($ansresult as $key => $ansrow) {
         $myfname = $ia[1] . $ansrow['code'];
         $check_ans = '';
         if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) {
             $check_ans = CHECKED;
         }
         list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, '', $myfname, "div", "form-group answer-item radio-item");
         /*    if(substr($wrapper['item-start'],0,4) == "\t<li")
                     {
                         $startitem = "\t$htmltbody2\n";
                     } else {
                         $startitem = $wrapper['item-start'];
                     }
         
                     $answer .= $startitem;*/
         $answer .= "\t{$hiddenfield}\n";
         $answer .= '<div  class="form-group">';
         $answer .= '    <label for="answer' . $ia[1] . $ansrow['code'] . '" class="answertext control-label">' . $ansrow['answer'] . '</label>';
         $answer .= '        <input class="radio" type="radio" value="' . $ansrow['code'] . '" name="' . $ia[1] . '" id="answer' . $ia[1] . $ansrow['code'] . '"' . $check_ans . ' onclick="if (document.getElementById(\'answer' . $ia[1] . 'othertext\') != null) document.getElementById(\'answer' . $ia[1] . 'othertext\').value=\'\';' . $checkconditionFunction . '(this.value, this.name, this.type)" />';
         $answer .= $wrapper['item-end'];
         $answer .= '</div>';
         ++$rowcounter;
         //if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'] || (count($ansresult)-$key)==$wrapper['cols']-$colcounter)
         if ($rowcounter == $ansByCol && $colcounter < $wrapper['cols']) {
             if ($colcounter == $wrapper['cols']) {
                 //$answer .= 'là '.$wrapper['col-devide-last'];
                 $answer .= '    </div><!-- last -->';
             } else {
                 //$answer .= 'et là '.$wrapper['col-devide'];
                 $answer .= '    </div><!-- devide --> ';
                 $answer .= '    <div class="col-xs-' . $iBootCols . '">';
             }
             $rowcounter = 0;
             ++$colcounter;
         }
     }
     if (isset($other) && $other == 'Y') {
         $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
         $sSeparator = $sSeparator['separator'];
         if ($aQuestionAttributes['other_numbers_only'] == 1) {
             $oth_checkconditionFunction = 'fixnum_checkconditions';
         } else {
             $oth_checkconditionFunction = 'checkconditions';
         }
         if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-') {
             $check_ans = CHECKED;
         } else {
             $check_ans = '';
         }
         $thisfieldname = $ia[1] . 'other';
         if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$thisfieldname])) {
             $dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$thisfieldname];
             if ($aQuestionAttributes['other_numbers_only'] == 1) {
                 $dispVal = str_replace('.', $sSeparator, $dispVal);
             }
             $answer_other = ' value="' . htmlspecialchars($dispVal, ENT_QUOTES) . '"';
         } else {
             $answer_other = ' value=""';
         }
         list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, array("code" => "other"), $thisfieldname, $trbc, $myfname, "div", "form-group answer-item radio-item other-item other");
         $answer .= "\t{$hiddenfield}\n";
         $answer .= '<div  class="form-group">';
         $answer .= '    <label for="SOTH' . $ia[1] . '" class="answertext control-label">' . $othertext . '</label>';
         $answer .= '    <input class="radio" type="radio" value="-oth-" name="' . $ia[1] . '" id="SOTH' . $ia[1] . '"' . $check_ans . ' onclick="' . $checkconditionFunction . '(this.value, this.name, this.type)" />';
         $answer .= '    <input type="text" class="text ' . $kpclass . '" id="answer' . $ia[1] . 'othertext" name="' . $ia[1] . 'other" title="' . gT('Other') . '"' . $answer_other . ' onkeyup="if($.trim($(this).val())!=\'\'){ $(\'#SOTH' . $ia[1] . '\').click(); }; ' . $oth_checkconditionFunction . '(this.value, this.name, this.type);" />';
         $answer .= $wrapper['item-end'];
         $answer .= '</div>';
         $inputnames[] = $thisfieldname;
         ++$rowcounter;
         if ($rowcounter == $ansByCol && $colcounter < $wrapper['cols']) {
             if ($colcounter == $wrapper['cols']) {
                 $answer .= '    </div><!-- last -->';
             } else {
                 $answer .= '    </div><!-- devide -->';
                 $answer .= '    <div class="col-xs-' . $iBootCols . '">';
             }
             $rowcounter = 0;
             ++$colcounter;
         }
     }
     if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
         if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == '' || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == ' ') {
             $check_ans = CHECKED;
             //Check the "no answer" radio button if there is no answer in session.
         } else {
             $check_ans = '';
         }
         $answer .= '<div  class="form-group">';
         $answer .= '    <label for="answer' . $ia[1] . 'NANS" class="answertext control-label">' . gT('No answer') . '</label>';
         $answer .= '        <input class="radio" type="radio" name="' . $ia[1] . '" id="answer' . $ia[1] . 'NANS" value=""' . $check_ans . ' onclick="if (document.getElementById(\'answer' . $ia[1] . 'othertext\') != null) document.getElementById(\'answer' . $ia[1] . 'othertext\').value=\'\';' . $checkconditionFunction . '(this.value, this.name, this.type)" />';
         $answer .= $wrapper['item-end'];
         $answer .= '</div>';
         // --> END NEW FEATURE - SAVE
         ++$rowcounter;
         //if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
         if ($rowcounter == $ansByCol && $colcounter < $wrapper['cols']) {
             if ($colcounter == $wrapper['cols']) {
                 //$answer .= $wrapper['col-devide-last'];
                 $answer .= '    </div><!-- last -->';
             } else {
                 //$answer .= $wrapper['col-devide'];
                 $answer .= '    </div><!-- devide -->';
                 $answer .= '    <div class="col-xs-' . $iBootCols . '">';
             }
             $rowcounter = 0;
             ++$colcounter;
         }
     }
     //END OF ITEMS
     //$answer .= $wrapper['whole-end'].'
     $answer .= '    <input type="hidden" name="java' . $ia[1] . '" id="java' . $ia[1] . "\" value=\"" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] . "\" />\n";
     $answer .= '</div> <!-- wrapper row -->';
     $inputnames[] = $ia[1];
     return array($answer, $inputnames);
 }
Beispiel #4
0
 /**
  * get subquestions fort the current question object in the right order
  */
 public function getOrderedSubQuestions($random = 0, $exclude_all_others = '')
 {
     if ($random == 1) {
         // TODO : USE AR PATTERN
         $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid='{$this->qid}' AND scale_id=0 AND language='{$this->language}' ORDER BY " . dbRandom();
     } else {
         // TODO : USE AR PATTERN
         $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid='{$this->qid}' AND scale_id=0 AND language='{$this->language}' ORDER BY question_order";
     }
     $ansresult = dbExecuteAssoc($ansquery)->readAll();
     //Checked
     //if  exclude_all_others is set then the related answer should keep its position at all times
     //thats why we have to re-position it if it has been randomized
     if (trim($exclude_all_others) != '' && $random == 1) {
         $position = 0;
         foreach ($ansresult as $answer) {
             if ($answer['title'] == trim($exclude_all_others)) {
                 if ($position == $answer['question_order'] - 1) {
                     break;
                 }
                 //already in the right position
                 $tmp = array_splice($ansresult, $position, 1);
                 array_splice($ansresult, $answer['question_order'] - 1, 0, $tmp);
                 break;
             }
             $position++;
         }
     }
     return $ansresult;
 }
Beispiel #5
0
function do_array_dual($ia)
{
    global $thissurvey;
    global $notanswered;
    $repeatheadings = Yii::app()->getConfig("repeatheadings");
    $minrepeatheadings = Yii::app()->getConfig("minrepeatheadings");
    $extraclass = "";
    $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
    $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";
    $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]);
    if ($aQuestionAttributes['use_dropdown'] == 1) {
        $useDropdownLayout = true;
        $extraclass .= " dropdown-list";
        $answertypeclass .= " dropdown";
    } else {
        $useDropdownLayout = false;
        $extraclass .= " radio-list";
        $answertypeclass .= " radio";
    }
    if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) {
        $repeatheadings = intval($aQuestionAttributes['repeat_headings']);
        $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']]);
    } else {
        $leftheader = '';
    }
    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']]);
    } else {
        $rightheader = '';
    }
    $lresult = dbExecuteAssoc($lquery);
    //Checked
    $aAnswersScale1 = $lresult->readAll();
    if ($useDropdownLayout === false && count($aAnswersScale1) > 0) {
        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);
        $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 = "<script type='text/javascript'>\n" . "<!--\n" . "function noanswer_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = name.replace(/#.*\$/,\"\");\n" . "\t\$('input[name^=\"' + vname + '\"]').attr('checked',false);\n" . "\t\$('input[id=\"answer' + vname + '#0-\"]').attr('checked',true);\n" . "\t\$('input[name^=\"java' + vname + '\"]').val('');\n" . "\t{$checkconditionFunction}(value, name, type);\n" . "}\n" . "function secondlabel_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = \"answer\"+name.replace(/#1/g,\"#0-\");\n" . "\tif(document.getElementById(vname))\n" . "\t{\n" . "\tdocument.getElementById(vname).checked=false;\n" . "\t}\n" . "\t{$checkconditionFunction}(value, name, type);\n" . "}\n" . " //-->\n" . " </script>\n";
        // Header row and colgroups
        $mycolumns = "\t<colgroup class=\"col-responses group-1\">\n" . "\t<col class=\"col-answers\" width=\"{$answerwidth}%\" />\n";
        $answer_head_line = "\t<th class=\"header_answer_text\">&nbsp;</th>\n\n";
        $odd_even = '';
        foreach ($labelans as $ld) {
            $answer_head_line .= "\t<th>" . $ld . "</th>\n";
            $odd_even = alternation($odd_even);
            $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n";
        }
        $mycolumns .= "\t</colgroup>\n";
        if (count($labelans1) > 0) {
            $mycolumns .= "\t<colgroup class=\"col-responses group-2\">\n" . "\t<col class=\"seperator\" />\n";
            $answer_head_line .= "\n\t<td class=\"header_separator\">&nbsp;</td>\n\n";
            // Separator
            foreach ($labelans1 as $ld) {
                $answer_head_line .= "\t<th>" . $ld . "</th>\n";
                $odd_even = alternation($odd_even);
                $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n";
            }
        }
        if ($right_exists) {
            $answer_head_line .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
            $mycolumns .= "\n\t<col class=\"answertextright\" />\n\n";
        }
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
            $answer_head_line .= "\t<td class=\"header_separator\">&nbsp;</td>\n";
            // Separator
            $answer_head_line .= "\t<th class=\"header_no_answer\">" . $clang->gT('No answer') . "</th>\n";
            $odd_even = alternation($odd_even);
            $mycolumns .= "\n\t<col class=\"seperator\" />\n\n";
            $mycolumns .= "\t<col class=\"col-no-answer {$odd_even}\" width=\"{$cellwidth}%\" />\n";
        }
        $mycolumns .= "\t</colgroup>\n";
        $answer_head2 = "\n<tr class=\"array1 header_row\">\n" . $answer_head_line . "</tr>\n";
        // build first row of header if needed
        if ($leftheader != '' || $rightheader != '') {
            $answer_head1 = "<tr class=\"array1 groups header_row\">\n" . "\t<th class=\"header_answer_text\">&nbsp;</th>\n" . "\t<th colspan=\"" . count($labelans) . "\" class=\"dsheader\">{$leftheader}</th>\n";
            if (count($labelans1) > 0) {
                $answer_head1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n" . "\t<th colspan=\"" . count($labelans1) . "\" class=\"dsheader\">{$rightheader}</th>\n";
            }
            if ($right_exists) {
                $answer_head1 .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
            }
            if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
                $answer_head1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n";
                // Separator
                $answer_head1 .= "\t<th class=\"header_no_answer\">&nbsp;</th>\n";
            }
            $answer_head1 .= "</tr>\n";
        } else {
            $answer_head1 = '';
        }
        $answer .= "\n<table class=\"question subquestions-list questions-list\" summary=\"" . str_replace('"', '', strip_tags($ia[3])) . " - a dual array type question\">\n" . $mycolumns . "\n\t<thead>\n" . $answer_head1 . $answer_head2 . "\n\t</thead>\n" . "<tbody>\n";
        $trbc = '';
        foreach ($aQuestionsRight 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 .= "</tbody>\n<tbody>";
                    // Close actual body and open another one
                    //$answer .= $answer_head1;
                    $answer .= "\n<tr class=\"repeat headings\">\n" . $answer_head_line . "</tr>\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] == '')) {
                $answertext = "<span class='errormandatory'>{$answertext}</span>";
            }
            // Get array_filter stuff
            list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname0, $trbc, $myfname, "tr", "{$trbc} answers-list radio-list");
            $answer .= $htmltbody2;
            if (strpos($answertext, '|')) {
                $answertext = substr($answertext, 0, strpos($answertext, '|'));
            }
            array_push($inputnames, $myfname);
            $answer .= "\t<th class=\"answertext\">\n" . $hiddenfield . "{$answertext}\n" . "<input type=\"hidden\" name=\"java{$myfname}\" id=\"java{$myfname}\" value=\"";
            if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
                $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
            }
            $answer .= "\" />\n\t</th>\n";
            $hiddenanswers = '';
            $thiskey = 0;
            foreach ($labelcode as $ld) {
                $answer .= "\t<td class=\"answer_cell_1_00{$ld} answer-item {$answertypeclass}-item\">\n" . "<label for=\"answer{$myfname}-{$ld}\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname}\" value=\"{$ld}\" id=\"answer{$myfname}-{$ld}\" title=\"" . HTMLEscape(strip_tags($labelans[$thiskey])) . '"';
                if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == $ld) {
                    $answer .= CHECKED;
                }
                // --> START NEW FEATURE - SAVE
                $answer .= " onclick=\"{$checkconditionFunction}(this.value, this.name, this.type)\" />\n</label>\n";
                // --> END NEW FEATURE - SAVE
                $answer .= "\n\t</td>\n";
                $thiskey++;
            }
            if (count($labelans1) > 0) {
                $dualgroup++;
                $hiddenanswers = '';
                $answer .= "\t<td class=\"dual_scale_separator information-item\">&nbsp;</td>\n";
                // separator
                array_push($inputnames, $myfname1);
                $hiddenanswers .= "<input type=\"hidden\" name=\"java{$myfname1}\" id=\"java{$myfname1}\" value=\"";
                if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) {
                    $hiddenanswers .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1];
                }
                $hiddenanswers .= "\" />\n";
                $thiskey = 0;
                foreach ($labelcode1 as $ld) {
                    $answer .= "\t<td class=\"answer_cell_2_00{$ld}  answer-item radio-item\">\n";
                    if ($hiddenanswers != '') {
                        $answer .= $hiddenanswers;
                        $hiddenanswers = '';
                    }
                    $answer .= "<label for=\"answer{$myfname1}-{$ld}\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname1}\" value=\"{$ld}\" id=\"answer{$myfname1}-{$ld}\" title=\"" . HTMLEscape(strip_tags($labelans1[$thiskey])) . '"';
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $ld) {
                        $answer .= CHECKED;
                    }
                    // --> START NEW FEATURE - SAVE
                    $answer .= " onclick=\"secondlabel_checkconditions(this.value, this.name, this.type)\" />\n</label>\n";
                    // --> END NEW FEATURE - SAVE
                    $answer .= "\t</td>\n";
                    $thiskey++;
                }
            }
            if (strpos($answertextsave, '|')) {
                $answertext = substr($answertextsave, strpos($answertextsave, '|') + 1);
                $answer .= "\t<td class=\"answertextright\">{$answertext}</td>\n";
                $hiddenanswers = '';
            } elseif ($right_exists) {
                $answer .= "\t<td class=\"answertextright\">&nbsp;</td>\n";
            }
            if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) {
                $answer .= "\t<td class=\"dual_scale_separator information-item\">&nbsp;</td>\n";
                // separator
                $answer .= "\t<td class=\"dual_scale_no_answer answer-item radio-item noanswer-item\">\n" . "<label for='answer{$myfname}-'>\n" . "\t<input class='radio' type='radio' name='{$myfname}' value='' id='answer{$myfname}-' title='" . $clang->gT("No answer") . "'";
                if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == "") {
                    $answer .= CHECKED;
                }
                // --> START NEW FEATURE - SAVE
                $answer .= " onclick=\"noanswer_checkconditions(this.value, this.name, this.type)\" />\n" . "</label>\n" . "\t</td>\n";
                // --> END NEW FEATURE - SAVE
            }
            $answer .= "</tr>\n";
            // $inputnames[]=$myfname;
            //IF a MULTIPLE of flexi-redisplay figure, repeat the headings
            $fn++;
        }
        $answer .= "\t</tbody>\n";
        $answer .= "</table>\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();
        } 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";
        }
        $ansresult = dbExecuteAssoc($ansquery);
        $aSubquestions = $ansresult->readAll();
        //Checked
        $anscount = count($aSubquestions);
        if ($anscount == 0) {
            $inputnames = array();
            $answer .= "\n<p class=\"error\">" . $clang->gT('Error: This question has no answers.') . "</p>\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']);
            }
            // 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;
                $ddsuffix = $ddsuffix;
            } else {
                $ddprefix = '';
                $ddsuffix = '';
            }
            if (trim($aQuestionAttributes['dropdown_separators']) != '') {
                list($postanswSep, $interddSep) = explode('|', $aQuestionAttributes['dropdown_separators']);
                $postanswSep = $postanswSep;
                $interddSep = $interddSep;
            } else {
                $postanswSep = '';
                $interddSep = '';
            }
            $colspan_1 = '';
            $colspan_2 = '';
            $suffix_cell = '';
            $answer .= "\n<table class=\"question subquestion-list questions-list dropdown-list\" summary=\"" . str_replace('"', '', strip_tags($ia[3])) . " - an dual array type question\">\n\n" . "\t<col class=\"answertext\" width=\"{$answerwidth}%\" />\n";
            if ($ddprefix != '') {
                $answer .= "\t<col class=\"ddprefix\" />\n";
                $colspan_1 = ' colspan="2"';
            }
            $answer .= "\t<col class=\"dsheader\" />\n";
            if ($ddsuffix != '') {
                $answer .= "\t<col class=\"ddsuffix\" />\n";
                if (!empty($colspan_1)) {
                    $colspan_2 = ' colspan="3"';
                }
                $suffix_cell = "\t<td>&nbsp;</td>\n";
                // suffix
            }
            $answer .= "\t<col class=\"ddarrayseparator\" width=\"{$separatorwidth}%\" />\n";
            if ($ddprefix != '') {
                $answer .= "\t<col class=\"ddprefix\" />\n";
            }
            $answer .= "\t<col class=\"dsheader\" />\n";
            if ($ddsuffix != '') {
                $answer .= "\t<col class=\"ddsuffix\" />\n";
            }
            // headers
            $answer .= "\n\t<thead>\n" . "<tr>\n" . "\t<td{$colspan_1}>&nbsp;</td>\n" . "\n" . "\t<th>{$leftheader}</th>\n" . "\n" . "\t<td{$colspan_2}>&nbsp;</td>\n" . "\t<th>{$rightheader}</th>\n" . $suffix_cell . "</tr>\n" . "\t</thead>\n\n";
            $answer .= "\n<tbody>\n";
            $trbc = '';
            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;
                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] == '')) {
                    $answertext = "<span class='errormandatory'>" . dTexts__run($ansrow['question']) . "</span>";
                } else {
                    $answertext = dTexts__run($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");
                $answer .= $htmltbody2;
                $answer .= "\t<th class=\"answertext\">\n" . "<label for=\"answer{$rowname}\">\n" . $hiddenfield . "{$answertext}\n" . "</label>\n" . "\t</th>\n";
                // Label0
                // prefix
                if ($ddprefix != '') {
                    $answer .= "\t<td class=\"ddprefix information-item\">{$ddprefix}</td>\n";
                }
                $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<select name=\"{$myfname}\" id=\"answer{$myfname}\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,{$dualgroup},{$checkconditionFunction});\">\n";
                if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == '') {
                    $answer .= "\t<option value=\"\" " . SELECTED . '>' . $clang->gT('Please choose...') . "</option>\n";
                }
                foreach ($labels0 as $lrow) {
                    $answer .= "\t<option value=\"" . $lrow['code'] . '" ';
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == $lrow['code']) {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . flattenText($lrow['title']) . "</option>\n";
                }
                // If not mandatory and showanswer, show no ans
                if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
                    $answer .= "\t<option class=\"noanswer-item\" value=\"\" ";
                    if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == '') {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . $clang->gT('No answer') . "</option>\n";
                }
                $answer .= "</select>\n";
                // suffix
                if ($ddsuffix != '') {
                    $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n";
                }
                $answer .= "<input type=\"hidden\" name=\"java{$myfname}\" id=\"java{$myfname}\" value=\"";
                if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
                    $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
                }
                $answer .= "\" />\n" . "\t</td>\n";
                $inputnames[] = $myfname;
                $answer .= "\t<td class=\"ddarrayseparator information-item\">{$interddSep}</td>\n";
                //Separator
                // Label1
                // prefix
                if ($ddprefix != '') {
                    $answer .= "\t<td class='ddprefix information-item'>{$ddprefix}</td>\n";
                }
                //				$answer .= "\t<td align='left' width='$columnswidth%'>\n"
                $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<select name=\"{$myfname1}\" id=\"answer{$myfname1}\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,{$dualgroup1},{$checkconditionFunction});\">\n";
                if (empty($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
                    $answer .= "\t<option value=\"\"" . SELECTED . '>' . $clang->gT('Please choose...') . "</option>\n";
                }
                foreach ($labels1 as $lrow1) {
                    $answer .= "\t<option value=\"" . $lrow1['code'] . '" ';
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $lrow1['code']) {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . flattenText($lrow1['title']) . "</option>\n";
                }
                // If not mandatory and showanswer, show no ans
                if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
                    $answer .= "\t<option class=\"noanswer-item\" value='' ";
                    if (empty($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
                        $answer .= SELECTED;
                    }
                    $answer .= ">" . $clang->gT('No answer') . "</option>\n";
                }
                $answer .= "</select>\n";
                // suffix
                if ($ddsuffix != '') {
                    $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n";
                }
                $answer .= "<input type=\"hidden\" name=\"java{$myfname1}\" id=\"java{$myfname1}\" value=\"";
                if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) {
                    $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1];
                }
                $answer .= "\" />\n" . "\t</td>\n";
                $inputnames[] = $myfname1;
                $answer .= "</tr>\n";
            }
        }
        // End there are answers
        $answer .= "\t</tbody>\n";
        $answer .= "</table>\n";
    } else {
        $answer = "<p class='error'>" . $clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.") . "</p>\n";
        $inputnames = "";
    }
    return array($answer, $inputnames);
}