Adding protection to MOODLE quizzes---

Adding protection to MOODLE quizzes---

by Rob Butner -
Number of replies: 15
We wanted to disable the following student functions: right click, copy and paste the page, print or view source etc. To achieve this we deactivated the mouse right button and the keyboard right click button.

But the same thing can be achieved with the help of the menu bar. We had to deactivate Alt key to restrict the user from accessing menu items.

After doing this there is one more possibility from where the user can directly take the stuff from the quiz. Just use Ctrl + A to select the whole page and directly Ctrl + C, Ctrl + V to copy and paste respectively. This option must also be disabled.

One more issue to take care is browser compatibility. It should work in Microsoft Internet Explorer and in Netscape Navigator.

Here's the code:

var isnn,isie
if(navigator.appName=='Microsoft Internet Explorer') //check the browser
{  isie=true }

if(navigator.appName=='Netscape')
{  isnn=true }

function right(e) //to trap right click button 
{
	if (isnn && (e.which == 3 || e.which == 2 ))
		return false;
	else if (isie && (event.button == 2 || event.button == 3)) 
	{
		alert("Sorry, you do not have permission to right click on this page.");
		return false;
	}
		return true;
}

function key(k)   
{
	if(isie) {
		if(event.keyCode==17 || event.keyCode==18 || event.keyCode==93) {
			alert("Sorry, you do not have permission to press this key.") 
			return false;
		 } 
	}

	if(isnn){
		alert("Sorry, you do not have permission to press this key.") 
		return false; }   
}

if (document.layers) window.captureEvents(Event.KEYPRESS);  
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
documentxxxkey;  
documentxxxright;
documentxxxright;
window.document.layers=right;

Put this code in a file called security.js and reference it between the <HEAD> and </HEAD> tags of your MOODLE theme header.html page using: <Scriptxxx"JavaScript" src="security.js"></script>

Hope this helps---Rob

Average of ratings: -
In reply to Rob Butner

Re: Adding protection to MOODLE quizzes---

by Przemyslaw Stencel -
If I were a student, I would take screenshot images of the quiz using a graphics program. wink
In reply to Przemyslaw Stencel

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -

The vast majority of our students use the University computers and it is impossible to install new software, such as screen captures programs on them. Admittedly though, some students will go to this sort of trouble.
Tim

Timothy Takemoto

In reply to Rob Butner

Re: Adding protection to MOODLE quizzes---

by Vijay Kumar Adhikari -
By the way, what does the following mean?


documentxxxkey;
documentxxxright;
documentxxxright;


In reply to Rob Butner

Re: Adding protection to MOODLE quizzes---

by Matthew Byars -

Hello All:

Does anyone know of any way to password-protect, or otherwise restrict access to quizzes aside from date restriction or "number of attempts" restriction?  I'm going to have multiple students from multiple locations taking my course at different paces, and some will need access to the tests before others...my concern is that the students not ready for the tests will see that the tests are open and use that opportunity to preview them.  Any ideas?

Thanks,

Matthew Byars

In reply to Matthew Byars

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -

John Bristor managed it but he was too busy, got sick, or was not met with enough interest in time to post it here at "Using Moodle." If you manage to find him on the net then perhaps you will be able to persuade him to post his wonderful hack here. It was the answer to all my dreams.

Timothy Takemoto 

In reply to Timothy Takemoto

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -

I implemented the anti-copying function supplied by Rob Butner and Indjana Dzons. Thank you both very much.

The instructions are alread available but I have made some very minor changes.

1) Insert

<?php include("common.php") ?>

Into header.php in your theme. I put it at the second to last line before the <!-- END OF HEADER --> because that enables me to put a warning at the top of the quiz (see 4 below)

2) create a file common.php in your theme folder (Indjana Dzons had it somewhere else but I think it is helpful to have it inside the theme folder since that is the one folder that one copies accross when updating Moodle.)

<?php
if (stristr($_SERVER['SCRIPT_FILENAME']."X", "attempt.phpX")) {
  include("blockit.html"); }
  ?>

One could add other pages (other than attempt.php) to the above if one wants to prevent students from copying other files but since the above prevents both the quiz attempt screen and the feedback screen, which is also created by attempt.php, it is enough for me.

3) Create a file blockit.html in your theme folder. Include the super-java script blocker supplied by Rob Butner here

I just used the code between <SCRIPT Xlanguage="JavaScript"><!-- and the last </SCRIPT>
This is an encoded javascript so I guess it makes it more difficult to beat. It prevents students from copying by interfering drastically with the clipboard and select. I think that the clipboard and the select range is emptied at a high rate. It becomes impossible to copy anything on any window on ones computer. BE WARNED: JUST OPENING ROB BUTNERS SCRIPT IN YOUR BROWSER CAUSES MAJOR LIMITATIONS TO YOUR ABILITY TO COPY. USE "view source" or save and open the header.php in a text editor or you will not be able to copy it.
Control P appears to work at first but in fact all that is printed out is a blank page. This is a mystery to me.

4) At the top of the blockit.html page I included
<meta http-equiv="Content-Type" content="text/html; charset=x-euc-jp">
<br /><table align="center"  class="generalbox" border="0" cellpadding="5" cellspacing="0"><tr><td bgcolor="pink" class="generalboxcontent">Copying and printing during the Test is prohibited</td></tr></table><center><br /> 
Change the content statement to
content="text/html; charset=x-euc-jp"
If using Japanese.

