📄 scorm_classes.php
字号:
/** * Export the question part as a matrix-choice, with only one possible answer per line. * @author Amand Tihon <amand@alrj.org> */ function export() { $js = ''; $html = '<tr><td colspan="2"><table width="100%">' . "\n"; // prepare list of right proposition to allow // - easiest display // - easiest randomisation if needed one day // (here I use array_values to change array keys from $code1 $code2 ... to 0 1 ...) $displayedRightList = array_values($this->rightList); // get max length of displayed array $arrayLength = max( count($this->leftList), count($this->rightList) ); $nbrAnswers=$this->selectNbrAnswers(); $cpt1='A'; $cpt2=1; $Select=array(); $qId = $this->questionJSId; $s = ''; $jstmp = ''; $jstmpc = ''; $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; for($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $identifier = 'question_'.$qId.'_matching_'; $answer=$this->selectAnswer($answerId); $answerCorrect=$this->isCorrect($answerId); $weight=$this->selectWeighting($answerId); $jstmp .= $answerId.','; if(!$answerCorrect) { // options (A, B, C, ...) that will be put into the list-box $Select[$answerId]['Lettre']=$cpt1; // answers that will be shown at the right side $answer = api_parse_tex($answer); $Select[$answerId]['Reponse']=$answer; $cpt1++; } else { $s.='<tr>'."\n"; $s.='<td width="40%" valign="top">'."\n".'<b>'.$cpt2.'</b>. '.$answer."\n</td>\n"; $s.='<td width="20%" align="center"> <select name="'.$identifier.$cpt2.'" id="'.$identifier.$cpt2.'">'; $s.=' <option value="0">--</option>'; // fills the list-box foreach($Select as $key=>$val) { $s.='<option value="'.$key.'">'.$val['Lettre'].'</option>'; } // end foreach() $s.='</select> </td>'."\n"; $s.='<td width="40%" valign="top">'; if(isset($Select[$cpt2])) $s.='<b>'.$Select[$cpt2]['Lettre'].'.</b> '.$Select[$cpt2]['Reponse']; else $s.=' '; $s.="</td>\n</tr>\n"; $jstmpc .= '['.$answerCorrect.','.$cpt2.'],'; $jstmpw .= 'questions_answers_ponderation['.$qId.']['.$cpt2.'] = '.$weight.";\n"; $cpt2++; // if the left side of the "matching" has been completely shown if($answerId == $nbrAnswers) { // if there remain answers to be shown on the right side while(isset($Select[$cpt2])) { //$s.='<tr>'."\n"; //$s.='<td colspan="2">'."\n"; //$s.='<table border="0" cellpadding="0" cellspacing="0" width="100%">'."\n"; $s.='<tr>'."\n"; $s.='<td width="60%" colspan="2"> </td>'."\n"; $s.='<td width="40%" valign="top">'; $s.='<b>'.$Select[$cpt2]['Lettre'].'.</b> '.$Select[$cpt2]['Reponse']; $s.="</td>\n</tr>\n"; $cpt2++; } // end while() } // end if() } } $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp,0,-1).');'."\n"; $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.substr($jstmpc,0,-1).');'."\n"; $js .= 'questions_types['.$this->questionJSId.'] = \'matching\';'."\n"; $js .= $jstmpw; $html .= $s; $html .= '</table></td></tr>' . "\n"; return array($js,$html); }}/** * This class handles the SCORM export of free-answer questions */class ScormAnswerFree extends Answer { /** * Export the text with missing words. * * As a side effect, it stores two lists in the class : * the missing words and their respective weightings. * */ function export() { $qId = $this->questionJSId; $js = ''; $html = '<tr><td colspan="2"><table width="100%">' . "\n"; // some javascript must be added for that kind of questions $html .= '<tr>' . "\n" . '<td>' . "\n" . '<textarea name="question_'.$qId.'_free" id="question_'.$qId.'_free" rows="20" cols="100"></textarea>' . "\n" . '</td>' . "\n" . '</tr>' . "\n"; $html .= '</table></td></tr>' . "\n"; // currently the free answers cannot be displayed, so ignore the textarea $html = '<tr><td colspan="2">'.get_lang('ThisItemIsNotExportable').'</td></tr>'; $js .= 'questions_answers['.$this->questionJSId.'] = new Array();'."\n"; $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array();'."\n"; $js .= 'questions_types['.$this->questionJSId.'] = \'free\';'."\n"; $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = 0'.";\n"; $js .= $jstmpw; return array($js,$html); }}/** * This class handles the SCORM export of hotpot questions */class ScormAnswerHotspot extends Answer { /** * Returns the javascript code that goes with HotSpot exercises * @return string The JavaScript code */ function get_js_header() { if($this->standalone) { $header = '<script type="text/javascript" language="javascript">'; $header .= file_get_contents('../plugin/hotspot/JavaScriptFlashGateway.js'); $header .= '</script>'; $header .= '<script type="text/javascript" language="javascript">'; $header .= file_get_contents('../plugin/hotspot/hotspot.js'); $header .= '</script>'; $header .= '<script language="javascript" type="text/javascript">'. "<!-- // ----------------------------------------------------------------------------- // Globals // Major version of Flash required var requiredMajorVersion = 7; // Minor version of Flash required var requiredMinorVersion = 0; // Minor version of Flash required var requiredRevision = 0; // the version of javascript supported var jsVersion = 1.0; // ----------------------------------------------------------------------------- // --> </script> <script language=\"VBScript\" type=\"text/vbscript\"> <!-- // Visual basic helper required to detect Flash Player ActiveX control version information Function VBGetSwfVer(i) on error resume next Dim swControl, swVersion swVersion = 0 set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i)) if (IsObject(swControl)) then swVersion = swControl.GetVariable(\"\$version\") end if VBGetSwfVer = swVersion End Function // --> </script> <script language=\"JavaScript1.1\" type=\"text/javascript\"> <!-- // Detect Client Browser type var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false; var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false; jsVersion = 1.1; // JavaScript helper required to detect Flash Player PlugIn version information function JSGetSwfVer(i){ // NS/Opera version >= 3 check for Flash plugin in plugin array if (navigator.plugins != null && navigator.plugins.length > 0) { if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) { var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\"; var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description; descArray = flashDescription.split(\" \"); tempArrayMajor = descArray[2].split(\".\"); versionMajor = tempArrayMajor[0]; versionMinor = tempArrayMajor[1]; if ( descArray[3] != \"\" ) { tempArrayMinor = descArray[3].split(\"r\"); } else { tempArrayMinor = descArray[4].split(\"r\"); } versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision; } else { flashVer = -1; } } // MSN/WebTV 2.6 supports Flash 4 else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4; // WebTV 2.5 supports Flash 3 else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3; // older WebTV supports Flash 2 else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2; // Can't detect in all other cases else { flashVer = -1; } return flashVer; } // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) { reqVer = parseFloat(reqMajorVer + \".\" + reqRevision); // loop backwards through the versions until we find the newest version for (i=25;i>0;i--) { if (isIE && isWin && !isOpera) { versionStr = VBGetSwfVer(i); } else { versionStr = JSGetSwfVer(i); } if (versionStr == -1 ) { return false; } else if (versionStr != 0) { if(isIE && isWin && !isOpera) { tempArray = versionStr.split(\" \"); tempString = tempArray[1]; versionArray = tempString .split(\",\"); } else { versionArray = versionStr.split(\".\"); } versionMajor = versionArray[0]; versionMinor = versionArray[1]; versionRevision = versionArray[2]; versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24 versionNum = parseFloat(versionString); // is the major.revision >= requested major.revision AND the minor version >= requested minor if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) { return true; } else { return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false ); } } } } // --> </script>"; //because this header closes so many times the <script> tag, we have to reopen our own $header .= '<script type="text/javascript" language="javascript">'."\n"; $header .= 'questions_answers['.$this->questionJSId.'] = new Array();'."\n"; $header .= 'questions_answers_correct['.$this->questionJSId.'] = new Array();'."\n"; $header .= 'questions_types['.$this->questionJSId.'] = \'hotspot\';'."\n"; $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = 0'.";\n"; $header .= $jstmpw; } else { $header = ''; $header .= 'questions_answers['.$this->questionJSId.'] = new Array();'."\n"; $header .= 'questions_answers_correct['.$this->questionJSId.'] = new Array();'."\n"; $header .= 'questions_types['.$this->questionJSId.'] = \'hotspot\';'."\n"; $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = 0;'."\n"; $header .= $jstmpw; } return $header; } /** * Export the text with missing words. * * As a side effect, it stores two lists in the class : * the missing words and their respective weightings. * */ function export() { $js = $this->get_js_header(); $html = '<tr><td colspan="2"><table width="100%">' . "\n"; // some javascript must be added for that kind of questions $html .= ''; // Get the answers, make a list $nbrAnswers=$this->selectNbrAnswers(); $answer_list = '<div style="padding: 10px; margin-left: -8px; border: 1px solid #4271b5; height: 448px; width: 200px;"><b>'.get_lang('HotspotZones').'</b><ol>'; for($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $answer_list .= '<li>'.$this->selectAnswer($answerId).'</li>'; } $answer_list .= '</ol></div>'; /* if(!$onlyAnswers) { $s="<tr> <td valign='top' colspan='2'> "; $questionName=api_parse_tex($questionName); $s.=$questionName; $s.="</td> </tr> <tr> <td valign='top' colspan='2'> <i>"; $questionDescription=api_parse_tex($questionDescription); $s.=$questionDescription; $s.="</i> </td> </tr>"; } */ //$canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); $canClick = true; //$tes = isset($_GET['modifyAnswers']) ? '0' : '1'; //echo $tes; $html .= '<tr><td>'." <script language=\"JavaScript\" type=\"text/javascript\"> <!-- // Version check based upon the values entered above in \"Globals\" var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); // Check to see if the version meets the requirements for playback if (hasReqestedVersion) { // if we've detected an acceptable version var oeTags = '<object type=\"application/x-shockwave-flash\"".' data="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_user.swf?modifyAnswers='.$this->questionJSId."&canClick:".$canClick."\" width=\"380\" height=\"470\">' + '<param name=\"movie\"".' value="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_user.swf?modifyAnswers='.$this->questionJSId."&canClick:".$canClick."\" \/>' + '<\/object>'; document.write(oeTags); // embed the Flash Content SWF when all tests are passed } else { // flash is too old or we can't detect the plugin var alternateContent = 'Error<br \/>' + 'Hotspots requires Macromedia Flash 7.<br \/>' + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>'; document.write(alternateContent); // insert non-flash content } // --> </script></td> <td valign='top'>$answer_list</td></tr>"; $html .= '</table></td></tr>' . "\n"; // currently the free answers cannot be displayed, so ignore the textarea $html = '<tr><td colspan="2">'.get_lang('ThisItemIsNotExportable').'</td></tr>'; return array($js,$html); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -