#!/usr/local/bin/perl
# mcsimple.cgi, version 2.4 written in Perl 5.0, last revision 8/19/96.
# A PERL script that generates HTML pages containing either a
# multiple-choice question or the corresponding response page
# after the user submits an answer.
# Requires the cgi-utils.pl library, available at:
# http://www-genome.wi.mit.edu/WWW/tools/scripting/cgi-utils.html
# The script reads the question and response information from a text
# data file (with a *.qdf extension) of the form:
# # The next two lines contain the page title and question topic that will be displayed at the top of the web page.
# SEQ Question
# Example 1
# # The next line contains the question.
# Where do plants get the carbon they need for growth?
# # The next x lines are for the x number of answers for the question.
# From the soil they are in.
# From carbon dioxide in the atmosphere.
# From water.
# # The next 2 lines contain the sequential number of the correct answer and an optional explanation.
# 2
# Plants convert carbon dioxide gas to sugar molecules via photosynthesis. The sugars store energy and provide the building blocks for the plant to grow.
# # The next four lines are dummy slots for features not implemented.
# NA
# NA
# NA
# NA
# For more information see:
# http://www.chem.vt.edu/chem-ed/CHP/scripts/perl/mcsimple.html.
# Program and concept by Ron Earp and Brian Tissue.
# Copyright 1996 by Ronald L. Earp and Brian M. Tissue, all rights reserved.
require "cgi-utils.pl";
# Path to the question script on YOUR server. MUST BE CHANGED!
$question_path="http://www.chem.vt.edu/cgi-bin/mcsimple.cgi";
# Set variables for question responses.
$incorrect_response="That answer is incorrect.";
$correct_response="That answer is correct.";
$answer_tag=" *** Correct Answer *** ";
# The following variables specify the line positions of information in
# the data file. Counting starts at 0 for the first line of the data file.
$title1 = 1;
$title2 = 2;
$question = 4;
$answers = 6;
# The next two variables specify the positions of the correct answer and
# explanation relative to the last answer choice.
$answerpos = 1;
$explanationpos = 2;
# The next variable refers to the number of lines in the data file
# that are not displayed as part of the question.
$deadlines = 14;
# Create top of HTML page.
&start_page;
# Gets the environment variables using cgi-utils.pl.
@passed = &get_query;
# Check to see if the script is being called for a question or an answer.
if ($passed[4] ne "makeanswer")
{
$qfile = $passed[1];
# Check for proper file type and if it can be opened
if ($qfile =~ /.qdf/)
{
&checkfile;
}
else
{
$fail = 1;
&error_message;
}
if ($fail != 1)
{
# Read lines from the data file and store them as an array.
$index = 0;
@qarray = ;
$qlength = @qarray;
# Code to display the question from the array. Backslash characters
# are used to denote literals, such as @ or " within a string.
&display_question;
print "\n";
print "
\n";
close(QFILE);
}
}
else
{
# Splits the query string into 2 separate pieces for use in the program.
$qfile = $passed[3];
$answer = $passed[1];
# Check for proper file type and if it can be opened
if ($qfile =~ /.qdf/)
{
&checkfile;
}
else
{
$fail = 1;
&error_message;
}
if ($fail != 1)
{
# Read lines from the data file and store them as an array, $qarray.
# Data is read in exactly as stored in the datafile.
$index = 0;
@qarray = ;
$qlength = @qarray;
# Call subroutine to display the question.
&display_question;
# Display answers for question
print " \n";
$maxcount = ($qlength - $deadlines);
$count = 0;
while ($count < $maxcount)
{
if (($answers + $qarray[$answers + $maxcount + $answerpos]) == ($answers + $count + 1))
{
print "- $qarray[$answers + $count] $answer_tag\n";
$count++;
}
else
{
print "
- $qarray[$answers+$count] \n";
$count++;
}
}
print " \n";
print "
\n";
# Branching to provide output based on the users selection.
print "Your answer was $answer. ";
if ($answer == $qarray[$answers + $maxcount + $answerpos])
{
print "$correct_response
\n";
}
else
{
print "$incorrect_response
\n";
}
$flag = $qarray[$answers + $maxcount + $explanationpos + 2];
if ($flag ne "NO")
{
print $qarray[$answers + $maxcount + $explanationpos];
}
print "
\n";
print "
\n";
}
}
# Create end of HTML page.
&end_page;
# END OF MAIN SCRIPT.
# BEGINNING OF SUBROUTINES.
sub start_page
{
print ("Content-type: text/html\n\n");
print ("\n");
print "\n";
}
sub end_page
{
print "