Ejemplo n.º 1
0
    function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options)
    {
        global $QTYPES, $CFG, $USER;
        $readonly = empty($options->readonly) ? '' : 'readonly="readonly"';
        $disabled = empty($options->readonly) ? '' : 'disabled="disabled"';
        $formatoptions = new stdClass();
        $formatoptions->noclean = true;
        $formatoptions->para = false;
        $nameprefix = $question->name_prefix;
        // adding an icon with alt to warn user this is a fill in the gap question
        // MDL-7497
        if (!empty($USER->screenreader)) {
            echo "<img src=\"{$CFG->wwwroot}/question/type/{$question->qtype}/icon.gif\" " . "class=\"icon\" alt=\"" . get_string('clozeaid', 'qtype_multichoice') . "\" />  ";
        }
        echo '<div class="ablock clearfix">';
        // For this question type, we better print the image on top:
        if ($image = get_question_image($question)) {
            echo '<img class="qimage" src="' . $image . '" alt="" /><br />';
        }
        $qtextremaining = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course);
        $strfeedback = get_string('feedback', 'quiz');
        // The regex will recognize text snippets of type {#X}
        // where the X can be any text not containg } or white-space characters.
        while (ereg('\\{#([^[:space:]}]*)}', $qtextremaining, $regs)) {
            $qtextsplits = explode($regs[0], $qtextremaining, 2);
            echo $qtextsplits[0];
            echo "<label>";
            // MDL-7497
            $qtextremaining = $qtextsplits[1];
            $positionkey = $regs[1];
            if (isset($question->options->questions[$positionkey]) && $question->options->questions[$positionkey] != '') {
                $wrapped =& $question->options->questions[$positionkey];
                $answers =& $wrapped->options->answers;
                // $correctanswers = $QTYPES[$wrapped->qtype]->get_correct_responses($wrapped, $state);
                $inputname = $nameprefix . $positionkey;
                if (isset($state->responses[$positionkey])) {
                    $response = $state->responses[$positionkey];
                } else {
                    $response = null;
                }
                // Determine feedback popup if any
                $popup = '';
                $style = '';
                $feedbackimg = '';
                $feedback = '';
                $correctanswer = '';
                $strfeedbackwrapped = $strfeedback;
                $testedstate = clone $state;
                if (($correctanswers = $QTYPES[$wrapped->qtype]->get_correct_responses($wrapped, $testedstate)) !== false) {
                    if ($options->readonly && $options->correct_responses) {
                        $delimiter = '';
                        if ($correctanswers) {
                            foreach ($correctanswers as $ca) {
                                switch ($wrapped->qtype) {
                                    case 'numerical':
                                    case 'shortanswer':
                                    case 'shortanswerwiris':
                                        $correctanswer .= $delimiter . $ca;
                                        break;
                                    case 'multichoice':
                                    case 'multichoicewiris':
                                        if (isset($answers[$ca])) {
                                            $correctanswer .= $delimiter . $answers[$ca]->answer;
                                        }
                                        break;
                                }
                                $delimiter = ', ';
                            }
                        }
                    }
                    if ($correctanswer != '') {
                        $feedback = '<div class="correctness">';
                        $feedback .= get_string('correctansweris', 'quiz', s($correctanswer, true));
                        $feedback .= '</div>';
                    }
                }
                if ($options->feedback) {
                    $chosenanswer = null;
                    switch ($wrapped->qtype) {
                        case 'shortanswerwiris':
                            $index = 0;
                            $maxgrade = 0.0;
                            if (isset($state->grades) && isset($state->grades[$positionkey])) {
                                foreach ($answers as $answer) {
                                    if (isset($state->grades[$positionkey][$index]) && $state->grades[$positionkey][$index] > $maxgrade) {
                                        $chosenanswer = clone $answer;
                                        $maxgrade = $state->grades[$positionkey][$index];
                                    }
                                    $index++;
                                }
                            }
                            //Try string comparation if wiris grade is zero for this response.
                            if (!empty($chosenanswer)) {
                                break;
                            }
                        case 'numerical':
                        case 'shortanswer':
                            $testedstate = clone $state;
                            $testedstate->responses[''] = $response;
                            foreach ($answers as $answer) {
                                if ($QTYPES[$wrapped->qtype]->test_response($wrapped, $testedstate, $answer)) {
                                    $chosenanswer = clone $answer;
                                    break;
                                }
                            }
                            break;
                        case 'multichoicewiris':
                        case 'multichoice':
                            if (isset($answers[$response])) {
                                $chosenanswer = clone $answers[$response];
                            }
                            break;
                        default:
                            break;
                    }
                    // Set up a default chosenanswer so that all non-empty wrong
                    // answers are highlighted red
                    if (empty($chosenanswer) && $response != '') {
                        $chosenanswer = new stdClass();
                        $chosenanswer->fraction = 0.0;
                    }
                    if (isset($chosenanswer->feedback) && $chosenanswer->feedback !== '') {
                        $feedback = s(str_replace(array("\\", "'"), array("\\\\", "\\'"), $feedback . $chosenanswer->feedback));
                        if ($options->readonly && $options->correct_responses) {
                            $strfeedbackwrapped = get_string('correctanswerandfeedback', 'qtype_multianswer');
                        } else {
                            $strfeedbackwrapped = get_string('feedback', 'quiz');
                        }
                        $popup = " onmouseover=\"return overlib('{$feedback}', STICKY, MOUSEOFF, CAPTION, '{$strfeedbackwrapped}', FGCOLOR, '#FFFFFF');\" " . " onmouseout=\"return nd();\" ";
                    }
                    /// Determine style
                    if ($options->feedback && $response != '') {
                        $style = 'class = "' . question_get_feedback_class($chosenanswer->fraction) . '"';
                        $feedbackimg = question_get_feedback_image($chosenanswer->fraction);
                    } else {
                        $style = '';
                        $feedbackimg = '';
                    }
                }
                if ($feedback !== '' && $popup === '') {
                    $strfeedbackwrapped = get_string('correctanswer', 'qtype_multianswer');
                    $feedback = s(str_replace(array("\\", "'"), array("\\\\", "\\'"), $feedback));
                    $popup = " onmouseover=\"return overlib('{$feedback}', STICKY, MOUSEOFF, CAPTION, '{$strfeedbackwrapped}', FGCOLOR, '#FFFFFF');\" " . " onmouseout=\"return nd();\" ";
                }
                // Print the input control
                $editor = false;
                switch ($wrapped->qtype) {
                    case 'shortanswerwiris':
                        mb_parse_str($wrapped->options->wiris->eqoption, $eqoptionArray);
                        $editor = isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true';
                    case 'shortanswer':
                    case 'numerical':
                        if (!$editor) {
                            $size = 1;
                            foreach ($answers as $answer) {
                                if (strlen(trim($answer->answer)) > $size) {
                                    $assembledAnswer = wrsqz_assemble(wrsqz_variablesToText($answer->answer), $state->vars);
                                    $size = strlen(trim($assembledAnswer));
                                }
                            }
                            if (strlen(trim($response)) > $size) {
                                $size = strlen(trim($response)) + 1;
                            }
                            $size = $size + rand(0, $size * 0.15);
                            $size > 60 ? $size = 60 : ($size = $size);
                            $styleinfo = "size=\"{$size}\"";
                            /**
                             * Uncomment the following lines if you want to limit for small sizes.
                             * Results may vary with browsers see MDL-3274
                             */
                            /*
                            if ($size < 2) {
                                $styleinfo = 'style="width: 1.1em;"';
                            }
                            if ($size == 2) {
                                $styleinfo = 'style="width: 1.9em;"';
                            }
                            if ($size == 3) {
                                $styleinfo = 'style="width: 2.3em;"';
                            }
                            if ($size == 4) {
                                $styleinfo = 'style="width: 2.8em;"';
                            }
                            */
                            echo "<input {$style} {$readonly} {$popup} name=\"{$inputname}\"";
                            echo "  type=\"text\" value=\"" . s($response, true) . "\" " . $styleinfo . " /> ";
                        } else {
                            echo wrsqz_embeddedShortanswerInput($wrapped, $response, $inputname, $style, $readonly, $popup);
                        }
                        if ($feedback !== '' && !empty($USER->screenreader)) {
                            echo "<img src=\"{$CFG->pixpath}/i/feedback.gif\" alt=\"{$feedback}\" />";
                        }
                        echo $feedbackimg;
                        break;
                    case 'multichoicewiris':
                    case 'multichoice':
                        if ($wrapped->options->layout == 0) {
                            $outputoptions = '<option></option>';
                            // Default empty option
                            foreach ($answers as $mcanswer) {
                                $selected = '';
                                if ($response == $mcanswer->id) {
                                    $selected = ' selected="selected"';
                                }
                                $outputoptions .= "<option value=\"{$mcanswer->id}\"{$selected}>" . s($mcanswer->answer, true) . '</option>';
                            }
                            // In the next line, $readonly is invalid HTML, but it works in
                            // all browsers. $disabled would be valid, but then the JS for
                            // displaying the feedback does not work. Of course, we should
                            // not be relying on JS (for accessibility reasons), but that is
                            // a bigger problem.
                            //
                            // The span is used for safari, which does not allow styling of
                            // selects.
                            echo "<span {$style}><select {$popup} {$readonly} {$style} name=\"{$inputname}\">";
                            echo $outputoptions;
                            echo '</select></span>';
                            if ($feedback !== '' && !empty($USER->screenreader)) {
                                echo "<img src=\"{$CFG->pixpath}/i/feedback.gif\" alt=\"{$feedback}\" />";
                            }
                            echo $feedbackimg;
                        } else {
                            if ($wrapped->options->layout == 1 || $wrapped->options->layout == 2) {
                                $ordernumber = 0;
                                $anss = array();
                                foreach ($answers as $mcanswer) {
                                    $ordernumber++;
                                    $checked = '';
                                    $chosen = false;
                                    $type = 'type="radio"';
                                    $name = "name=\"{$inputname}\"";
                                    if ($response == $mcanswer->id) {
                                        $checked = 'checked="checked"';
                                        $chosen = true;
                                    }
                                    $a = new stdClass();
                                    $a->id = $question->name_prefix . $mcanswer->id;
                                    $a->class = '';
                                    $a->feedbackimg = '';
                                    // Print the control
                                    $a->control = "<input {$readonly} id=\"{$a->id}\" {$name} {$checked} {$type} value=\"{$mcanswer->id}\" />";
                                    if ($options->correct_responses && $mcanswer->fraction > 0) {
                                        $a->class = question_get_feedback_class(1);
                                    }
                                    if ($options->feedback && $chosen || $options->correct_responses) {
                                        if ($type == ' type="checkbox" ') {
                                            $a->feedbackimg = question_get_feedback_image($mcanswer->fraction > 0 ? 1 : 0, $chosen && $options->feedback);
                                        } else {
                                            $a->feedbackimg = question_get_feedback_image($mcanswer->fraction, $chosen && $options->feedback);
                                        }
                                    }
                                    // Print the answer text: no automatic numbering
                                    $a->text = format_text($mcanswer->answer, FORMAT_MOODLE, $formatoptions, $cmoptions->course);
                                    // Print feedback if feedback is on
                                    if (($options->feedback || $options->correct_responses) && $checked) {
                                        //|| $options->readonly
                                        $a->feedback = format_text($mcanswer->feedback, true, $formatoptions, $cmoptions->course);
                                    } else {
                                        $a->feedback = '';
                                    }
                                    $anss[] = clone $a;
                                }
                                ?>
            <?php 
                                if ($wrapped->options->layout == 1) {
                                    ?>
                  <table class="answer">
                    <?php 
                                    $row = 1;
                                    foreach ($anss as $answer) {
                                        ?>
                      <tr class="<?php 
                                        echo 'r' . ($row = $row ? 0 : 1);
                                        ?>
">
                        <td class="c0 control">
                          <?php 
                                        echo $answer->control;
                                        ?>
                        </td>
                        <td class="c1 text <?php 
                                        echo $answer->class;
                                        ?>
">
                          <label for="<?php 
                                        echo $answer->id;
                                        ?>
">
                            <?php 
                                        echo $answer->text;
                                        ?>
                            <?php 
                                        echo $answer->feedbackimg;
                                        ?>
                          </label>
                        </td>
                        <td class="c0 feedback">
                          <?php 
                                        echo $answer->feedback;
                                        ?>
                        </td>
                      </tr>
                    <?php 
                                    }
                                    ?>
                  </table>
                  <?php 
                                } else {
                                    if ($wrapped->options->layout == 2) {
                                        ?>

                  <table class="answer">
                      <tr class="<?php 
                                        echo 'r' . ($row = $row ? 0 : 1);
                                        ?>
">
                    <?php 
                                        $row = 1;
                                        foreach ($anss as $answer) {
                                            ?>
                        <td class="c0 control">
                          <?php 
                                            echo $answer->control;
                                            ?>
                        </td>
                        <td class="c1 text <?php 
                                            echo $answer->class;
                                            ?>
">
                          <label for="<?php 
                                            echo $answer->id;
                                            ?>
">
                            <?php 
                                            echo $answer->text;
                                            ?>
                            <?php 
                                            echo $answer->feedbackimg;
                                            ?>
                          </label>
                        </td>
                        <td class="c0 feedback">
                          <?php 
                                            echo $answer->feedback;
                                            ?>
                        </td>
                    <?php 
                                        }
                                        ?>
                      </tr>
                  </table>
                  <?php 
                                    }
                                }
                            } else {
                                echo "no valid layout";
                            }
                        }
                        break;
                    default:
                        $a = new stdClass();
                        $a->type = $wrapped->qtype;
                        $a->sub = $positionkey;
                        print_error('unknownquestiontypeofsubquestion', 'qtype_multianswer', '', $a);
                        break;
                }
                echo "</label>";
                // MDL-7497
            } else {
                if (!isset($question->options->questions[$positionkey])) {
                    echo $regs[0] . "</label>";
                } else {
                    echo '</label><div class="error" >' . get_string('questionnotfound', 'qtype_multianswer', $positionkey) . '</div>';
                }
            }
        }
        // Print the final piece of question text:
        echo $qtextremaining;
        if (!empty($question->options->wiris->options['wirisCASForComputations'])) {
            $wirisCASContent = '';
            if (isset($state->responses['wirisCASHidden'])) {
                $wirisCASContent = htmlentities(stripslashes_safe($state->responses['wirisCASHidden']), ENT_QUOTES, 'UTF-8');
            }
            echo '<br />';
            echo wrsqz_wirisCASAppletHTML($nameprefix, $wirisCASContent, false, 630, 300);
            require_js(array('yui_yahoo', 'yui_dom-event'));
            require_js($CFG->wwwroot . '/wiris-quizzes/js/wiris-quizzes.js');
        }
        $this->print_question_submit_buttons($question, $state, $cmoptions, $options);
        echo '</div>';
    }
