Articulate Community Forums

Articulate Community Forums » Articulate Product Forums » Articulate Quizmaker » Email Results Tutorial - PHP

Reply
 
LinkBack Thread Tools Search this Thread
Old 07-11-2007, 04:48 PM   # 1
Moderator
 
beeneeb's Avatar
 
Join Date: Jul 2007
Posts: 2,487
Smile Email Results Tutorial - PHP


Hey everyone. I figured out how to use PHP to email the results of a quiz. (This does not work with Articulate '09, only the 5.x products. Click here for the Articulate '09 solution.

Essentially, I changed the "SendQuiz" function so that it posts the data to "sendmail.php". sendmail.php is not universally installed on every server. So, this may not work for you.

For simplicity sake, I have attached a .zip file (at the bottom) with the "quizmaker.html", "backup.txt", and the "sendmail.php". You should be able to copy and paste these into your output folder (the folder that contains your published quiz). Be sure to make backup copies on your side. I'm not responsible for problems that you have since I have not tested this on any other machines.

I replaced the "SendQuiz" function in "quizmaker.html" with the following code:

Code:
function SendQuiz()  
{
	g_strQuizResults = g_strQuizResults.replace(/'/g,"'");

	var sHTML = "";
	sHTML += '<FORM id="formQuiz" method="POST" action="sendmail.php">';
	sHTML += '<INPUT TYPE="hidden" NAME="QuizResults" VALUE=\'' + g_strQuizResults.replace(/\\n/g,"\n") + '\'>';
	sHTML += '<br><input type="submit"><br>';
	sHTML += '</FORM>';
	document.getElementById("divQuiz").innerHTML = sHTML;
	document.forms["formQuiz"].submit();
}
I then switched the string replacements for "Quiz Results" and "QuizResults" in the "function player_DoFSCommand(command, args)" function.

Code:
function player_DoFSCommand(command, args) 
{
	args = String(args);

	args = args.replace(/%_q_%/g,"\"")
	args = args.replace(/;/g,"|$s$|")
	args = args.replace(/%_s_%/g,";")

	command = String(command);
	var F_intData = args.split("|$s$|");

	switch (command)
	{
    		case "ART_CloseAndExit":
			if (!g_bLMS)
			{
	       			 //QM customized//
				if (FF)
				{
					setTimeout("CloseWindow()", 100);
				}
				else
				{
					window.close();
				}
			}
			break;

		//Email//
		case "emailEmail":
			g_strEmail = args;
			break;

		case "QuizResults":
			var strTemp = args.replace(/\|\$s\$\|/g,";");
			g_strQuizResults = strTemp;
			break;
		case "Quiz Results":
			
		case "emailSubject":
			g_strSubject = args;
			break;

		case "emailSubmit":
			SendQuiz();
			break;
		case "StoreQuestionResult":
			StoreResult(args);
			break;
		case "StoreQuizResult":
			StoreQuizResult(args);
			break;
		case "DisplayPrintScreen":
			ShowResult(args);
			break;
		case "ART_QMAttachment":
			g_strAttachment = args;
			if (IESP2)
			{
				OpenAttachment()
			}
			else
			{
				setTimeout("OpenAttachment()", 100)
			}
			break;
		case "QM_ZoomImage":
			PopZoomImage(F_intData[0], F_intData[1], F_intData[2]);
			break;

	}


	if (g_bLMS)
	{
		customFScommandHandler(command, args);
	}
}
I then saved the file & created a sendmail.php file in the same folder. You will need to change "none@none.com" to your email address to receive the email. When uploading the "sendmail.php" to your server, it must have a "644" attribute (which means the owner can read and write the file, but members of the group the file belongs to, and all others can only read the file) Here's the entire code for that file:

Code:
<? 
 $email = $_REQUEST['email']; 
 $QuizResults = $_REQUEST['QuizResults']; 
 $Replace = "\\\""; 
 $QuizResults = str_replace($Replace, "", $QuizResults); 
  mail( "none@none.com", "Quiz Name", 
   $QuizResults, "From: Quiz Name" ); 

print "Congratulations! Your quiz has been submitted!"; 

?>
After doing this & uploading the files to my server, I get the following results for an email:

==========

Core Data

Status,Raw Score,Passing Score,Max Score,Min Score,Time
failed,10,80,100,0,

Date,Time,Score,Interaction ID,Objective ID,Interaction Type,Student Response,Result,Weight,Latency
07/11/07,15:17:24,0,I0001,I0001,choice,Build-A-Brochure, Co-Marketing, Yellow Pages, Consumer Extended Warranty Notification;,wrong,1,00:00:02
07/11/07,15:17:26,0,I0002,I0002,choice,Can provide additional sell up opportunities;,wrong,1,00:00:02
07/11/07,15:17:28,0,I0003,I0003,choice,6 month No Interest No Pay;,wrong,1,00:00:02
07/11/07,15:17:30,0,I0004,I0004,true-false,false;,wrong,1,00:00:02
07/11/07,15:17:32,0,I0005,I0005,choice,Commercial Leasing Program;,wrong,1,00:00:02
07/11/07,15:17:34,0,I0006,I0006,true-false,true;,wrong,1,00:00:02
07/11/07,15:17:36,0,I0007,I0007,choice,$15;,wrong,1,00:0 0:02
07/11/07,15:17:38,0,I0008,I0008,choice,Dealer Locator;,wrong,1,00:00:02
07/11/07,15:17:39,0,I0009,I0009,choice,16%;,wrong,1,00:0 0:02
07/11/07,15:17:42,0,I00010,I00010,choice,None of the above;,wrong,1,00:00:03
07/11/07,15:17:44,0,I00011,I00011,choice,www.Hvacr.com;,wrong,1,00:00:02
07/11/07,15:17:46,5,I00012,I00012,choice,NetProphet;,cor rect,1,00:00:02
07/11/07,15:17:47,0,I00013,I00013,choice,Ad Planner;,wrong,1,00:00:01
07/11/07,15:17:49,5,I00014,I00014,choice,All of the Above;,correct,1,00:00:02
07/11/07,15:17:51,0,I00015,I00015,choice,All of the above;,wrong,1,00:00:02
07/11/07,15:17:53,0,I00016,I00016,choice,200;,wrong,1,00 :00:02
07/11/07,15:17:55,0,I00017,I00017,choice,Ad Planner;,wrong,1,00:00:02
07/11/07,15:17:57,0,I00018,I00018,true-false,false;,wrong,1,00:00:03
07/11/07,15:17:59,0,I00019,I00019,choice,In business for at least 3 years;,wrong,1,00:00:02
07/11/07,15:18:01,0,I00020,I00020,choice,Performance Consulting;,wrong,1,00:00:02

==========

The following information was edited on 8/28/2007:

I recently ran into a problem in which the receiver of the emails didn't get all of the results that were submitted. After pondering a few days about a solution to this problem, I figured out a way to create a "backup" for the results. Essentially, I created a "backup.txt" file that is initially empty. In the "sendmail.php" file, I added some code that opens up the text file & appends it. So, every time a user "Emails Results", it also writes the same data to a text file. When uploading the "backup.txt", be sure to change the attributes to "767"

For simplicity sake, I have attached a .zip file with the "quizmaker.html", "backup.txt", and the "sendmail.php". You should be able to copy and paste these into your output folder. Be sure to make backup copies on your side. I'm not responsible for problems that you have since I have not tested this on any other machines.

The following information was edited on 12/19/2007:

Thanks to desabol, the tutorial has been updated so that it now works with Firefox!

Good luck!
Attached Files
File Type: zip For Articulate120108.zip (4.1 KB, 105 views)
__________________
Brian Batt
Customer Support Engineer
Articulate - Empowering Rapid E-Learning
www.articulate.com

Using the latest versions? Get 63 product enhancements with Studio '09 Update 5

You twitter? Follow me here.


Last edited by beeneeb : 04-09-2009 at 02:22 PM.
beeneeb is offline  
Reply With Quote
Old 07-11-2007, 08:31 PM   # 2
Member
 
GerryWaz's Avatar
 
Join Date: Feb 2006
Location: Woodbury, MN
Posts: 5,564
Default Re: Email Results Tutorial - PHP


WAY COOL! Congrats! Looking forward to trying this out ourselves.

Best.

- Gerry
GerryWaz is offline  
Reply With Quote
Old 07-13-2007, 09:39 PM   # 3
Moderator
 
beeneeb's Avatar
 
Join Date: Jul 2007
Posts: 2,487
Default Re: Email Results Tutorial - PHP


Quote:
Originally Posted by beeneeb View Post

For simplicity sake, I have attached a .zip file with both the "quizmaker.html" and the "sendmail.php". You should be able to copy and paste these into your output folder. Be sure to make backup copies on your side. I'm not responsible for problems that you have since I have not tested this on any other machines.

Good luck!
Hey everyone! I got some more time to test this with a few quizzes & it works perfectly. After creating your quiz, simply replace your "quizmaker.html" file with the one that's attached in the zip file from the original message. Then, tweak the "sendmail.php" & change the email address to your own. Put the "sendmail.php" file into the same folder as the rest of your quiz & upload it to your server. As long as your server is capable of the "sendmail.php" function, it will work perfectly. If you don't know if it'll work, simply try it & see what happens.

If anyone tries this, I would love to see some feedback on it. Thanks!
beeneeb is offline  
Reply With Quote
Old 07-18-2007, 10:52 AM   # 4
Member
 
Join Date: Jul 2007
Posts: 5
Default Re: Email Results Tutorial - PHP


I;'m having a little difficulty with this. I had no problems editing quizmaker.html nor creating the sendmail.php. I can load sendmail.php with nio issues and it emails just fine. But when I finish a quiz and press "Email Results" It never loads sendmail.php and just hangs.

I also tried using the files from the zip.

And before I am asked. User permissions are correct, 755 and 777 on both files (tried both) sendmail.php is in the same directory as quizmaker.html. loading sendmail.php manually does work.

Anything else I could try?
Rick Vestal is offline  
Reply With Quote
Old 07-18-2007, 11:09 AM   # 5
Moderator
 
beeneeb's Avatar
 
Join Date: Jul 2007
Posts: 2,487
Default Re: Email Results Tutorial - PHP


Would you mind uploading your quizmaker.html & sendmail.php? I'll take a look at it & compare it to my source.
beeneeb is offline  
Reply With Quote
Old 07-18-2007, 11:14 AM   # 6
Member
 
Join Date: Jul 2007
Posts: 5
Default Re: Email Results Tutorial - PHP


You bet! Keep in mind the quizmaker.html is the one from your zip file.
Attached Files
File Type: zip spnc_hipaa.zip (3.8 KB, 83 views)
Rick Vestal is offline  
Reply With Quote
Old 07-18-2007, 02:38 PM   # 7
Moderator
 
beeneeb's Avatar
 
Join Date: Jul 2007
Posts: 2,487
Default Re: Email Results Tutorial - PHP


Quote:
Originally Posted by Rick vestal View Post
You bet! Keep in mind the quizmaker.html is the one from your zip file.
Hey Rick. I'm not sure what the problem is. Your files are perfect. In fact, I replaced my files on my server with the files from your zip file & they worked perfectly. If I had to guess, I would say that the sendmail function isn't installed on your server. Contact your hosting company to verify that the sendmail function is installed. If not, either request that they do it or ask if you can install it yourself. I really don't know much about installing sendmail, but you might try google.com. I found a few things:

Install Sendmail at Holy Shmoly!
Sendmail.org - Downloads

You might try those...I don't know anything about installing functions on the server-side, maybe someone here can help you with that. For me, I got lucky enough to have a hosting company that has sendmail. So, good luck & I hope that it works out for you.

Sorry I couldn't help more.
beeneeb is offline  
Reply With Quote
Old 07-19-2007, 03:44 PM   # 8
Member
 
Join Date: Jul 2007
Posts: 5
Default Re: Email Results Tutorial - PHP


I'm still working on this... The server this was originally on is a SuSE 10.2 box running postfix. Both the Quiz work as well as the sendmail.php (by loading sendmail.php directly instead of calling it from PHP.) So as a test, I went ahead and moved it over to my personal host, which is FreeBSD running sendmail. Same thing... the quiz hangs when it should be loading sendmail.php. Again, you can load sendmail.php directly in a browser and it works (it just sends me a blank message.) I checked permissions on sendmail.php as well... It just plain and simply will not call this script on either of my servers...

Here's the test quiz the training guy threw together for me to test...

Rick&apos;s Test

And here's the sendmail script...

http://www.acceptable-risk.org/test_quiz/sendmail.php

I think I'm just going to give up here soon. Maybe they'll incorporate this feature in future revisions of Articulate...
Rick Vestal is offline  
Reply With Quote
Old 07-19-2007, 04:09 PM   # 9
Moderator
 
beeneeb's Avatar
 
Join Date: Jul 2007
Posts: 2,487
Default Re: Email Results Tutorial - PHP


Quote:
Originally Posted by Rick vestal View Post
I checked permissions on sendmail.php as well... It just plain and simply will not call this script on either of my servers...
FYI...the file permission on my "sendmail.php" is 644. Try that & let me know if it works.

By the way, I just tried your "Rick's Test" link & it did go through. After I answered question 3, I selected "Email Results" & it went through. This leads me to believe that your browser settings are different than mine. Check your email & see if you got my results. I think I submitted my results 2 or 3 times.

What browser are you using?


Last edited by beeneeb : 07-19-2007 at 04:26 PM.
beeneeb is offline  
Reply With Quote
Old 07-19-2007, 05:40 PM   # 10
Administrator

 
Join Date: Feb 2006
Location: NY
Posts: 2,139
Default Re: Email Results Tutorial - PHP


Clicking email results also works for me in IE6, but not in FF2 (which is to be expected). In IE6 after clicking email results, I get this:

Quote:
Congratulations! Your quiz has been submitted!
__________________
Gabe Anderson
Director of Customer Advocacy
Articulate - Empowering Rapid E-Learning
Get the latest Articulate news: Subscribe to Word of Mouth
You should follow me on Twitter here.
gabe is offline  
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On