function create_session_and_responses(&$question, &$state, $cmoptions, $attempt)
 {
     parent::create_session_and_responses($question, $state, $cmoptions, $attempt);
     return wrsqz_create_session_and_responses('match', 'wmatprom', $question, $state, $cmoptions, $attempt);
 }
function wrsqz_print_question($questionType, $dbType, &$question, &$state, &$number, &$cmoptions, &$options) {
	if(empty($state->vars)){
		//this is needed because when a teacher previews a quiz, moodle doesn't call create_session_and_responses.
		wrsqz_create_session_and_responses($questionType, $dbType, $question, $state, $cmoptions, null);
	}
	$question->questiontext = wrsqz_assemble($question->questiontext, $state->vars); 
	$question->generalfeedback = wrsqz_assemble($question->generalfeedback, $state->vars); 

	if ($questionType == 'match') {
		foreach ($question->options->subquestions as $key => $subquestion) {
			$question->options->subquestions[$key]->questiontext = wrsqz_assemble($subquestion->questiontext, $state->vars);
			$question->options->subquestions[$key]->answertext = wrsqz_assemble(wrsqz_variablesToText($subquestion->answertext), $state->vars);
		}

		foreach ($state->options->subquestions as $key => $subquestion) {
			$state->options->subquestions[$key]->questiontext = wrsqz_assemble($subquestion->questiontext,$state->vars);
			$state->options->subquestions[$key]->answertext = wrsqz_assemble(wrsqz_variablesToText($subquestion->answertext), $state->vars);
			
			foreach ($state->options->subquestions[$key]->options->answers as $secondKey => $answer) {
				$state->options->subquestions[$key]->options->answers[$secondKey]->answer = wrsqz_assemble(wrsqz_variablesToText($answer->answer), $state->vars);
			}
		}
	}
	else if ($questionType == 'multichoice') {
		$question->options->correctfeedback = wrsqz_assemble($question->options->correctfeedback, $state->vars); 
		$question->options->partiallycorrectfeedback = wrsqz_assemble($question->options->partiallycorrectfeedback, $state->vars); 
		$question->options->incorrectfeedback = wrsqz_assemble($question->options->incorrectfeedback, $state->vars); 

        //this is for multichoice questions embedded in a multianswer question
        if(!empty($question->parent) && isset($question->options->layout) && ($question->options->layout==0)){
            foreach ($question->options->answers as $key => $answer) {
                $question->options->answers[$key]->answer = wrsqz_variablesToText($answer->answer);
            }
        }

		foreach ($question->options->answers as $key => $answer) {
			$question->options->answers[$key]->answer = wrsqz_assemble($answer->answer, $state->vars);
			$question->options->answers[$key]->feedback = wrsqz_assemble($answer->feedback, $state->vars);
		}
	}
	else if ($questionType == 'shortanswer') {
		foreach ($question->options->answers as $key => $answer) {
			// TODO. Remove wrsqz_variablesToText
			//$question->options->answers[$key]->answer = wrsqz_assemble($answer->answer, $state->vars);
			$question->options->answers[$key]->feedback = wrsqz_assemble($answer->feedback, $state->vars);
		}
	}
	else if ($questionType == 'truefalse') {
		foreach ($question->options->answers as $key => $answer) {
			$question->options->answers[$key]->answer = wrsqz_assemble($answer->answer, $state->vars);
			$question->options->answers[$key]->feedback = wrsqz_assemble($answer->feedback, $state->vars);
		}
	}else if ($questionType == 'multianswer'){
        foreach ($question->options->questions as $key=>$wrapped) {
            if(substr($wrapped->qtype,-5)=='wiris'){
                wrsqz_print_question(substr($wrapped->qtype,0,-5), $dbType , $wrapped, $state, $number, $cmoptions, $options);
                $question->options->questions[$key]=$wrapped;
            }
        }
    }
}
	function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
		parent::create_session_and_responses($question, $state, $cmoptions, $attempt);
		return wrsqz_create_session_and_responses('truefalse', 'wtrflsprom', $question, $state, $cmoptions, $attempt);
	}
 function create_session_and_responses(&$question, &$state, $cmoptions, $attempt)
 {
     parent::create_session_and_responses($question, $state, $cmoptions, $attempt);
     return wrsqz_create_session_and_responses('shortanswer', 'wshanprom', $question, $state, $cmoptions, $attempt);
 }