/**
 * This page is a popup launched when a user is editing a question and clicks
 * the button 'Initial content' of CAS field.
 * **/
  require_once('../../config.php');
  global $CFG;
  require_once($CFG->dirroot.'/wiris-quizzes/lib/functions.php');
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php echo wrsqz_get_string('wrsqz_initialcontent'); ?></title>
        <script type="text/javascript"  src="<?php echo $CFG->wwwroot; ?>/lib/yui/yahoo/yahoo-min.js"></script>
        <script type="text/javascript"  src="<?php echo $CFG->wwwroot; ?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
        <script type="text/javascript" src="<?php echo $CFG->wwwroot; ?>/wiris-quizzes/js/constants.js"></script>
        <script type="text/javascript" src="<?php echo $CFG->wwwroot; ?>/wiris-quizzes/js/wiris-quizzes-edit.js"></script>
    </head>
    <body>
<?php
//applet
  $wirisCASContent = '';
  $applet = wrsqz_wirisCASAppletHTML('initial', $wirisCASContent, FALSE, "100%", "92%");
  echo $applet;
?>
         <div id="buttons" style="text-align: right; margin: 4px">
         <button id="initialCASOk"><?php echo wrsqz_get_string('wrsqz_ok'); ?></button>
         <button id="initialCASCancel"><?php echo wrsqz_get_string('wrsqz_cancel'); ?></button>
      </div>
    </body>
