Hi everybody,
I don't know if it is the right place for what I want to say but we'll see.
I run a couple of copies of Moodle for various companies and one client came up with the request to use the quiz activity for testing language skills including listening comprehension. The point is that they want to use the secure quiz window with a programmable mp3 player that enables them to control how many times an audio files can be played during a quiz session.
I looked up the Moodle site for some ideas but it was not too much help so I've programmed my own hack to satisfy them.
How it works: when the question with the audio is edited and the link to the mp3 file has been made change the editor into HTML mode. Look for the
<a href="....myaudiofile.mp3">link here </a> remove the link ("link here") and simply write the number of the required replays behind the .mp3 like this : <a href="....myaudiofile.mp32"></a>.
In this case the player will play the file twice. The integer behind the mp3 can be anything between 1 and 9.
------------------------------------------------------
The required modifications:
- to modify the mp3 player so that it can accept control values
- to modify the mp3 filter to send the control value to the mp3 player
- to remove the "Save without submitting " button from the bottom of the quiz in secure mode
- to disable the F function buttons and the Ctrl+N és Ctrl+R combinations while in secure mode
Used Moodle version: 1.9
Tested on IE 7 and Firefox 3. (Not a thorough test but it worked so far.)
STEP 1.
Used file : \moodle\filter\mediaplugin\mp3player.fla
New variable: playnr (integer 1...9) The audio file can be played "playnr" times.
Code:
if (playnr>0) {
playnr = playnr - 1
if (playnr<0) {
playnr=0
}
if (playnr==0) {
playBtn.enabled = false;
}
pauseBtn.enabled = false;
slider.handle.enabled=false;
}
Effect: The Pause button and the Slider are disabled at the first Play buton press and when the number of replays reaches "playnr" the Play button is also disabled.
STEP 2.
Used file: \moodle\filter\mediaplugin\filter.php
New variable: playnr
Code:
1. Modified regexp for the mp3 filter (separating the playnr from the end of the mp3 extension):
if ($CFG->filter_mediaplugin_enable_swf) {
$search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);
2. Modified var FO = for the mp3 filter (playnr is sent to the player)
var FO = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/mp3player.swf?src='.$url.'",
width:"90", height:"15", majorversion:"6", build:"40", flashvars:"'.$c.'&playnr='.$link[3].'", quality: "high"};
STEP 3.
Used file: \moodle\mod\quiz\attempt.php
Code:
1. In the Print the submit buttons section:
if (!$quiz->popup) {
echo "<input type=\"submit\" name=\"saveattempt\" value=\"".get_string("savenosubmit", "quiz")."\" />\n";
}
Effect: The "Save without submitting " is not printed if the secure window option is selected during the quiz setting
STEP 4.
Used file: \moodle\mod\quiz\protect_js.php
Code:
//Source website:
//http://www.gklein.org/tests/js/disablekey.js
//http://www.gklein.org/tests/js/disablekey.html
//http://www.gklein.org
setEventListener(disableKey);
function setEventListener(eventListener) {
if (document.addEventListener) document.addEventListener('keypress', eventListener, true);
if (!document.getElementById) return;
}
function disableKey(event) {
if (!event) event = window.event;
if (!event) return;
var keyCode = event.keyCode ? event.keyCode : event.charCode;
// keyCode for F% on Opera is 57349 ?!
if (keyCode >= 110 && keyCode <= 123) {
// Standard DOM (Mozilla):
if (event.preventDefault) event.preventDefault();
return false;
}
}I
//Source website
//http://forums.devarticles.com/javascript-development-22/disable-new-window-opening-7531.html
document.Xonkeydown= function(){
if ((((event.keyCode == 78)||(event.keyCode == 82)) && (event.ctrlKey)) || (((event.keyCode >= 110)&&(event.keyCode <= 123)))){
event.cancelBubble = true;
event.returnValue = false;
event.keyCode = false;
return false;
}
}
Effect: when in secure window the F function buttons and the Ctrl+N és Ctrl+R combinations are disabled.
Notes:
- although I program desktop applications routinely I don't have any experience in web programming. I fully understand Step1-3 but the 4. one is a mess for me. I looked up some code snipets on the net, modified them so I have to admit it is not a piece of diamond but it works)
I would be very happy if somebody could clean up this last code segment. - Of course the secure window is not secure enough but it is a little bit better than the original one.
- I think the keyboard should be restricted for examinations on the OS level. It can be done easyly with a key mapper before launching the browser for the exam. I tried a very simple one, found it in five minutes.(Key Remapper 1.03 http://www.softarium.com/) Everything can be disabled in a second including the Window keys, Alt+Tab ... using a GUI.