It seems to work very well but

1) It still seems possible to download source. The determined copier could use this method of copying the quiz.

2) I cannot seem to get the above Rob Butner"Super-encoded-anti-copyiing-Javascript to work in Tandem with the Rob Butner provided Simpler-Javascript given above on this forum. The one above on this forum prevents use of the right click and gives warnings about the way that the browser functionality has been changed. The "Super-encoded" version seems just to work in the background which has the result that the student will not know why the functions are not working. I would like to be able to use both. 
Part of the problem was that I was using
"<scriptxxx" but in fact it should be script l a n g u a g e without the spaces as Genner explains above. But all the same, I still can't get security.js above to work.

3) If one saves the quiz then it is impossible to view that quiz simply in a browser. "aboutblack" is displayed. But it is still possible to view it in a text editor.

But of course, this functionality is a great help.

Tim
takemoto
 

In reply to Timothy Takemoto

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -

Oops, I am really sorry, blocking only attempt.php does not block the feedback since it is review.php that powers the feedback screen. Hence I have made common.php into

<?php
if (stristr($_SERVER['SCRIPT_FILENAME']."X", "attempt.phpX")) {
  include("blockit.html"); }
  if (stristr($_SERVER['SCRIPT_FILENAME']."X", "review.phpX")) {
  include("blockit.html"); }
  ?>

But perhaps
if (stristr($_SERVER['SCRIPT_FILENAME']."X", "attempt.phpX" or "review.phpX")) {
  include("blockit.html"); }
  ?>
would work? "or"?

I also changed "Copying and printing during the Test is prohibited" to "Copying and printing while viewing the Test is prohibited"

Tim

In reply to Timothy Takemoto

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -
I used to use Chris U's timer because, my boss wanted one, language should be readily accessable rather than slowly accessible, I thought that the timer made the test look rather serious and exam like, I thought that perhaps it would reduce on cheating.

However, having applied the above lobotomy to my students' browsers, I find that students are taking about 3 times longer over the homework!

Is this because they are swearing and cursing me as they use paper dictionaries rather than copying and pasting to one online?

Or is this because they are less like to copy from friends? Or is it just that the text is longer this week? Hmm...

They are doing pretty well too. I will let readers know of the student response this evening after the lesson.

Tim
In reply to Timothy Takemoto

Re: Adding protection to MOODLE quizzes---

by Edson Pfützenreuter -
I don't know so much of java and PHP, but know how to follow instructions. I did exactly what you is written in your messagem, but it didn't work.

Is there any other thing to set up.
In reply to Edson Pfützenreuter

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -
Dear Edson Pfutzenreuter
Sorry I did not see this sooner. That's strange. Perhaps I left something out. If you care to share you passwords with me I will take a look. It is working fine for me.
Tim
In reply to Timothy Takemoto

Re: Adding protection to MOODLE quizzes---

by Steven Geggie -
When you make these sorts of changes to the source code, how are you managing to re-integrate them into future releases?
In reply to Steven Geggie

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -

The good thing about the above hack is that it takes place entirely in the themes folder. The themes folder is the only one (plust config.php, sorry) that you have to move accross to future releases.

However perhpas there will have to be a rewrite when it comes to a new templated Moodle 2.0.

I have not used many of the other quiz hacks because they require changes outside the themes folder.

Perhaps it would be possible to have a "hacks" subdirectory within the themes folder such that any core moodle file that one wants to change, is placed in that hacks directory and moodle would look in there first. Trouble is...the hacks become non-compatible. I would really like to use the open quiz in new window hack but I don't for this reason.

Tim

In reply to Timothy Takemoto

Re: Adding protection to MOODLE quizzes---

by Scott Bartley -
Does this still work? I'm using 1.8.3. I want to have the clipboard constantly cleared, and the pages made unprintable and unsaveable with taking a quiz or viewing quiz results. My moodle can only be accessed for computers on our LAN which have no admin privileges, so I don't have to worry about them installing Snagit, etc.
In reply to Scott Bartley

Re: Adding protection to MOODLE quizzes---

by Timothy Takemoto -

I think that the above copy protection should work in any version of Moodle.

However while it will flush the clipboard, it does not work on Snagit which seems to use its own keepboard. I have Snagit and I just tried it, and I could copy the quiz screen. 

It will workon "Printscreen," which uses the normal clipboard however.

OOps stop press...the following does not seem to work. I am working on it now.

Also, and this is the reason why almost a year later I am returning to this thread, I have made a minor modification to the file "common.php" in the above theme, such that the copy-protection does not apply to administrators or teachers

common.php is now
 <?php
  if (!isadmin() && !isteacher()) { //so that copy protection does not apply to teachers
  if (stristr($_SERVER['SCRIPT_FILENAME']."X", "attempt.phpX")) {
  include("blockit.html"); }
  if (stristr($_SERVER['SCRIPT_FILENAME']."X", "review.phpX")) {
  include("blockit.html"); }
  }
  ?>

I think that perhaps all admins are teachers, but I am not sure, so I included both isadmin and isteacher. The above makes my life (and editing quizzes) a lot easier.

Enjoy,

Tim