</html>
/**
 * Prints the question body. Since standard moodle question functions set up
 * variables and prints html in the same function, we cannot call these functions.
 * So, the most code of this function (specially the type-specific part) is copied
 * from the standard moodle question types.
 * **/
function wrsqz_print_question_formulation_and_controls($questionType, $dbType, &$question, &$state, &$cmoptions, &$options) {
	//COMMON VARIABLES:
  global $CFG, $QTYPES;
  //1. Question text
  $formatoptions = new stdClass;
  $formatoptions->noclean = true;
  $formatoptions->para = false;

  $questiontext = format_text($question->questiontext, $question->questiontextformat,
                              $formatoptions, $cmoptions->course);

  //2. Question image
  $image = get_question_image($question);

  //3. name & strings
  $inputname = $question->name_prefix;
  $stranswer = get_string("answer", "quiz").': ';

  //4. WIRIS CAS applet
  $wirisCASApplet = '';
  $wirisCASForComputationsEnabled = !empty($question->options->wiris->options['wirisCASForComputations']);
  if($wirisCASForComputationsEnabled){
    $wirisCASContent = '';
    if (!empty($state->responses['wirisCASHidden'])) {
      $wirisCASContent = htmlentities(stripslashes_safe($state->responses['wirisCASHidden']), ENT_QUOTES, 'UTF-8');
      unset($state->responses['wirisCASHidden']);
    }else if(!empty($question->options->wiris->options['hiddenInitialCASValue'])){
      $wirisCASContent = htmlentities(stripslashes_safe($question->options->wiris->options['hiddenInitialCASValue']), ENT_QUOTES, 'UTF-8');
    }
    $wirisCASApplet = wrsqz_wirisCASAppletHTML($inputname, $wirisCASContent, false, 630, 300);
    require_js(array('yui_yahoo', 'yui_dom-event'));
    require_js(array($CFG->wwwroot.'/wiris-quizzes/js/wiris-quizzes.js',$CFG->wwwroot.'/wiris-quizzes/js/constants.js.php'));
  }
  
  //ANSWER FIELDS & FEEDBACK: QUESTION-TYPE specific
  if($questionType == 'essay'){
    // Response
    if (isset($state->responses[''])) {
      $value = stripslashes_safe($state->responses['']);
    }else{
      $value = "";
    }
    //answer
    if($wirisCASForComputationsEnabled){
      $wirisCASForComputations = $question->options->wiris->options['wirisCASForComputations'];
    }else{
      $wirisCASForComputations = '0';
    }
    //replace answer by an applet
    if($wirisCASForComputations == '2'){
      $answer = $wirisCASApplet;
      $answer .= '<input type="hidden" name="'.$inputname.'" id="edit-'.$inputname.'"/>';
      $wirisCASApplet = '';
    }else{
      if (empty($options->readonly)) {
        static $htmleditorused = false;
        $usehtmleditor = can_use_html_editor() && !$htmleditorused;
        // the student needs to type in their answer so print out a text editor
        echo '<!-- yes we can: '.$usehtmleditor.'-->';
        $answer = print_textarea($usehtmleditor, 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true);
      }else{
        //it is read only, so just format the students answer and output it
        $safeformatoptions = new stdClass;
        $safeformatoptions->para = false;
        $answer = format_text($value, FORMAT_MOODLE, $safeformatoptions, $cmoptions->course);
        $answer = '<div class="answerreview">' . $answer . '</div>';
      }
      if($wirisCASForComputationsEnabled){
        $wirisCASApplet = '<tr><td>'.$wirisCASApplet.'</td></tr>';
      }
    }
    
    // feedback handling
    $feedback = '';
    if ($options->feedback && !empty($answers)) {
      foreach ($answers as $answer) {
        $feedback = format_text($answer->feedback, '', $formatoptions, $cmoptions->course);
      }
    }
    
  }else if($questionType == 'match'){
    $subquestions   = $state->options->subquestions;
    $correctanswers = $QTYPES[$question->qtype]->get_correct_responses($question, $state);
    $answers        = array(); // Answer choices formatted ready for output.
    $allanswers     = array(); // This and the next used to detect identical answers
    $answerids      = array(); // and adjust ids.
    $responses      = &$state->responses;

    // Prepare a list of answers, removing duplicates.
    foreach ($subquestions as $subquestion) {
      foreach ($subquestion->options->answers as $ans) {
        $allanswers[$ans->id] = $ans->answer;
        if (!in_array($ans->answer, $answers)) {
          $answers[$ans->id] = strip_tags(format_string($ans->answer, false));
          $answerids[$ans->answer] = $ans->id;
        }
      }
    }
    // Fix up the ids of any responses that point the the eliminated duplicates.
    foreach ($responses as $subquestionid => $ignored) {
      if ($responses[$subquestionid]) {
        $responses[$subquestionid] = $answerids[$allanswers[$responses[$subquestionid]]];
      }
    }
    foreach ($correctanswers as $subquestionid => $ignored) {
      $correctanswers[$subquestionid] = $answerids[$allanswers[$correctanswers[$subquestionid]]];
    }
    // Shuffle the answers
    $answers = draw_rand_array($answers, count($answers));
    // Print the input controls
    foreach ($subquestions as $key => $subquestion) {
      if ($subquestion->questiontext !== '' && !is_null($subquestion->questiontext)) {
        // Subquestion text:
        $a = new stdClass;
        $a->text = format_text($subquestion->questiontext,
        $question->questiontextformat, $cmoptions);
        // Drop-down list:
        $menuname = $inputname.$subquestion->id;
        $response = isset($state->responses[$subquestion->id])
                    ? $state->responses[$subquestion->id] : '0';
        $a->class = ' ';
        $a->feedbackimg = ' ';

        if ($options->readonly and $options->correct_responses) {
          if (isset($correctanswers[$subquestion->id])
          and ($correctanswers[$subquestion->id] == $response)) {
            $correctresponse = 1;
          } else {
            $correctresponse = 0;
          }
          if ($options->feedback && $response) {
            $a->class = question_get_feedback_class($correctresponse);
            $a->feedbackimg = question_get_feedback_image($correctresponse);
          }
        }

        $a->control = choose_from_menu($answers, $menuname, $response, 'choose',
                                       '', 0, true, $options->readonly);
        $anss[] = $a;
      }
    }

  }else if($questionType == 'multianswer'){

  }else if($questionType == 'multichoice'){
  
    $answers = &$question->options->answers;
    $correctanswers = $QTYPES['multichoicewiris']->get_correct_responses($question, $state);
    $readonly = empty($options->readonly) ? '' : 'disabled="disabled"';
    $answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') :
                    get_string('multipleanswers', 'quiz');
    // Print each answer in a separate row
    foreach ($state->options->order as $key => $aid) {
      $answer = &$answers[$aid];
      $checked = '';
      $chosen = false;

      if ($question->options->single) {
        $type = 'type="radio"';
        $name   = "name=\"{$question->name_prefix}\"";
        if (isset($state->responses['']) and $aid == $state->responses['']) {
          $checked = 'checked="checked"';
          $chosen = true;
        }
      } else {
        $type = ' type="checkbox" ';
        $name   = "name=\"{$question->name_prefix}{$aid}\"";
        if (isset($state->responses[$aid])) {
          $checked = 'checked="checked"';
          $chosen = true;
        }
      }

      $a = new stdClass;
      $a->id   = $question->name_prefix . $aid;
      $a->class = '';
      $a->feedbackimg = '';

      // Print the control
      $a->control = "<input $readonly id=\"$a->id\" $name $checked $type value=\"$aid\" />";

      if ($options->correct_responses && $answer->fraction > 0) {
        $a->class = question_get_feedback_class(1);
      }
      if (($options->feedback && $chosen) || $options->correct_responses) {
        if ($type == ' type="checkbox" ') {
          $a->feedbackimg = question_get_feedback_image($answer->fraction > 0 ? 1 : 0, $chosen && $options->feedback);
        } else {
          $a->feedbackimg = question_get_feedback_image($answer->fraction, $chosen && $options->feedback);
        }
      }

      // Print the answer text
      $a->text = $QTYPES['multichoicewiris']->number_in_style($key, $question->options->answernumbering) .
                 format_text($answer->answer, FORMAT_MOODLE, $formatoptions, $cmoptions->course);

      // Print feedback if feedback is on
      if (($options->feedback || $options->correct_responses) && $checked) {
        $a->feedback = format_text($answer->feedback, true, $formatoptions, $cmoptions->course);
      } else {
        $a->feedback = '';
      }

      $anss[] = clone($a);
    }

    $feedback = '';
      if ($options->feedback) {
        if ($state->raw_grade >= $question->maxgrade/1.01) {
          $feedback = $question->options->correctfeedback;
        } else if ($state->raw_grade > 0) {
          $feedback = $question->options->partiallycorrectfeedback;
        } else {
          $feedback = $question->options->incorrectfeedback;
        }
        $feedback = format_text($feedback, $question->questiontextformat,
                    $formatoptions, $cmoptions->course);
        }

  

  }else if($questionType == 'shortanswer'){
    $value = '';
    $readonly = (empty($options->readonly)) ? '' : 'readonly="readonly"';
    $feedback = '';
		$class = '';
		$feedbackimg = '';

    if (isset($state->responses['']) && $state->responses[''] != '') {
      $value = s($state->responses[''], true);
    }
    mb_parse_str($question->options->wiris->eqoption, $eqoptionArray);
		$wirisEditorEnabled = (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true');
		if($wirisCASForComputationsEnabled && $wirisEditorEnabled){
      //copy button
      $wirisCASApplet .= '<input id="'.$inputname.'copy_button" name="'.$inputname.'copy_button" type="button" '.
                         'value="'.wrsqz_get_string('wrsqz_copyresponse')
                         .'" onclick="copyCASSessionToEditor('.$question->id.',\''.$inputname.'\')"/>';
      require_js('yui_connection');
    }
    //$wirisCASForComputationsEnabled = (isset($eqoptionArray['wirisCASForComputations']) && $eqoptionArray['wirisCASForComputations'] == 'true');
		$multipleAnswers = (isset($eqoptionArray['multipleAnswers']) && $eqoptionArray['multipleAnswers'] == 'true');

		if ($multipleAnswers) {
			$formulaGrammar = 'http://' . $CFG->wirisservicehost . ':' . $CFG->wirisserviceport . $CFG->wirisservicepath . '/test/grammars/grammar-assign.txt';
			$formulaGrammarTarget = 'math2';
		}else {
			$formulaGrammar = 'http://' . $CFG->wirisservicehost . ':' . $CFG->wirisserviceport . $CFG->wirisservicepath . '/test/grammars/grammar.txt';
			$formulaGrammarTarget = 'math';
		}
    $wirisEditorApplet = wrsqz_wirisEditorAppletHTML($inputname, $formulaGrammar, $formulaGrammarTarget, $value);
    require_js(array('yui_yahoo', 'yui_dom-event'));
    require_js(array($CFG->wwwroot.'/wiris-quizzes/js/wiris-quizzes.js', $CFG->wwwroot.'/wiris-quizzes/js/constants.js.php'));
    
    // Chose feedback according to current response
		if ($options->feedback) {
			$class = question_get_feedback_class(0);
			$feedbackimg = question_get_feedback_image(0);
			$i = 0;

			foreach ($question->options->answers as $answer) {
				if (wrsqz_testResponse($question, $state, $answer) || (!empty($state->grades) && $state->grades[$i] > 0.0)) {
					$class = question_get_feedback_class($answer->fraction);
					$feedbackimg = question_get_feedback_image($answer->fraction);

					if ($answer->feedback) {
						$feedback = format_text($answer->feedback, true, $formatoptions, $cmoptions->course);
					}
					break;
				}
				++$i;
			}
		}
  }else if($questionType == 'truefalse'){
    $readonly = $options->readonly ? ' disabled="disabled"' : '';
    $answers = &$question->options->answers;
    $trueanswer = &$answers[$question->options->trueanswer];
    $falseanswer = &$answers[$question->options->falseanswer];
    $correctanswer = ($trueanswer->fraction == 1) ? $trueanswer : $falseanswer;

    $trueclass = '';
    $falseclass = '';
    $truefeedbackimg = '';
    $falsefeedbackimg = '';

    // Work out which radio button to select (if any)
    if (isset($state->responses[''])) {
      $response = $state->responses[''];
    } else {
      $response = '';
    }
    $truechecked = ($response == $trueanswer->id) ? ' checked="checked"' : '';
    $falsechecked = ($response == $falseanswer->id) ? ' checked="checked"' : '';

    // Work out visual feedback for answer correctness.
    if ($options->feedback) {
      if ($truechecked) {
         $trueclass = question_get_feedback_class($trueanswer->fraction);
      } else if ($falsechecked) {
         $falseclass = question_get_feedback_class($falseanswer->fraction);
      }
    }
    if ($options->feedback || $options->correct_responses) {
      if (isset($answers[$response])) {
        $truefeedbackimg = question_get_feedback_image($trueanswer->fraction, !empty($truechecked) && $options->feedback);
        $falsefeedbackimg = question_get_feedback_image($falseanswer->fraction, !empty($falsechecked) && $options->feedback);
      }
    }

    $inputname = ' name="'.$question->name_prefix.'" ';
    $trueid    = $question->name_prefix.'true';
    $falseid   = $question->name_prefix.'false';

    $radiotrue = '<input type="radio"' . $truechecked . $readonly . $inputname
      . 'id="'.$trueid . '" value="' . $trueanswer->id . '" /><label for="'.$trueid . '">'
      . s($trueanswer->answer) . '</label>';
    $radiofalse = '<input type="radio"' . $falsechecked . $readonly . $inputname
      . 'id="'.$falseid . '" value="' . $falseanswer->id . '" /><label for="'.$falseid . '">'
      . s($falseanswer->answer) . '</label>';

    $feedback = '';
    if ($options->feedback and isset($answers[$response])) {
      //choose feedback depending on correctness of response
      if($answers[$response]->fraction == 1){
        $feedback = format_text($trueanswer->feedback, true, $formatoptions, $cmoptions->course);
      }else{
        $feedback = format_text($falseanswer->feedback, true, $formatoptions, $cmoptions->course);
      }
    }
  }
  //print body
  include("$CFG->dirroot/question/type/$question->qtype/display.html");

  //print buttons
  $QTYPES[$question->qtype]->print_question_submit_buttons($question, $state, $cmoptions, $options);
  echo '</div>'; //close <div class="block clearfix">
  if($questionType == 'essay' && empty($options->readonly) && !empty($usehtmleditor)){
    use_html_editor($inputname);
    $htmleditorused = true;
  }else if($questionType == 'truefalse'){
    echo '</div>'; //close <div class = "truefalse"/>
  }
}