Esempio n. 1
0
function do_array($ia)
{
    global $dbprefix, $connect, $thissurvey, $clang;
    global $repeatheadings;
    global $notanswered;
    global $minrepeatheadings;

    if (isset($ia[8]) && $ia[8] == 'Y')
    {
        $checkconditionFunction = "checkconditions";
    }
    else
    {
        $checkconditionFunction = "noop_checkconditions";
    }

    $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."'";
    $qresult = db_execute_assoc($qquery);     //Checked
    while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];}
    $lquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY sortorder, code";

    $qidattributes=getQuestionAttributes($ia[0],$ia[4]);
    if (trim($qidattributes['answer_width'])!='')
    {
        $answerwidth=$qidattributes['answer_width'];
    }
    else
    {
        $answerwidth=20;
    }
    $columnswidth=100-$answerwidth;

   if ($qidattributes['use_dropdown'] == 1)
   {
       $useDropdownLayout = true;
   }
   else
   {
       $useDropdownLayout = false;
   }

    $lresult = db_execute_assoc($lquery);   //Checked
    if ($useDropdownLayout === false && $lresult->RecordCount() > 0)
    {
        while ($lrow=$lresult->FetchRow())
        {
            $labelans[]=$lrow['answer'];
            $labelcode[]=$lrow['code'];
        }

        //		$cellwidth=sprintf('%02d', $cellwidth);

        $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND question like '%|%' ";
        $ansresult = db_execute_assoc($ansquery);  //Checked
        if ($ansresult->RecordCount()>0) {$right_exists=true;$answerwidth=$answerwidth/2;} else {$right_exists=false;}
        // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column
        if ($qidattributes['random_order']==1) {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
        }
        else
        {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
        }
        $ansresult = db_execute_assoc($ansquery); //Checked
        $anscount = $ansresult->RecordCount();
        $fn=1;

        $numrows = count($labelans);
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
        {
            ++$numrows;
        }
        if ($right_exists)
        {
            ++$numrows;
        }
        $cellwidth = round( ($columnswidth / $numrows ) , 1 );

        $answer_start = "\n<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - an array type question\" >\n";
        $answer_head = "\t<thead>\n"
        . "<tr>\n"
        . "\t<td>&nbsp;</td>\n";
        foreach ($labelans as $ld)
        {
            $answer_head .= "\t<th>".$ld."</th>\n";
        }
        if ($right_exists) {$answer_head .= "\t<td>&nbsp;</td>\n";}
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer"
        {
            $answer_head .= "\t<th>".$clang->gT('No answer')."</th>\n";
        }
        $answer_head .= "</tr>\n\t</thead>\n\n\t\n";

        $answer = '';
        $trbc = '';
        $inputnames=array();

        while ($ansrow = $ansresult->FetchRow())
        {
            if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0)
            {
                if ( ($anscount - $fn + 1) >= $minrepeatheadings )
                {
                    $answer .= "<tr class=\"repeat headings\">\n"
                    . "\t<td>&nbsp;</td>\n";
                    foreach ($labelans as $ld)
                    {
                        $answer .= "\t<th>".$ld."</th>\n";
                    }
                    if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer"
                    {
                        $answer .= "\t<th>".$clang->gT('No answer')."</th>\n";
                    }
                    $answer .= "</tr>\n";
                }
            }
            $myfname = $ia[1].$ansrow['title'];
            $answertext=dTexts::run($ansrow['question']);
            $answertextsave=$answertext;
            if (strpos($answertext,'|'))
            {
                $answertext=substr($answertext,0, strpos($answertext,'|'));
            }
            /* 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 (strpos($answertext,'|')) {$answerwidth=$answerwidth/2;}

            if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) {
                $answertext = '<span class="errormandatory">'.$answertext.'</span>';
            }
            // Get array_filter stuff
            list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname);
            $row_selected = return_array_filter_selected($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname);
			if($row_selected)
			{
				$trbc = alternation($trbc , 'row');
				$fn++;
			}
			$answer .= $htmltbody2;

            $answer .= "<tr class=\"$trbc\">\n"
            . "\t<th class=\"answertext\">\n$answertext"
            . $hiddenfield
            . "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\"";
            if (isset($_SESSION[$myfname]))
            {
                $answer .= $_SESSION[$myfname];
            }
            $answer .= "\" />\n\t</th>\n";

            $thiskey=0;
            foreach ($labelcode as $ld)
            {
                $answer .= "\t\t\t<td class=\"answer_cell_00$ld\">\n"
                . "<label for=\"answer$myfname-$ld\">\n"
                . "\t<input class=\"radio\" type=\"radio\" name=\"$myfname\" value=\"$ld\" id=\"answer$myfname-$ld\" title=\""
                . html_escape(strip_tags($labelans[$thiskey])).'"';
                if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $ld)
                {
                    $answer .= CHECKED;
                }
                // --> START NEW FEATURE - SAVE
                $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n"
                . "</label>\n"
                . "\t</td>\n";
                // --> END NEW FEATURE - SAVE

                $thiskey++;
            }
            if (strpos($answertextsave,'|'))
            {
                $answertext=substr($answertextsave,strpos($answertextsave,'|')+1);
                $answer .= "\t<th class=\"answertextright\">$answertext</th>\n";
            }
            elseif ($right_exists)
            {
                $answer .= "\t<td class=\"answertextright\">&nbsp;</td>\n";
            }

            if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
            {
                $answer .= "\t<td>\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[$myfname]) || $_SESSION[$myfname] == '')
                {
                    $answer .= CHECKED;
                }
                // --> START NEW FEATURE - SAVE
                $answer .= " onclick=\"$checkconditionFunction(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
        }

        $answer_cols = "\t<colgroup class=\"col-responses\">\n"
        ."\t<col class=\"col-answers\" width=\"$answerwidth%\" />\n" ;

        $odd_even = '';
        foreach ($labelans as $c)
        {
            $odd_even = alternation($odd_even);
            $answer_cols .= "<col class=\"$odd_even\" width=\"$cellwidth%\" />\n";
        }
        if ($right_exists)
        {
            $odd_even = alternation($odd_even);
            $answer_cols .= "<col class=\"answertextright $odd_even\" width=\"$answerwidth%\" />\n";
        }
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory
        {
            $odd_even = alternation($odd_even);
            $answer_cols .= "<col class=\"col-no-answer $odd_even\" width=\"$cellwidth%\" />\n";
        }
        $answer_cols .= "\t</colgroup>\n";

        $answer = $answer_start . $answer_cols . $answer_head .$answer . "\t</tbody>\n</table>\n";
    }
   elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0)
   {
       while ($lrow=$lresult->FetchRow())
           $labels[]=Array('code' => $lrow['code'],
                           'answer' => $lrow['answer']);
        $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND question like '%|%' ";
       $ansresult = db_execute_assoc($ansquery);  //Checked
       if ($ansresult->RecordCount()>0) {$right_exists=true;$answerwidth=$answerwidth/2;} else {$right_exists=false;}
       // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column
        if ($qidattributes['random_order']==1) {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
        }
        else
        {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
        }
       $ansresult = db_execute_assoc($ansquery); //Checked
       $anscount = $ansresult->RecordCount();
       $fn=1;

       $numrows = count($labels);
       if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
       {
           ++$numrows;
       }
       if ($right_exists)
       {
           ++$numrows;
       }
       $cellwidth = round( ($columnswidth / $numrows ) , 1 );

       $answer_start = "\n<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - an array type question\" >\n";

       $answer = "\t<tbody>\n";
       $trbc = '';
        $inputnames=array();

       while ($ansrow = $ansresult->FetchRow())
       {
           $myfname = $ia[1].$ansrow['title'];
           $trbc = alternation($trbc , 'row');
           $answertext=answer_replace($ansrow['question']);
            $answertextsave=$answertext;
           if (strpos($answertext,'|'))
           {
               $answertext=substr($answertext,0, strpos($answertext,'|'));
           }
           /* 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 (strpos($answertext,'|')) {$answerwidth=$answerwidth/2;}

           if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) {
               $answertext = '<span class="errormandatory">'.$answertext.'</span>';
           }
           // Get array_filter stuff
           list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname);
           $answer .= $htmltbody2;

           $answer .= "<tr class=\"$trbc\">\n"
           . "\t<th class=\"answertext\">\n$answertext"
           . $hiddenfield
           . "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\"";
           if (isset($_SESSION[$myfname]))
           {
               $answer .= $_SESSION[$myfname];
           }
           $answer .= "\" />\n\t</th>\n";

           $answer .= "\t<td >\n"
           . "<select name=\"$myfname\" id=\"answer$myfname\" onchange=\"$checkconditionFunction(this.value, this.name, this.type);\">\n";

           if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] =='')
           {
               $answer .= "\t<option value=\"\" ".SELECTED.'>'.$clang->gT('Please choose')."...</option>\n";
           }

           foreach ($labels as $lrow)
           {
               $answer .= "\t<option value=\"".$lrow['code'].'" ';
               if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $lrow['code'])
               {
                   $answer .= SELECTED;
               }
               $answer .= '>'.$lrow['answer']."</option>\n";
           }
           // If not mandatory and showanswer, show no ans
           if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
           {
               $answer .= "\t<option value=\"\" ";
               if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == '')
               {
                   $answer .= SELECTED;
               }
               $answer .= '>'.$clang->gT('No answer')."</option>\n";
           }
           $answer .= "</select>\n";

           if (strpos($answertextsave,'|'))
           {
               $answertext=substr($answertextsave,strpos($answertextsave,'|')+1);
               $answer .= "\t<th class=\"answertextright\">$answertext</th>\n";
           }
           elseif ($right_exists)
           {
               $answer .= "\t<td class=\"answertextright\">&nbsp;</td>\n";
           }

           $answer .= "</tr>\n</tbody>";
           $inputnames[]=$myfname;
           //IF a MULTIPLE of flexi-redisplay figure, repeat the headings
           $fn++;
       }

       $answer = $answer_start . $answer . "\t</tbody>\n</table>\n";
   }
   else
    {
        $answer = "\n<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);
}
Esempio n. 2
0
function do_array_dual($ia)
{
    global $dbprefix, $connect, $thissurvey, $clang;
    global $shownoanswer;
    global $repeatheadings;
    global $notanswered;
    global $minrepeatheadings;
    if ($ia[8] == 'Y') {
        $checkconditionFunction = "checkconditions";
    } else {
        $checkconditionFunction = "noop_checkconditions";
    }
    $inputnames = array();
    $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=" . $ia[0] . " AND language='" . $_SESSION['s_lang'] . "'";
    $other = $connect->GetOne($qquery);
    //Checked
    $lquery = "SELECT * FROM {$dbprefix}answers WHERE scale_id=0 AND qid={$ia[0]} AND language='" . $_SESSION['s_lang'] . "' ORDER BY sortorder, code";
    $lquery1 = "SELECT * FROM {$dbprefix}answers WHERE scale_id=1 AND qid={$ia[0]} AND language='" . $_SESSION['s_lang'] . "' ORDER BY sortorder, code";
    $qidattributes = getQuestionAttributes($ia[0], $ia[4]);
    if ($qidattributes['use_dropdown'] == 1) {
        $useDropdownLayout = true;
    } else {
        $useDropdownLayout = false;
    }
    if (trim($qidattributes['dualscale_headerA']) != '') {
        $leftheader = $clang->gT($qidattributes['dualscale_headerA']);
    } else {
        $leftheader = '';
    }
    if (trim($qidattributes['dualscale_headerB']) != '') {
        $rightheader = $clang->gT($qidattributes['dualscale_headerB']);
    } else {
        $rightheader = '';
    }
    $lresult = db_execute_assoc($lquery);
    //Checked
    if ($useDropdownLayout === false && $lresult->RecordCount() > 0) {
        if (trim($qidattributes['answer_width']) != '') {
            $answerwidth = $qidattributes['answer_width'];
        } else {
            $answerwidth = 20;
        }
        $columnswidth = 100 - $answerwidth;
        while ($lrow = $lresult->FetchRow()) {
            $labelans[] = $lrow['answer'];
            $labelcode[] = $lrow['code'];
        }
        $lresult1 = db_execute_assoc($lquery1);
        //Checked
        if ($lresult1->RecordCount() > 0) {
            while ($lrow1 = $lresult1->FetchRow()) {
                $labelans1[] = $lrow1['answer'];
                $labelcode1[] = $lrow1['code'];
            }
        }
        $numrows = count($labelans) + count($labelans1);
        if ($ia[6] != "Y" && $shownoanswer == 1) {
            $numrows++;
        }
        $cellwidth = $columnswidth / $numrows;
        $cellwidth = sprintf("%02d", $cellwidth);
        $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%'";
        $ansresult = db_execute_assoc($ansquery);
        //Checked
        if ($ansresult->RecordCount() > 0) {
            $right_exists = true;
        } else {
            $right_exists = false;
        }
        // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column
        if ($qidattributes['random_order'] == 1) {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['s_lang'] . "' and scale_id=0 ORDER BY " . db_random();
        } else {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['s_lang'] . "' and scale_id=0 ORDER BY question_order";
        }
        $ansresult = db_execute_assoc($ansquery);
        //Checked
        $anscount = $ansresult->RecordCount();
        $fn = 1;
        // unselect second scale when using "no answer"
        $answer = "<script type='text/javascript'>\n" . "<!--\n" . "\tfunction noanswer_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = name.replace(/#0/g,\"#1\");\n" . "\tfor(var i=0, n=document.getElementsByName(vname).length; i<n; ++i)\n" . "\t{\n" . "document.getElementsByName(vname)[i].checked=false;\n" . "\t}\n" . "\t{$checkconditionFunction}(value, name, type);\n" . "}\n" . "\tfunction 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" . "document.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";
        $myheader2 = "\n<tr class=\"array1 header_row\">\n" . "\t<th class=\"header_answer_text\">&nbsp;</th>\n\n";
        $odd_even = '';
        foreach ($labelans as $ld) {
            $myheader2 .= "\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";
            $myheader2 .= "\n\t<td class=\"header_separator\">&nbsp;</td>\n\n";
            // Separator
            foreach ($labelans1 as $ld) {
                $myheader2 .= "\t<th>" . $ld . "</th>\n";
                $odd_even = alternation($odd_even);
                $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n";
            }
        }
        if ($right_exists) {
            $myheader2 .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
            $mycolumns .= "\n\t<col class=\"answertextright\" />\n\n";
        }
        if ($ia[6] != 'Y' && $shownoanswer == 1) {
            $myheader2 .= "\t<td class=\"header_separator\">&nbsp;</td>\n";
            // Separator
            $myheader2 .= "\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";
        $myheader2 .= "</tr>\n";
        // build first row of header if needed
        if ($leftheader != '' || $rightheader != '') {
            $myheader1 = "<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) {
                $myheader1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n" . "\t<th colspan=\"" . count($labelans1) . "\" class=\"dsheader\">{$rightheader}</th>\n";
            }
            if ($right_exists) {
                $myheader1 .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
            }
            if ($ia[6] != 'Y' && $shownoanswer == 1) {
                $myheader1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n";
                // Separator
                $myheader1 .= "\t<th class=\"header_no_answer\">&nbsp;</th>\n";
            }
            $myheader1 .= "</tr>\n";
        } else {
            $myheader1 = '';
        }
        $answer .= "\n<table class=\"question\" summary=\"" . str_replace('"', '', strip_tags($ia[3])) . " - a dual array type question\">\n" . $mycolumns . "\n\t<thead>\n" . $myheader1 . $myheader2 . "\n\t</thead>\n";
        $trbc = '';
        while ($ansrow = $ansresult->FetchRow()) {
            // 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<tr  class=\"repeat\">\n" . "\t<th class=\"header_answer_text\">&nbsp;</th>\n";
                    foreach ($labelans as $ld) {
                        $answer .= "\t<th>" . $ld . "</th>\n";
                    }
                    if (count($labelans1) > 0) {
                        $answer .= "<th class=\"header_separator\">&nbsp;</th>\n";
                        // Separator
                        foreach ($labelans1 as $ld) {
                            $answer .= "\t<th>" . $ld . "</th>\n";
                        }
                    }
                    if ($right_exists) {
                        $answer .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
                    }
                    if ($ia[6] != 'Y' && $shownoanswer == 1) {
                        $answer .= "\t<td class=\"header_separator\">&nbsp;</td>\n";
                        // Separator
                        $answer .= "\t<th class=\"header_no_answer\">" . $clang->gT('No answer') . "</th>\n";
                    }
                    $answer .= "</tr>\n</tbody>\n";
                }
            }
            $trbc = alternation($trbc, 'row');
            $answertext = answer_replace($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 (is_array($notanswered) && array_search($ia[1], $notanswered) !== FALSE && ($_SESSION[$myfname] == '' || $_SESSION[$myfname1] == '')) {
                $answertext = "<span class='errormandatory'>{$answertext}</span>";
            }
            // Get array_filter stuff
            list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname0, $trbc, $myfname);
            $answer .= $htmltbody2;
            if (strpos($answertext, '|')) {
                $answertext = substr($answertext, 0, strpos($answertext, '|'));
            }
            array_push($inputnames, $myfname);
            $answer .= "<tr class=\"{$trbc}\">\n" . "\t<th class=\"answertext\">\n" . $hiddenfield . "{$answertext}\n" . "<input type=\"hidden\" name=\"java{$myfname}\" id=\"java{$myfname}\" value=\"";
            if (isset($_SESSION[$myfname])) {
                $answer .= $_SESSION[$myfname];
            }
            $answer .= "\" />\n\t</th>\n";
            $hiddenanswers = '';
            $thiskey = 0;
            foreach ($labelcode as $ld) {
                $answer .= "\t<td class=\"answer_cell_1_00{$ld}\">\n" . "<label for=\"answer{$myfname}-{$ld}\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname}\" value=\"{$ld}\" id=\"answer{$myfname}-{$ld}\" title=\"" . html_escape(strip_tags($labelans[$thiskey])) . '"';
                if (isset($_SESSION[$myfname]) && $_SESSION[$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\">&nbsp;</td>\n";
                // separator
                array_push($inputnames, $myfname1);
                $hiddenanswers .= "<input type=\"hidden\" name=\"java{$myfname1}\" id=\"java{$myfname1}\" value=\"";
                if (isset($_SESSION[$myfname1])) {
                    $hiddenanswers .= $_SESSION[$myfname1];
                }
                $hiddenanswers .= "\" />\n";
                $thiskey = 0;
                foreach ($labelcode1 as $ld) {
                    $answer .= "\t<td class=\"answer_cell_2_00{$ld}\">\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=\"" . html_escape(strip_tags($labelans1[$thiskey])) . '"';
                    if (isset($_SESSION[$myfname1]) && $_SESSION[$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" && $shownoanswer == 1) {
                $answer .= "\t<td class=\"dual_scale_separator\">&nbsp;</td>\n";
                // separator
                $answer .= "\t<td class=\"dual_scale_no_answer\">\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[$myfname]) || $_SESSION[$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";
            $answer .= "\t</tbody>\n";
            // $inputnames[]=$myfname;
            //IF a MULTIPLE of flexi-redisplay figure, repeat the headings
            $fn++;
        }
        $answer .= "</table>\n";
    } elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0) {
        if (trim($qidattributes['answer_width']) != '') {
            $answerwidth = $qidattributes['answer_width'];
        } else {
            $answerwidth = 20;
        }
        $separatorwidth = (100 - $answerwidth) / 10;
        $columnswidth = 100 - $answerwidth - $separatorwidth * 2;
        $answer = "<script type='text/javascript'>\n" . "<!--\n" . "\tfunction special_checkconditions(value, name, type, rank)\n" . "{\n" . "\tif (value == '') {\n" . "if (rank == 0) { dualname = name.replace(/#0/g,\"#1\"); }\n" . "else if (rank == 1) { dualname = name.replace(/#1/g,\"#0\"); }\n" . "document.getElementsByName(dualname)[0].value=value;\n" . "\t}\n" . "{$checkconditionFunction}(value, name, type);\n" . "}\n" . " //-->\n" . " </script>\n";
        // Get Answers
        //question atribute random_order set?
        if ($qidattributes['random_order'] == 1) {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia['0']} and scale_id=0 AND language='" . $_SESSION['s_lang'] . "' ORDER BY " . db_random();
        } else {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia['0']} and scale_id=0 AND language='" . $_SESSION['s_lang'] . "' ORDER BY question_order";
        }
        $ansresult = db_execute_assoc($ansquery);
        //Checked
        $anscount = $ansresult->RecordCount();
        if ($anscount == 0) {
            $inputnames = array();
            $answer .= "\n<p class=\"error\">" . $clang->gT('Error: This question has no answers.') . "</p>\n";
        } else {
            //already done $lresult = db_execute_assoc($lquery);
            while ($lrow = $lresult->FetchRow()) {
                $labels0[] = array('code' => $lrow['code'], 'title' => $lrow['answer']);
            }
            $lresult1 = db_execute_assoc($lquery1);
            //Checked
            while ($lrow1 = $lresult1->FetchRow()) {
                $labels1[] = array('code' => $lrow1['code'], 'title' => $lrow1['answer']);
            }
            // Get attributes for Headers and Prefix/Suffix
            if (trim($qidattributes['dropdown_prepostfix']) != '') {
                list($ddprefix, $ddsuffix) = explode("|", $qidattributes['dropdown_prepostfix']);
                $ddprefix = $ddprefix;
                $ddsuffix = $ddsuffix;
            } else {
                $ddprefix = '';
                $ddsuffix = '';
            }
            if (trim($qidattributes['dropdown_separators']) != '') {
                list($postanswSep, $interddSep) = explode('|', $qidattributes['dropdown_separators']);
                $postanswSep = $postanswSep;
                $interddSep = $interddSep;
            } else {
                $postanswSep = '';
                $interddSep = '';
            }
            $colspan_1 = '';
            $colspan_2 = '';
            $suffix_cell = '';
            $answer .= "\n<table class=\"question\" 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";
            $trbc = '';
            while ($ansrow = $ansresult->FetchRow()) {
                $rowname = $ia[1] . $ansrow['title'];
                $dualgroup = 0;
                $myfname = $ia[1] . $ansrow['title'] . "#" . $dualgroup;
                $dualgroup1 = 1;
                $myfname1 = $ia[1] . $ansrow['title'] . "#" . $dualgroup1;
                if (is_array($notanswered) && array_search($ia[1], $notanswered) !== FALSE && ($_SESSION[$myfname] == "" || $_SESSION[$myfname1] == "")) {
                    $answertext = "<span class='errormandatory'>" . answer_replace($ansrow['question']) . "</span>";
                } else {
                    $answertext = answer_replace($ansrow['question']);
                }
                $trbc = alternation($trbc, 'row');
                // Get array_filter stuff
                list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc, $myfname);
                $answer .= $htmltbody2;
                $answer .= "<tr class=\"{$trbc}\">\n" . "\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\">{$ddprefix}</td>\n";
                }
                $answer .= "\t<td >\n" . "<select name=\"{$myfname}\" id=\"answer{$myfname}\" onchange=\"special_checkconditions(this.value, this.name, this.type,{$dualgroup});\">\n";
                if (!isset($_SESSION[$myfname]) || $_SESSION[$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[$myfname]) && $_SESSION[$myfname] == $lrow['code']) {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . $lrow['title'] . "</option>\n";
                }
                // If not mandatory and showanswer, show no ans
                if ($ia[6] != 'Y' && $shownoanswer == 1) {
                    $answer .= "\t<option value=\"\" ";
                    if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == '') {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . $clang->gT('No answer') . "</option>\n";
                }
                $answer .= "</select>\n";
                // suffix
                if ($ddsuffix != '') {
                    $answer .= "\t<td class=\"ddsuffix\">{$ddsuffix}</td>\n";
                }
                $answer .= "<input type=\"hidden\" name=\"java{$myfname}\" id=\"java{$myfname}\" value=\"";
                if (isset($_SESSION[$myfname])) {
                    $answer .= $_SESSION[$myfname];
                }
                $answer .= "\" />\n" . "\t</td>\n";
                $inputnames[] = $myfname;
                $answer .= "\t<td class=\"ddarrayseparator\">{$interddSep}</td>\n";
                //Separator
                // Label1
                // prefix
                if ($ddprefix != '') {
                    $answer .= "\t<td class='ddprefix'>{$ddprefix}</td>\n";
                }
                //				$answer .= "\t<td align='left' width='$columnswidth%'>\n"
                $answer .= "\t<td>\n" . "<select name=\"{$myfname1}\" id=\"answer{$myfname1}\" onchange=\"special_checkconditions(this.value, this.name, this.type,{$dualgroup1});\">\n";
                if (!isset($_SESSION[$myfname1]) || $_SESSION[$myfname1] == '') {
                    $answer .= "\t<option value=\"\"" . SELECTED . '>' . $clang->gT('Please choose...') . "</option>\n";
                }
                foreach ($labels1 as $lrow1) {
                    $answer .= "\t<option value=\"" . $lrow1['code'] . '" ';
                    if (isset($_SESSION[$myfname1]) && $_SESSION[$myfname1] == $lrow1['code']) {
                        $answer .= SELECTED;
                    }
                    $answer .= '>' . $lrow1['title'] . "</option>\n";
                }
                // If not mandatory and showanswer, show no ans
                if ($ia[6] != 'Y' && $shownoanswer == 1) {
                    $answer .= "\t<option value='' ";
                    if (!isset($_SESSION[$myfname1]) || $_SESSION[$myfname1] == '') {
                        $answer .= SELECTED;
                    }
                    $answer .= ">" . $clang->gT('No answer') . "</option>\n";
                }
                $answer .= "</select>\n";
                // suffix
                if ($ddsuffix != '') {
                    $answer .= "\t<td class=\"ddsuffix\">{$ddsuffix}</td>\n";
                }
                $answer .= "<input type=\"hidden\" name=\"java{$myfname1}\" id=\"java{$myfname1}\" value=\"";
                if (isset($_SESSION[$myfname1])) {
                    $answer .= $_SESSION[$myfname1];
                }
                $answer .= "\" />\n" . "\t</td>\n";
                $inputnames[] = $myfname1;
                $answer .= "</tr>\n";
                $answer .= "\t</tbody>\n";
            }
        }
        // End there are answers
        $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);
}