I think the Q and A sessions that can be created, are excellent.
At the end of a quiz, it is already possible to show the results, ie: the sum of correct answers.
However, I would like to know if there is any way to further use these results.
Is it possible for these results to be emailed to an address or written to a database?
Quiz Results - How to use them
8 posts • Page 1 of 1
Yes, missing from the template at the moment is any kind of sample server-side script to handle the Exchange Variables command. Think of the Exchange Variables action as like the Submit button in an HTML Form, except that the fields that are sent are the values of the variables that you declare. Let's say you have a URL of Save.asp on your Exhange Variables action. Then you create a Save.asp, in the Output directory, as follows:
Save.asp:
<%@ Language=VBScript %>
<%
Response.Expires = -1
set fso = Server.CreateObject("Scripting.FileSystemObject")
set ts = fso.OpenTextFile(Server.MapPath("Data\User" & Session.SessionID & ".xml"), 2, True)
ts.WriteLine "<Record>" & Chr(13)+Chr(10)
ts.WriteLine " <A>" & Request.Form("A") & "</A>" & Chr(13)&Chr(10)
ts.WriteLine " <B>" & Request.Form("B") & "</B>" & Chr(13)&Chr(10)
ts.WriteLine " <C>" & Request.Form("C") & "</C>" & Chr(13)&Chr(10)
ts.WriteLine "</Record>" & Chr(13)+Chr(10)
ts.Close()
Response.Write "ExchangeDone=true"
%>
This assumes your project has declared variables A, B, and C. It will use the current users's unique session id to create an xml file, which it then fills with the values of the variables. You would normally also have the user's userid at this point in a more complete solution, which you could use instead of the session id to store the data in the right row of a database.
However for this to work you need to run your project through your web server. You can do this via Project Options, General tab, Run this project via a custom URL, and specifying, eg. http://localhost/projects/myproject/out ... oject.html, assuming you've used My Computer > Manage to create a virtual root "projects" for your My Character Builder Projects directory, as we recommend when working with the Character Server. Then Run in Browser will run your project through the local web server, and, providing you have given IIS permission to write to the Output\Data subdirectory, you should start seeing files appear there.
Save.asp:
<%@ Language=VBScript %>
<%
Response.Expires = -1
set fso = Server.CreateObject("Scripting.FileSystemObject")
set ts = fso.OpenTextFile(Server.MapPath("Data\User" & Session.SessionID & ".xml"), 2, True)
ts.WriteLine "<Record>" & Chr(13)+Chr(10)
ts.WriteLine " <A>" & Request.Form("A") & "</A>" & Chr(13)&Chr(10)
ts.WriteLine " <B>" & Request.Form("B") & "</B>" & Chr(13)&Chr(10)
ts.WriteLine " <C>" & Request.Form("C") & "</C>" & Chr(13)&Chr(10)
ts.WriteLine "</Record>" & Chr(13)+Chr(10)
ts.Close()
Response.Write "ExchangeDone=true"
%>
This assumes your project has declared variables A, B, and C. It will use the current users's unique session id to create an xml file, which it then fills with the values of the variables. You would normally also have the user's userid at this point in a more complete solution, which you could use instead of the session id to store the data in the right row of a database.
However for this to work you need to run your project through your web server. You can do this via Project Options, General tab, Run this project via a custom URL, and specifying, eg. http://localhost/projects/myproject/out ... oject.html, assuming you've used My Computer > Manage to create a virtual root "projects" for your My Character Builder Projects directory, as we recommend when working with the Character Server. Then Run in Browser will run your project through the local web server, and, providing you have given IIS permission to write to the Output\Data subdirectory, you should start seeing files appear there.
- staff
- Site Admin
- Posts: 620
- Joined: Fri Mar 21, 2008 6:24 am
- Location: Bellevue, Washington
Thanks again.
You mention localhost, IIS and ASP. That's fine for local testing but I would like to set this up on our virtual Unix server so that clients can login and use it for their own staff and/or customers.
Do you have any pointers as to what I need to do?
You mention localhost, IIS and ASP. That's fine for local testing but I would like to set this up on our virtual Unix server so that clients can login and use it for their own staff and/or customers.
Do you have any pointers as to what I need to do?
- polding
- Posts: 22
- Joined: Fri Mar 21, 2008 6:24 am
I don't, but everything would be roughly the same. Assuming you use php instead of asp, you would just need to make the appropriate syntax changes - the server-side script can happily pretend that it's talking to a regular HTML form on the client side - imagine a form with one edit field per variable.
- staff
- Site Admin
- Posts: 620
- Joined: Fri Mar 21, 2008 6:24 am
- Location: Bellevue, Washington
I am trying to get an ASP to PHP translation on the above code.
If I get it, and get this working, I will post my findings here for others to use.
In the meantime, if anybody has a translation already, I would love to see it because that could in fact save me an amount of time, effort and grief.
If I get it, and get this working, I will post my findings here for others to use.
In the meantime, if anybody has a translation already, I would love to see it because that could in fact save me an amount of time, effort and grief.
- polding
- Posts: 22
- Joined: Fri Mar 21, 2008 6:24 am
Okay, I have it. The PHP translation of the above code is ...
<?php
session_start();
// Obtain POST variables from form
$A = $_POST['Correct'];
$B = $_POST['Incorrect'];
$C = $_POST['Total'];
// Create file contents
$data="<Record>\n<A>$A</A>\n<B>$B</B>\n<C>$C</C>\n</Record>";
// Obtain sessionid and create file
$session_id = session_id();
$file = "/home/path/to/file/Data/User".$session_id.".xml";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
fclose($file_handle);
?>
The next steps for us will be ...
1 - to have the user provide an email address or name before taking the quiz
2 - create a user ID instead of a session ID
3 - write the info to a database instead of a file
If anyone is interested, I will post our solutions here when we have them.
<?php
session_start();
// Obtain POST variables from form
$A = $_POST['Correct'];
$B = $_POST['Incorrect'];
$C = $_POST['Total'];
// Create file contents
$data="<Record>\n<A>$A</A>\n<B>$B</B>\n<C>$C</C>\n</Record>";
// Obtain sessionid and create file
$session_id = session_id();
$file = "/home/path/to/file/Data/User".$session_id.".xml";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
fclose($file_handle);
?>
The next steps for us will be ...
1 - to have the user provide an email address or name before taking the quiz
2 - create a user ID instead of a session ID
3 - write the info to a database instead of a file
If anyone is interested, I will post our solutions here when we have them.
- polding
- Posts: 22
- Joined: Fri Mar 21, 2008 6:24 am
8 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest