Пример #1
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);
}
function do_arraycolumns($ia)
{
    global $notanswered;
    $clang = Yii::app()->lang;
    $extraclass = "";
    $checkconditionFunction = "checkconditions";
    $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);
    $qquery = "SELECT other FROM {{questions}} WHERE qid=" . $ia[0] . " AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "'";
    $other = Yii::app()->db->createCommand($qquery)->queryScalar();
    //Checked
    $lquery = "SELECT * FROM {{answers}} WHERE qid=" . $ia[0] . "  AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY sortorder, code";
    $oAnswers = dbExecuteAssoc($lquery);
    $aAnswers = $oAnswers->readAll();
    if (count($aAnswers) > 0) {
        foreach ($aAnswers as $lrow) {
            $labelans[] = $lrow['answer'];
            $labelcode[] = $lrow['code'];
            $labels[] = array("answer" => $lrow['answer'], "code" => $lrow['code']);
        }
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
            $labelcode[] = '';
            $labelans[] = $clang->gT('No answer');
            $labels[] = array('answer' => $clang->gT('No answer'), 'code' => '');
        }
        if ($aQuestionAttributes['random_order'] == 1) {
            $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['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 language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY question_order";
        }
        $ansresult = dbExecuteAssoc($ansquery);
        //Checked
        $aQuestions = $ansresult->readAll();
        $anscount = count($aQuestions);
        if ($anscount > 0) {
            $fn = 1;
            $cellwidth = $anscount;
            $cellwidth = round(50 / $cellwidth, 1);
            $answer = "\n<table class=\"question subquestions-list questions-list\" summary=\"" . str_replace('"', '', strip_tags($ia[3])) . " - an array type question with a single response per column\">\n\n" . "\t<colgroup class=\"col-responses\">\n" . "\t<col class=\"col-answers\" width=\"50%\" />\n";
            $odd_even = '';
            for ($c = 0; $c < $anscount; ++$c) {
                $odd_even = alternation($odd_even);
                $answer .= "<col class=\"{$odd_even} question-item answers-list radio-list\" width=\"{$cellwidth}%\" />\n";
            }
            $answer .= "\t</colgroup>\n\n" . "\t<thead>\n" . "<tr>\n" . "\t<td>&nbsp;</td>\n";
            foreach ($aQuestions as $ansrow) {
                $anscode[] = $ansrow['title'];
                $answers[] = dTexts__run($ansrow['question']);
            }
            $trbc = '';
            $odd_even = '';
            for ($_i = 0; $_i < count($answers); ++$_i) {
                $ld = $answers[$_i];
                $myfname = $ia[1] . $anscode[$_i];
                $trbc = alternation($trbc, 'row');
                /* 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 && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == "") {
                    $ld = "<span class=\"errormandatory\">{$ld}</span>";
                }
                $odd_even = alternation($odd_even);
                $answer .= "\t<th class=\"{$odd_even}\">{$ld}</th>\n";
            }
            unset($trbc);
            $answer .= "</tr>\n\t</thead>\n\n\t<tbody>\n";
            $ansrowcount = 0;
            $ansrowtotallength = 0;
            foreach ($aQuestions as $ansrow) {
                $ansrowcount++;
                $ansrowtotallength = $ansrowtotallength + strlen($ansrow['question']);
            }
            $percwidth = 100 - $cellwidth * $anscount;
            foreach ($labels as $ansrow) {
                $answer .= "<tr>\n" . "\t<th class=\"arraycaptionleft\">{$ansrow['answer']}</th>\n";
                foreach ($anscode as $ld) {
                    //if (!isset($trbc) || $trbc == 'array1') {$trbc = 'array2';} else {$trbc = 'array1';}
                    $myfname = $ia[1] . $ld;
                    $answer .= "\t<td class=\"answer_cell_00{$ld} answer-item radio-item\">\n" . "<label for=\"answer" . $myfname . '-' . $ansrow['code'] . "\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"" . $myfname . '" value="' . $ansrow['code'] . '" ' . 'id="answer' . $myfname . '-' . $ansrow['code'] . '" ' . 'title="' . HTMLEscape(strip_tags($ansrow['answer'])) . '"';
                    if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == $ansrow['code']) {
                        $answer .= CHECKED;
                    } elseif (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $ansrow['code'] == '') {
                        $answer .= CHECKED;
                        // Humm.. (by lemeur), not sure this section can be reached
                        // because I think $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] is always set (by save.php ??) !
                        // should remove the !isset part I think !!
                    }
                    $answer .= " onclick=\"{$checkconditionFunction}(this.value, this.name, this.type)\" />\n</label>\n\t</td>\n";
                }
                unset($trbc);
                $answer .= "</tr>\n";
                $fn++;
            }
            $answer .= "\t</tbody>\n</table>\n";
            foreach ($anscode as $ld) {
                $myfname = $ia[1] . $ld;
                $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";
                $inputnames[] = $myfname;
            }
        } else {
            $answer = '<p class="error">' . $clang->gT('Error: There are no answers defined for this question.') . "</p>";
            $inputnames = "";
        }
    } 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);
}