How To Display Different Message When The User Passes and Fails a Quiz?

Actually WatuPRO is a lot more flexible than having “Failed” and “Passed” outcomes of a quiz. But many users need only “Failed” and “Passed” and the question how to display different content depending on this outcome comes often.

It’s very easy:

Step 1: Create “Passed” and “Failed” grades

Click on the “Grades” link for the quiz and you’ll get to the Manage Grades page. Define what points or % correct answer the user needs to achieve in order to pass. From this number of points up to the maximum number of points (or 100% correct answers) will be your “Passed” grade. Your conditional message will go inside the grade description. For example:

passed-grade

Any points or % correct answers below this will make the “Failed” grade. In similar way, enter your conditional message, if any. For example:

failed-grade

Step 2: Add the variable to your “Quiz output / Final page box

You can use the variable %%GDESC%% to dislay the conditional message accordingly to the achieved result. For example:

final-screen

That’s all! Two really easy steps.

[WatuPRO] How to Open The Export Files (Tab Delimited CSV Files)

In WatuPRO all export files are TAB (tabulator) delimited CSV files. The reason we use this format is because comma delimited files are more error prone when the data contains rich text, HTML, commas, quotes etc. Tabulator is a lot more reliable as delimiter when importing and exporting data.

If you use Microsoft Excel here are a couple of links that will help you:

The official Microsoft guides

A pictorial by Excel Easy

Here at Kiboko Labs we prefer to use Libre Office Calc. It’s free and has versions for Mac, Windows, and Linux. When you double-click a .csv named file it automatically suggests the proper delimiter. Just select UTF-8 (Unicode) as encoding, if this is not already selected and open the file. Much easier.

[WatuPRO] How To Make It Reload The Page on Each Question

This is a request we got few times. WatuPRO is designed to load pages in paginated quizzes nicely via ajax. This is the contemporary way of doing things and the desired behaviour for 99.9% of the customers. So “feature” to reload page on each refresh will probably never be added.

However this post will explain you how to customize the plugin yourself and achieve this in the rare case you need it (for example to get more ad impressions).

This is too complicated to be done as external plugin so it involves customizing WatuPRO directly. Here is it, step by step:

0. For all of this to work you must select “Automatically store user progress as they go from page to page” in the quiz settings.

1. Open lib/main.js and add:

WatuPRO.doReload = false;

under the other WatuPRO properties on top.

2. In method WatuPRO.nextQuestion in the same file add the following changes (in red) to the following piece of code:

       if(!this.doReload) {		
		jQuery("#question-" + WatuPRO.current_question).show();		
		
		this.hilitePage(WatuPRO.current_question, this.answered);			
		
		// show/hide next/submit button
		if(WatuPRO.total_questions <= WatuPRO.current_question) {		 			jQuery("#next-question").hide();		 			jQuery('#action-button').show(); 			if(jQuery('#WTPReCaptcha').length) jQuery('#WTPReCaptcha').show();  		} 		else { 			jQuery("#next-question").show();		 			if(jQuery('#WTPReCaptcha').length) jQuery('#WTPReCaptcha').hide(); 		} 		 		// show/hide previous button 		if(WatuPRO.current_question>1) jQuery('#prev-question').show();
		else jQuery('#prev-question').hide();
		
		// show/hide liveResult toggle if any
		if(jQuery('#questionWrap-'+WatuPRO.current_question).is(':hidden')) {
			jQuery('#liveResultBtn').hide();
		} else {
			if(jQuery('#liveResultBtn').length)  jQuery('#liveResultBtn').show();
		}
	}	
	else jQuery('.watupro-buttons').hide();

3. At the bottom of the same method add:

jQuery.post(WatuPRO.siteURL, data, function(msg){
		if(WatuPRO.doReload) location.reload();
	})	

This will make it reload when WatuPRO.doReload is true.
Now we have to make it true when clicking on buttons:

4. In the method initWatu in the same file REMOVE the red from the following code:

// different behavior if we have preloaded page
	if(!WatuPRO.pagePreLoaded) {
		jQuery("#question-1").show();
	} else WatuPRO.goto(null, WatuPRO.current_question);

so the goto gets executed always.

5. Open views/show_exam.php and find the calls to WatuPRO.nextQuestion(event, ‘previous’); and WatuPRO.nextQuestion(event). Make doReload to be true like this:

onclick=”WatuPRO.doReload=true;WatuPRO.nextQuestion(event, ‘previous’);”

6. If you use the paginator, do it for the paginator too. Models/exam.php static function paginator:

onclick=’WatuPRO.doReload=true;WatuPRO.goto(event, “.$j.”);’

7. Now if you want this to work for non-logged in users you need to make several PHP changes. By default WatuPRO never stores progress for non-logged in users to save server resources. But you can change this. In show_exam.php (not the view/ but the main file) add the following code (in red):

if(!empty($_SESSION['watupro_taking_id'])) {
	$in_progress = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".WATUPRO_TAKEN_EXAMS." 
		WHERE ID=%d AND exam_id=%d AND in_progress=1 ORDER BY ID DESC LIMIT 1", $_SESSION['watupro_taking_id'], $exam_id));
}
if(!empty($advanced_settings['dont_load_inprogress'])) $in_progress = null;

so we can get taking ID from session (Sessions MUST be enabled on your server)

8. In order to store tkaing ID in session you need to do several changes in lib/watupro.php. The first is to remove/comment the following from watupro_store_details() and watupro_store_all():

if(!is_user_logged_in()) exit;

9. Then in function add_taking() just before return $taking_id; add:

$_SESSION['watupro_taking_id'] = $taking_id;

10. In the same function just above if(empty($taking_id)) { add:

if(!empty($_SESSION['watupro_taking_id'])) $taking_id = $_SESSION['watupro_taking_id'];

That’s it. Shouldn’t take you more than 1-2 hours. If you can’t handle it yourself, we can provide the service for charge.

This is a customization and we cannot provide free support for it. If the change does not work you have to debug it yourself. Make sure sessions are enabled on your server.