Example #1
0
function do_multiplechoice($ia)
{
    global $dbprefix, $clang, $connect, $thissurvey;

    // Find out if any questions have attributes which reference this questions
    // based on value of attribute. This could be array_filter and array_filter_exclude

    $attribute_ref=false;
    $inputnames=array();

    $qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value LIKE '".strtolower($ia[2])."' and (attribute='array_filter' or attribute='array_filter_exclude')";
    $qaresult = db_execute_assoc($qaquery);     //Checked
    while($qarow = $qaresult->FetchRow())
    {
        $qquery = "SELECT qid FROM ".db_table_name('questions')." WHERE sid=".$thissurvey['sid']." AND scale_id=0 AND qid=".$qarow['qid'];
        $qresult = db_execute_assoc($qquery);     //Checked
        if ($qresult->RecordCount() > 0)
        {
            $attribute_ref = true;
        }
    }

    if ($ia[8] == 'Y' || $attribute_ref === true)
    {
        $checkconditionFunction = "checkconditions";
    }
    else
    {
        $checkconditionFunction = "noop_checkconditions";
    }

    $qidattributes=getQuestionAttributes($ia[0],$ia[4]);

    if (trim($qidattributes['other_replace_text'])!='')
    {
        $othertext=$qidattributes['other_replace_text'];
    }
    else
    {
        $othertext=$clang->gT('Other:');
    }

    if (trim($qidattributes['display_columns'])!='')
    {
        $dcols = $qidattributes['display_columns'];
    }
    else
    {
        $dcols = 1;
    }

    if ($qidattributes['other_numbers_only']==1)
    {
        $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeperator= $sSeperator['seperator'];
        $numbersonly = 'return goodchars(event,"0123456789'.$sSeperator.'")';
    }
    else
    {
        $numbersonly = '';
    }

    // Check if the max_answers attribute is set
    $maxansw = 0;
    $callmaxanswscriptcheckbox = '';
    $callmaxanswscriptother = '';
    $maxanswscript = '';

    $exclude_all_others_auto = trim($qidattributes["exclude_all_others_auto"]);

    if ($exclude_all_others_auto=='1'){
        $autoArray['list'][]=$ia[1];
        $autoArray[$ia[1]]['parent'] = $ia[1];
    }

    if (trim($qidattributes['exclude_all_others'])!='')
    {
        $excludeallothers=explode(';',trim($qidattributes['exclude_all_others']));
        $excludeallotherscript = "
		<script type='text/javascript'>
		<!--
		function excludeAllOthers$ia[1](value, doconditioncheck)
		{\n";
        $excludeallotherscripton='';
        $excludeallotherscriptoff='';
    }
    else
    {
        $excludeallothers=array();
    }


    if (((int)$qidattributes['max_answers']>0) && $exclude_all_others_auto=='0')
    {
        $maxansw=$qidattributes['max_answers'];
        $callmaxanswscriptcheckbox = "limitmaxansw_{$ia[0]}(this);";
        $callmaxanswscriptother = "onkeyup='limitmaxansw_{$ia[0]}(this)'";
        $maxanswscript = "\t<script type='text/javascript'>\n"
        . "\t<!--\n"
        . "function limitmaxansw_{$ia[0]}(me)\n"
        . "{\n"
        . "\tmax=$maxansw\n"
        . "\tcount=0;\n"
        . "\tif (max == 0) { return count; }\n";
    }


    // Check if the min_answers attribute is set
    $minansw=0;
    $minanswscript = "";

    if ((int)$qidattributes['min_answers']>0)
    {
        $minansw=trim($qidattributes["min_answers"]);
        $minanswscript = "<script type='text/javascript'>\n"
        . "\t<!--\n"
        . "oldonsubmit_{$ia[0]} = document.limesurvey.onsubmit;\n"
        . "function ensureminansw_{$ia[0]}()\n"
        . "{\n"
        . "\tcount=0;\n"
        ;
    }

    $qquery = "SELECT other FROM ".db_table_name('questions')." WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."' and parent_qid=0";
    $qresult = db_execute_assoc($qquery);     //Checked
    while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];}

    if ($qidattributes['random_order']==1) {
        $ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
    }
    else
    {
        $ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
    }

    $ansresult = $connect->GetAll($ansquery);  //Checked
    $anscount = count($ansresult);

    if (trim($qidattributes['exclude_all_others'])!='' && $qidattributes['random_order']==1)
    {
        //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
        $position=0;
        foreach ($ansresult as $answer)
        {
            if ((trim($qidattributes['exclude_all_others']) != '')  &&    ($answer['title']==trim($qidattributes['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++;
        }
    }


    if ($other == 'Y')
    {
        $anscount++; //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING!
    }

    $wrapper = setup_columns($dcols, $anscount);

    $answer = '<input type="hidden" name="MULTI'.$ia[1].'" value="'.$anscount."\" />\n\n".$wrapper['whole-start'];

    $fn = 1;
    if (!isset($multifields))
    {
        $multifields = '';
    }

    $rowcounter = 0;
    $colcounter = 1;
    $startitem='';
    $postrow = '';
    $trbc='';
    foreach ($ansresult as $ansrow)
    {
        $myfname = $ia[1].$ansrow['title'];

        if ($exclude_all_others_auto==1){
            if ($ansrow['title']==trim($qidattributes['exclude_all_others'])){
                $autoArray[$ia[1]]['focus'] = $ia[1].trim($qidattributes['exclude_all_others']);
            }
            else{
                $autoArray[$ia[1]]['children'][] = $myfname;
            }
        }

        $trbc='';
        /* Check for array_filter */
        list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li");

        if($wrapper['item-start'] == "\t<li>\n")
        {
            $startitem = "\t$htmltbody2\n";
        } else {
            $startitem = $wrapper['item-start'];
        }

        /* Print out the checkbox */
        $answer .= $startitem;
        $answer .= "\t$hiddenfield\n";
        $answer .= '		<input class="checkbox" type="checkbox" name="'.$ia[1].$ansrow['title'].'" id="answer'.$ia[1].$ansrow['title'].'" value="Y"';

        /* If the question has already been ticked, check the checkbox */
        if (isset($_SESSION[$myfname]))
        {
            if ($_SESSION[$myfname] == 'Y')
            {
                $answer .= CHECKED;
                if(in_array($ansrow['title'], $excludeallothers))
                {
                    $postrow.="\n\n<script type='text/javascript'>\n<!--\nexcludeAllOthers$ia[1]('answer$ia[1]{$ansrow['title']}', 'no');\n-->\n</script>\n";
                }
            }
        }
        $answer .= " onclick='cancelBubbleThis(event);";
        /* Exclude all others coding */
        if(in_array($ansrow['title'], $excludeallothers))
        {
            $answer .= "excludeAllOthers$ia[1](this.id, \"yes\");"; // was "this.id"
            $excludeallotherscripton .= "/* SKIPPING QUESTION {$ia[1]} */\n";
            //			$excludeallotherscripton .= "alert(value+'---'+'answer$ia[1]{$ansrow['code']}');\n";
            $excludeallotherscripton .= "if( value != 'answer$ia[1]{$ansrow['title']}') {\n"
            . "\tthiselt=document.getElementById('answer$ia[1]{$ansrow['title']}');\n"
            . "thiselt.checked='';\n"
            . "thiselt.disabled='true';\n"
            . "if (doconditioncheck == 'yes') {\n"
            . "\t$checkconditionFunction(thiselt.value, thiselt.name, thiselt.type);\n"
            . "}\n}\n";
            $excludeallotherscriptoff .= "document.getElementById('answer$ia[1]{$ansrow['title']}').disabled='';\n";
        }
        elseif (count($excludeallothers)>0)
        {
            $excludeallotherscripton .= "\tthiselt=document.getElementById('answer$ia[1]{$ansrow['title']}');\n"
            . "thiselt.checked='';\n"
            . "thiselt.disabled='true';\n"
            . "if (doconditioncheck == 'yes') {\n"
            . "\t$checkconditionFunction(thiselt.value, thiselt.name, thiselt.type);\n"
            . "}\n";
            $excludeallotherscriptoff.= "document.getElementById('answer$ia[1]{$ansrow['title']}').disabled='';\n";
        }
        /* End of exclude all others coding */

        $answer .= $callmaxanswscriptcheckbox    	/* Include checkbox for script for maxanswers if that attribute is selected */
        .  "$checkconditionFunction(this.value, this.name, this.type)' />\n"
        .  "<label for=\"answer$ia[1]{$ansrow['title']}\" class=\"answertext\">"
        .  $ansrow['question']
        .  "</label>\n";


        if ($maxansw > 0) {$maxanswscript .= "\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";}
        if ($minansw > 0) {$minanswscript .= "\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";}

        ++$fn;
        /* Now add the hidden field to contain information about this answer */
        $answer .= '		<input type="hidden" name="java'.$myfname.'" id="java'.$myfname.'" value="';
        if (isset($_SESSION[$myfname]))
        {
            $answer .= $_SESSION[$myfname];
        }
        $answer .= "\" />\n{$wrapper['item-end']}";

        $inputnames[]=$myfname;

        ++$rowcounter;
        if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
        {
            if($colcounter == $wrapper['cols'] - 1)
            {
                $answer .= $wrapper['col-devide-last'];
            }
            else
            {
                $answer .= $wrapper['col-devide'];
            }
            $rowcounter = 0;
            ++$colcounter;
        }
    }
    if ($exclude_all_others_auto==1){
        $answer .= "<script type='text/javascript'>autoArray = ".json_encode($autoArray).";</script>";
    }
    if ($other == 'Y')
    {
        $myfname = $ia[1].'other';
        list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, array("code"=>"other"), $myfname, $trbc, $myfname, "li");
        if(count($excludeallothers) > 0)
        {
            $excludeallotherscripton .= "thiselt=document.getElementById('answer{$ia[1]}othercbox');\n"
            . "thiselt.checked='';\n"
            . "thiselt.disabled='true';\n";
            $excludeallotherscripton .= "thiselt=document.getElementById('answer$ia[1]other');\n"
            . "thiselt.value='';\n"
            . "thiselt.disabled='true';\n"
            . "if (doconditioncheck == 'yes') {\n"
            . "\t$checkconditionFunction(thiselt.value, thiselt.name, thiselt.type);\n"
            . "}\n";
            $excludeallotherscriptoff .="document.getElementById('answer$ia[1]other').disabled='';\n";
            $excludeallotherscriptoff .="document.getElementById('answer{$ia[1]}othercbox').disabled='';\n";
        }
        if($wrapper['item-start'] == "\t<li>\n")
        {
            $startitem = "\t$htmltbody2\n";
        } else {
            $startitem = $wrapper['item-start'];
        }
        $answer .= $startitem;
		$answer .= $hiddenfield.'
		<input class="checkbox" type="checkbox" name="'.$myfname.'cbox" alt="'.$clang->gT('Other').'" id="answer'.$myfname.'cbox"';

        if (isset($_SESSION[$myfname]) && trim($_SESSION[$myfname])!='')
        {
            $answer .= CHECKED;
        }
        $answer .= " onclick='cancelBubbleThis(event);".$callmaxanswscriptcheckbox."if(this.checked===false) document.getElementById(\"answer$myfname\").value=\"\";";
        $answer .= " if(this.checked===true) document.getElementById(\"answer$myfname\").focus();";
        $answer .= " $checkconditionFunction(document.getElementById(\"answer$myfname\").value, document.getElementById(\"answer$myfname\").name, document.getElementById(\"answer$myfname\").type);";
        $answer .= "' />
		<label for=\"answer$myfname\" class=\"answertext\">".$othertext."</label>
		<input class=\"text\" type=\"text\" name=\"$myfname\" id=\"answer$myfname\"";
        if (isset($_SESSION[$myfname]))
        {
            $answer .= ' value="'.htmlspecialchars($_SESSION[$myfname],ENT_QUOTES).'"';
        }
        $answer .= " onkeyup='$checkconditionFunction(this.value, this.name, this.type);if ($.trim($(\"#answer{$myfname}\").val())!=\"\" && !document.getElementById(\"answer{$myfname}cbox\").checked) {\$(\"#answer{$myfname}cbox\").attr(\"checked\",\"checked\");} $numbersonly ".$callmaxanswscriptcheckbox."' />";
        $answer .= '<input type="hidden" name="java'.$myfname.'" id="java'.$myfname.'" value="';

        if ($maxansw > 0)
        {
            // For multiplechoice question there is no DB field for the other Checkbox
            // I've added a javascript which will warn a user if no other comment is given while the other checkbox is checked
            // For the maxanswer script, I will alert the participant
            // if the limit is reached when he checks the other cbox
            // even if the -other- input field is still empty
            $maxanswscript .= "\tif (document.getElementById('answer".$myfname."cbox').checked ) { count += 1; }\n";
        }
        if ($minansw > 0)
        {
            //
            // For multiplechoice question there is no DB field for the other Checkbox
            // We only count the -other- as valid if both the cbox and the other text is filled
            $minanswscript .= "\tif (document.getElementById('answer".$myfname."').value != '' && document.getElementById('answer".$myfname."cbox').checked ) { count += 1; }\n";
        }


        if (isset($_SESSION[$myfname]))
        {
            $answer .= htmlspecialchars($_SESSION[$myfname],ENT_QUOTES);
        }

        $answer .= "\" />\n{$wrapper['item-end']}";
        $inputnames[]=$myfname;
        ++$anscount;

        ++$rowcounter;
        if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
        {
            if($colcounter == $wrapper['cols'] - 1)
            {
                $answer .= $wrapper['col-devide-last'];
            }
            else
            {
                $answer .= $wrapper['col-devide'];
            }
            $rowcounter = 0;
            ++$colcounter;
        }
    }
    $answer .= $wrapper['whole-end'];
    if ( $maxansw > 0 )
    {
        $maxanswscript .= "
        if (count > max)
        {
            alert('".sprintf($clang->gT("Please choose at most %d answers for question \"%s\"","js"), $maxansw, trim(javascript_escape(str_replace(array("\n", "\r"), "", $ia[3]),true,true)))."');
            if (me.type == 'checkbox') {me.checked = false;}
            if (me.type == 'text') {
                me.value = '';
                if (document.getElementById('answer'+me.name + 'cbox') ){
                    document.getElementById('answer'+me.name + 'cbox').checked = false;
                }
            }
            return max;
        }
}
//-->
</script>\n";
        $answer = $maxanswscript . $answer;
    }


    if ( $minansw > 0 )
    {
        $minanswscript .=
			"\tif (count < {$minansw} && document.getElementById('display{$ia[0]}').value == 'on'){\n"
        . "alert('".sprintf($clang->gT("Please choose at least %d answer(s) for question \"%s\"","js"),
        $minansw, trim(javascript_escape(str_replace(array("\n", "\r"), "",$ia[3]),true,true)))."');\n"
        . "return false;\n"
        . "\t} else {\n"
        . "if (oldonsubmit_{$ia[0]}){\n"
        . "\treturn oldonsubmit_{$ia[0]}();\n"
        . "}\n"
        . "return true;\n"
        . "\t}\n"
        . "}\n"
        . "document.limesurvey.onsubmit = ensureminansw_{$ia[0]}\n"
        . "-->\n"
        . "\t</script>\n";
        //$answer = $minanswscript . $answer;
    }

    $checkotherscript = "";
    if ($other == 'Y')
    {
        // Multiple choice with 'other' is a specific case as the checkbox isn't recorded into DB
        // this means that if it is cehcked We must force the end-user to enter text in the input
        // box
        $checkotherscript = "<script type='text/javascript'>\n"
        . "\t<!--\n"
        . "oldonsubmitOther_{$ia[0]} = document.limesurvey.onsubmit;\n"
        . "function ensureOther_{$ia[0]}()\n"
        . "{\n"
        . "\tothercboxval=document.getElementById('answer".$myfname."cbox').checked;\n"
        . "\totherval=document.getElementById('answer".$myfname."').value;\n"
        . "\tif (otherval != '' || othercboxval != true) {\n"
        . "if(typeof oldonsubmitOther_{$ia[0]} == 'function') {\n"
        . "\treturn oldonsubmitOther_{$ia[0]}();\n"
        . "}\n"
        . "\t}\n"
        . "\telse {\n"
        . "alert('".sprintf($clang->gT("You've marked the \"other\" field for question \"%s\". Please also fill in the accompanying \"other comment\" field.","js"),trim(javascript_escape($ia[3],true,true)))."');\n"
        . "return false;\n"
        . "\t}\n"
        . "}\n"
        . "document.limesurvey.onsubmit = ensureOther_{$ia[0]};\n"
        . "\t-->\n"
        . "</script>\n";
    }

    $answer = $minanswscript . $checkotherscript . $answer;

    if (count($excludeallothers)>0)
    {
        $excludeallotherscript .= "
		    if (document.getElementById(value).checked)
		    {
		        $excludeallotherscripton
		    }
		    else
		    {
		        $excludeallotherscriptoff
		    }
		}
		//-->
		</script>";
		$answer = $excludeallotherscript . $answer;
    }
    $answer .= $postrow;
    return array($answer, $inputnames);
}
     }
 } else {
     $maxansw = $qidattributes["max_answers"];
     $question['QUESTION_TYPE_HELP'] = sprintf($clang->gT('Please choose *at most* %s answers:'), '<span class="num">' . $maxansw . '</span>');
     if (isset($_POST['printableexport'])) {
         $pdf->intopdf(sprintf($clang->gT('Please choose *at most* %s answers:'), $maxansw), "U");
     }
 }
 $meaquery = "SELECT * FROM " . db_table_name("questions") . " WHERE parent_qid={$deqrow['qid']} AND language='{$surveyprintlang}' ORDER BY question_order";
 $question['QUESTION_TYPE_HELP'] .= array_filter_help($qidattributes, $surveyprintlang, $surveyid);
 $mearesult = db_execute_assoc($meaquery);
 $meacount = $mearesult->RecordCount();
 if ($deqrow['other'] == 'Y') {
     $meacount++;
 }
 $wrapper = setup_columns($dcols, $meacount);
 $question['ANSWER'] = $wrapper['whole-start'];
 $rowcounter = 0;
 $colcounter = 1;
 while ($mearow = $mearesult->FetchRow()) {
     $question['ANSWER'] .= $wrapper['item-start'] . input_type_image('checkbox', $mearow['question']) . "\n\t\t" . $mearow['question'] . addsgqacode(" (" . $fieldname . $mearow['title'] . ") ") . $wrapper['item-end'];
     if (isset($_POST['printableexport'])) {
         $pdf->intopdf(" o " . $mearow['answer']);
     }
     //						$upto++;
     ++$rowcounter;
     if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) {
         if ($colcounter == $wrapper['cols'] - 1) {
             $question['ANSWER'] .= $wrapper['col-devide-last'];
         } else {
             $question['ANSWER'] .= $wrapper['col-devide'];
Example #3
0
function do_multiplechoice($ia)
{
    global $dbprefix, $clang, $connect, $thissurvey;
    if ($thissurvey['nokeyboard'] == 'Y') {
        vIncludeKeypad();
        $kpclass = "text-keypad";
    } else {
        $kpclass = "";
    }
    // Find out if any questions have attributes which reference this questions
    // based on value of attribute. This could be array_filter and array_filter_exclude
    $attribute_ref = false;
    $inputnames = array();
    $qaquery = "SELECT qid,attribute FROM " . db_table_name('question_attributes') . " WHERE value LIKE '" . strtolower($ia[2]) . "' and (attribute='array_filter' or attribute='array_filter_exclude')";
    $qaresult = db_execute_assoc($qaquery);
    //Checked
    while ($qarow = $qaresult->FetchRow()) {
        $qquery = "SELECT qid FROM " . db_table_name('questions') . " WHERE sid=" . $thissurvey['sid'] . " AND scale_id=0 AND qid=" . $qarow['qid'];
        $qresult = db_execute_assoc($qquery);
        //Checked
        if ($qresult->RecordCount() > 0) {
            $attribute_ref = true;
        }
    }
    $checkconditionFunction = "checkconditions";
    $qidattributes = getQuestionAttributes($ia[0], $ia[4]);
    if (trim($qidattributes['other_replace_text']) != '') {
        $othertext = $qidattributes['other_replace_text'];
    } else {
        $othertext = $clang->gT('Other:');
    }
    if (trim($qidattributes['display_columns']) != '') {
        $dcols = $qidattributes['display_columns'];
    } else {
        $dcols = 1;
    }
    if ($qidattributes['other_numbers_only'] == 1) {
        $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeperator = $sSeperator['seperator'];
        $oth_checkconditionFunction = "fixnum_checkconditions";
    } else {
        $oth_checkconditionFunction = "checkconditions";
    }
    $qquery = "SELECT other FROM " . db_table_name('questions') . " WHERE qid=" . $ia[0] . " AND language='" . $_SESSION['s_lang'] . "' and parent_qid=0";
    $qresult = db_execute_assoc($qquery);
    //Checked
    while ($qrow = $qresult->FetchRow()) {
        $other = $qrow['other'];
    }
    if ($qidattributes['random_order'] == 1) {
        $ansquery = "SELECT * FROM " . db_table_name('questions') . " WHERE parent_qid={$ia['0']} AND scale_id=0 AND language='" . $_SESSION['s_lang'] . "' ORDER BY " . db_random();
    } else {
        $ansquery = "SELECT * FROM " . db_table_name('questions') . " WHERE parent_qid={$ia['0']} AND scale_id=0 AND language='" . $_SESSION['s_lang'] . "' ORDER BY question_order";
    }
    $ansresult = $connect->GetAll($ansquery);
    //Checked
    $anscount = count($ansresult);
    if (trim($qidattributes['exclude_all_others']) != '' && $qidattributes['random_order'] == 1) {
        //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
        $position = 0;
        foreach ($ansresult as $answer) {
            if (trim($qidattributes['exclude_all_others']) != '' && $answer['title'] == trim($qidattributes['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++;
        }
    }
    if ($other == 'Y') {
        $anscount++;
        //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING!
    }
    $wrapper = setup_columns($dcols, $anscount);
    $answer = '<input type="hidden" name="MULTI' . $ia[1] . '" value="' . $anscount . "\" />\n\n" . $wrapper['whole-start'];
    $fn = 1;
    if (!isset($multifields)) {
        $multifields = '';
    }
    $rowcounter = 0;
    $colcounter = 1;
    $startitem = '';
    $postrow = '';
    $trbc = '';
    foreach ($ansresult as $ansrow) {
        $myfname = $ia[1] . $ansrow['title'];
        $trbc = '';
        /* Check for array_filter */
        list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li");
        if ($wrapper['item-start'] == "\t<li>\n") {
            $startitem = "\t{$htmltbody2}\n";
        } else {
            $startitem = $wrapper['item-start'];
        }
        /* Print out the checkbox */
        $answer .= $startitem;
        $answer .= "\t{$hiddenfield}\n";
        $answer .= '		<input class="checkbox" type="checkbox" name="' . $ia[1] . $ansrow['title'] . '" id="answer' . $ia[1] . $ansrow['title'] . '" value="Y"';
        /* If the question has already been ticked, check the checkbox */
        if (isset($_SESSION[$myfname])) {
            if ($_SESSION[$myfname] == 'Y') {
                $answer .= CHECKED;
            }
        }
        $answer .= " onclick='cancelBubbleThis(event);";
        $answer .= '' . "{$checkconditionFunction}(this.value, this.name, this.type)' />\n" . "<label for=\"answer{$ia['1']}{$ansrow['title']}\" class=\"answertext\">" . $ansrow['question'] . "</label>\n";
        ++$fn;
        /* Now add the hidden field to contain information about this answer */
        $answer .= '		<input type="hidden" name="java' . $myfname . '" id="java' . $myfname . '" value="';
        if (isset($_SESSION[$myfname])) {
            $answer .= $_SESSION[$myfname];
        }
        $answer .= "\" />\n{$wrapper['item-end']}";
        $inputnames[] = $myfname;
        ++$rowcounter;
        if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) {
            if ($colcounter == $wrapper['cols'] - 1) {
                $answer .= $wrapper['col-devide-last'];
            } else {
                $answer .= $wrapper['col-devide'];
            }
            $rowcounter = 0;
            ++$colcounter;
        }
    }
    if ($other == 'Y') {
        $myfname = $ia[1] . 'other';
        list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $qidattributes, $thissurvey, array("code" => "other"), $myfname, $trbc, $myfname, "li", "other");
        if ($wrapper['item-start'] == "\t<li>\n") {
            $startitem = "\t{$htmltbody2}\n";
        } else {
            $startitem = $wrapper['item-start'];
        }
        $answer .= $startitem;
        $answer .= $hiddenfield . '
		<input class="checkbox other-checkbox" type="checkbox" name="' . $myfname . 'cbox" alt="' . $clang->gT('Other') . '" id="answer' . $myfname . 'cbox" ';
        // othercbox can not be display, Can use css to hide it.
        if (isset($_SESSION[$myfname]) && trim($_SESSION[$myfname]) != '') {
            $answer .= CHECKED;
        }
        $answer .= " onclick='cancelBubbleThis(event);if(this.checked===false){ document.getElementById(\"answer{$myfname}\").value=\"\"; document.getElementById(\"java{$myfname}\").value=\"\"; {$checkconditionFunction}(\"\", \"{$myfname}\", \"text\"); }";
        $answer .= " if(this.checked===true) { document.getElementById(\"answer{$myfname}\").focus(); }; LEMflagMandOther(\"{$myfname}\",this.checked);";
        $answer .= "' />\n\t\t<label for=\"answer{$myfname}\" class=\"answertext\">" . $othertext . "</label>\n\t\t<input class=\"text " . $kpclass . "\" type=\"text\" name=\"{$myfname}\" id=\"answer{$myfname}\"";
        if (isset($_SESSION[$myfname])) {
            $dispVal = $_SESSION[$myfname];
            if ($qidattributes['other_numbers_only'] == 1) {
                $dispVal = str_replace('.', $sSeperator, $dispVal);
            }
            $answer .= ' value="' . htmlspecialchars($dispVal, ENT_QUOTES) . '"';
        }
        #        $answer .= " onkeyup='if ($.trim(this.value)!=\"\") { \$(\"#answer{$myfname}cbox\").attr(\"checked\",\"checked\"); } else { \$(\"#answer{$myfname}cbox\").attr(\"checked\",\"\"); }; $(\"#java{$myfname}\").val(this.value);$oth_checkconditionFunction(this.value, this.name, this.type); LEMflagMandOther(\"$myfname\",\$(\"#answer{$myfname}cbox\").attr(\"checked\"));' />";
        $answer .= " />";
        $answer .= "<script type='text/javascript'>\n";
        $answer .= "\$('#answer{$myfname}').bind('keyup blur',function(){\n";
        $answer .= " if (\$.trim(\$(this).val())!=\"\") { \$(\"#answer{$myfname}cbox\").attr(\"checked\",true); } else { \$(\"#answer{$myfname}cbox\").attr(\"checked\",false); }; \$(\"#java{$myfname}\").val(\$(this).val());{$oth_checkconditionFunction}(this.value, this.name, this.type); LEMflagMandOther(\"{$myfname}\",\$(\"#answer{$myfname}cbox\").attr(\"checked\"));\n";
        $answer .= "});\n";
        $answer .= "</script>\n";
        $answer .= '<input type="hidden" name="java' . $myfname . '" id="java' . $myfname . '" value="';
        if (isset($_SESSION[$myfname])) {
            $dispVal = $_SESSION[$myfname];
            if ($qidattributes['other_numbers_only'] == 1) {
                $dispVal = str_replace('.', $sSeperator, $dispVal);
            }
            $answer .= htmlspecialchars($dispVal, ENT_QUOTES);
        }
        $answer .= "\" />\n{$wrapper['item-end']}";
        $inputnames[] = $myfname;
        ++$anscount;
        ++$rowcounter;
        if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) {
            if ($colcounter == $wrapper['cols'] - 1) {
                $answer .= $wrapper['col-devide-last'];
            } else {
                $answer .= $wrapper['col-devide'];
            }
            $rowcounter = 0;
            ++$colcounter;
        }
    }
    $answer .= $wrapper['whole-end'];
    #   No need $checkotherscript : already done by check mandatory
    #    $checkotherscript = "";
    #    if ($other == 'Y')
    #    {
    #        // Multiple choice with 'other' is a specific case as the checkbox isn't recorded into DB
    #        // this means that if it is cehcked We must force the end-user to enter text in the input
    #        // box
    #        $checkotherscript = "<script type='text/javascript'>\n"
    #        . "\t<!--\n"
    #        . "oldonsubmitOther_{$ia[0]} = document.limesurvey.onsubmit;\n"
    #        . "function ensureOther_{$ia[0]}()\n"
    #        . "{\n"
    #        . "\tothercboxval=document.getElementById('answer".$myfname."cbox').checked;\n"
    #        . "\totherval=document.getElementById('answer".$myfname."').value;\n"
    #        . "\tif (otherval != '' || othercboxval != true) {\n"
    #        . "if(typeof oldonsubmitOther_{$ia[0]} == 'function') {\n"
    #        . "\treturn oldonsubmitOther_{$ia[0]}();\n"
    #        . "}\n"
    #        . "\t}\n"
    #        . "\telse {\n"
    #        . "alert('".sprintf($clang->gT("You've marked the '%s' field, please also fill in the accompanying comment field.","js"),$othertext)."');\n"
    #        . "return false;\n"
    #        . "\t}\n"
    #        . "}\n"
    #        . "document.limesurvey.onsubmit = ensureOther_{$ia[0]};\n"
    #        . "\t-->\n"
    #        . "</script>\n";
    #    }
    #    $answer = $checkotherscript . $answer;
    $answer .= $postrow;
    return array($answer, $inputnames);
}