/** @param $prefix String a name prefix. Usually $question->name_prefix. It is used in order to distinguish between applets. @param $wirisCASContent String the MathML content of WIRIS CAS. @param $printString if true, prints a string telling user that can do auxiliar computations. @return an html with a tag <applet> that includes the WIRS CAS applet. **/ function wrsqz_wirisCASAppletHTML($prefix, $wirisCASContent='', $printString = TRUE, $width = 500, $height = 265){ global $CFG; $casLang = empty($wirisCASContent) ? wrsqz_currentCASLanguage() : wrsqz_CASLanguageFromSession($wirisCASContent); $html = '<div class="wirisCASApplet">'; if($printString){ $html .= wrsqz_get_string('wrsqz_candocomputations')."\n"; $html .= '<br />'."\n"; } $html .= '<applet'."\n"; $html .= 'id="'.$prefix.'wirisCAS"'."\n"; $html .= 'width="'.$width.'" height="'.$height.'"'."\n"; $html .= 'name="'.$prefix.'wirisCAS"'."\n"; $html .= 'codebase="'.$CFG->wiriscascodebase.'"'."\n"; $html .= 'archive="'.wrsqz_getCASArchive($casLang).'"'."\n"; $html .= 'code="'.wrsqz_getCASClass($casLang).'"'."\n"; $html .= '>'."\n"; if($wirisCASContent){ $html .= '<param name="command" value="false" />'."\n"; $html .= '<param name="commands" value="false" />'."\n"; $html .= '<param name="interface" value="false" />'."\n"; $html .= '<param name="XMLinitialText" value="'.$wirisCASContent.'" />'."\n"; } $html .= '</applet>'; $html .= '<input type="hidden" id="'.$prefix.'wirisCASHidden" name="'.$prefix.'wirisCASHidden" value=""/>'; $html .= '</div>'."\n"; return $html; }
function wrsqz_set_data($questionType, $dbType, &$mform, &$question) { $default_values = array(); //common options if(isset($question->options->wiris->options)){ $options = $question->options->wiris->options; if(isset($options['wirisCASForComputations'])){ $default_values['wirisCASForComputations'] = $options['wirisCASForComputations']; } if(isset($options['hiddenInitialCASValue'])){ $default_values['hiddenInitialCASValue'] = $options['hiddenInitialCASValue']; } } //question-type specific options if ($questionType == 'shortanswer' && isset($question) && isset($question->options) && isset($question->options->wiris) && isset($question->options->wiris->eqoption)) { $default_values['wirisEditor'] = ''; mb_parse_str($question->options->wiris->eqoption, $eqoptionArray); if (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true') { $default_values['wirisEditor'] = '1'; } if (isset($eqoptionArray['multipleAnswers']) && $eqoptionArray['multipleAnswers'] == 'true') { $default_values['multipleAnswers'] = '1'; } /*if (isset($eqoptionArray['wirisCASForComputations']) && $eqoptionArray['wirisCASForComputations'] == 'true') { $default_values['wirisCASForComputations'] = '1'; }*/ if (isset($eqoptionArray['testFunction'])){ //set testFunctionNames where their associated answers are $index = 0; foreach ($question->options->answers as $answer){ if (isset($eqoptionArray['testFunction'][$answer->id])){ $testFunctionNameIndex = $eqoptionArray['testFunction'][$answer->id]; $default_values['testFunctionName['.$index.']'] = $eqoptionArray['testFunctionName'][$testFunctionNameIndex]; unset($eqoptionArray['testFunctionName'][$testFunctionNameIndex]); } $index++; } //set test functions with no associated answer. foreach($eqoptionArray['testFunctionName'] as $key => $value){ $default_values['testFunctionName['.$index.']'] = $value; $index++; } }else if (isset($eqoptionArray['testFunctionName'])){ //Backwards compatibility for old WIRIS quizzes (didn't have testFunction attribute). foreach ($eqoptionArray['testFunctionName'] as $index => $value){ $default_values['testFunctionName['.$index.']'] = $eqoptionArray['testFunctionName'][$index]; } } }else if($questionType == 'multianswer' && isset($question) && isset($question->options) && isset($question->options->wiris) && isset($question->options->wiris->eqoption)){ mb_parse_str($question->options->wiris->eqoption, $eqoptionArray); if (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true') { $default_values['wirisEditor'] = '1'; } else { $default_values['wirisEditor'] = ''; } } if (isset($question) && isset($question->options) && isset($question->options->wiris) && !empty($question->options->wiris->override)) { if ($questionType == 'multichoice') { $overrideList = explode(';', $question->options->wiris->override); foreach ($overrideList as $key => $value) { $default_values['gradeOverride[' . $key . ']'] = $value; } }else if ($questionType == 'truefalse') { $overrideList = explode(';', $question->options->wiris->override); $default_values['wirisAnswer'] = $overrideList[0]; } } global $CFG; $pos = ($mform->_elementIndex['hiddenCASValue']); $value = trim($mform->_elements[$pos]->_attributes['value']); $selectedLang = optional_param('WIRISCASLang','',PARAM_ALPHA); $availableLangs = wrsqz_getAvailableCASLangs(); if (!empty($value)) { $program = $value; $sessionLang = wrsqz_CASLanguageFromSession($program); if(in_array($selectedLang, $availableLangs) && $selectedLang != $sessionLang){ //We have to translate the WIRIS session $translation = wrsqz_translateCASSession($program,$selectedLang); if($translation !==false){ $program = $translation[0]; $CASLang = $selectedLang; //Rearrange all form fields with the new named variables (at the end of the function). }else{ //We couldn't translate the program. Do nothing $CASLang = $sessionLang; } }else{ $CASLang = $sessionLang; } }else{ if (isset($question) && isset($question->id) && ($program = wrsqz_getProgram($questionType, $question->id)) !== false && !empty($program)) { $CASLang = wrsqz_CASLanguageFromSession($program); }else { $CASLang = wrsqz_currentCASLanguage(); $program = wrsqz_getDefaultCASCode($CASLang); } } $default_values['htmlWirisEditor'] = '<applet name="WirisCASApplet" code="' . wrsqz_getCASClass($CASLang) . '" codebase="' . $CFG->wiriscascodebase . '" archive="' . wrsqz_getCASArchive($CASLang) . '" height="450" WIDTH="100%">'; $default_values['htmlWirisEditor'] .= '<param name="version" value="2.0"/>'; $default_values['htmlWirisEditor'] .= '<param name="command" value="false"/>'; $default_values['htmlWirisEditor'] .= '<param name="commands" value="false"/>'; $default_values['htmlWirisEditor'] .= '<param name="interface" value="false"/>'; $default_values['htmlWirisEditor'] .= '<param name="XMLinitialText" value="' . htmlentities($program, ENT_QUOTES, 'UTF-8') . '"/>'; $default_values['htmlWirisEditor'] .= '</applet>'; $default_values['WIRISCASLang'] = $CASLang; // defined only because we call wrsqz_wirisQuizzesUsed $default_values['hiddenCASValue'] = $program; $question = (object)(array_merge((array)$question, $default_values)); if(isset($translation) && ! empty($translation[1])){ //If WIRIS CAS program had to be translated, there may be references (#a) to //old variable names, so replace them. wrsqz_replaceVarReferencesInFlatQuestion($questionType, $question, $translation[1]); wrsqz_replaceVarReferencesInForm($questionType, $mform, $translation[1]); } // If uses wiris quizzes, display advanced otherwise the program // is lost if the advanced button is never clicked if (wrsqz_wirisQuizzesUsed($question)) { $mform->setShowAdvanced(1); } }