Prototype Question with Logging of Either Responses or Errors


Here is a prototype question, to show you how each question will appear. To try the question, click here
#!/usr/local/bin/perl -- -*-perl-*-
use CGI;
require  "CleanUp.pl";
require  "explain.pl";
srand;
$query = new CGI;
print $query->header;
print $query->start_html('Prototype Question');

$scriptname = $query->script_name();#this gives the question name
#print $query->dump;#use this to check that it worked! Just remove comment(#).

print "<a href=/~cdavid/cgi-bin/test_send_memo.pl?var=$scriptname>Click here to send a message concerning errors in this question.<br></a>";

# this question was called via html?owner=Jones&name=SomeOne
$faculty_id = $query->param('owner');
$student_id = $query->param('name');
print "<br>";
print "<a href=send_memo.html>Click here to get a notation explanation</a>";
print "<br>";
print $query->start_form;
print <<EOF;
This is teacher created text concerning this particular question.
Without explicit print statements, it must be entered using a
special format.
<br>The faculty owner of this question is $faculty_id.
<br>The student owner of this questions is $student_id.
EOF
print "<br>Answer = ",$query->textfield('ans','',50,80);
print"<P> Query, is the above formula/number correct?",$query->submit;
print $query->end_form;

if ( $query->param('ans') ne '')
{
$stu_ans = $query->param('ans');
$saved_stu_ans = $stu_ans;
&CleanUp($stu_ans);#this removes potential hacker imbedded illegal commands
$ans = "sqrt(4/x)"; 
$x = rand;
$ans =~s/x/$x/gi;
$stu_ans =~s/x/$x/gi;
print "student_answer = $saved_stu_ans";
$stu_ans = eval($stu_ans);
$ans =  eval($ans);
#print "student_answer  = $stu_ans <p>";
#print "student_answer evaluated = $stu_ans<p>";
#print "answer evaluated = $ans <p>";
if (eval (($stu_ans - $ans)**2 - 0.0001  ) ge 0.0 ) 
	{print ", <EM> Wrong</EM>,
	<IMG SRC=../icons/checkno.gif>"}
 else {print ", <EM> Right! </EM>,
	<IMG SRC=../icons/check.gif>" };
};

print $query->end_html;




$scriptname = $query->script_name();
#print $query->dump;
print "<a href=../test_send_memo.pl?var=$scriptname>Click here to send a message concerning errors in this question.<br></a>";

Now we break up this text to explain its various parts
#!/usr/local/bin/perl -- -*-perl-*-
use CGI;
require  "/home/cdavid/public_html/cgi-bin/CleanUp.pl";
require  "/home/cdavid/public_html/cgi-bin/explain.pl";
srand;
$query = new CGI;
print $query->header;
print $query->start_html('Prototype Question');

`CleanUp' is a filter to prevent students from hacking into the system. Its text will be presented below.
`explain' is a generalized explanatory text panel which explains things like notation. One can have as many of them as one needs.
$scriptname = $query->script_name();#this gives the question name
#print $query->dump;#use this to check that it worked! Just remove comment(#).

We grab the name (file name) of this question here, so that the mailer can insert this information into the text being mailed. This is important, since when students think there are errors in the question, they rarely indicate its exact name. Thus speaks the voice of experience.
print "<a href=../test_send_memo.pl?var=$scriptname>Click here to send a message concerning errors in this question.<br></a>";

# this question was called via html?owner=Jones&name=SomeOne
$faculty_id = $query->param('owner');
$student_id = $query->param('name');
print "<br>";
`test_send_memo' is the mailer we use, whose text will be shown later, to allow students to declare that they think there are errors in the questions. This mailer points to me (cwd) no the teacher. (This can be changed by creating a new mailer for each teacher, but since the intent is to address the maintainer of the questions, I am the most likely candidate.)
We here capture the teacher and student id's for future use.
print "<a href=send_memo.html>Click here to get a notation explanation</a>";
print "<br>";
print $query->start_form;
Here starts the form which will be transmitted for grading.
print <<EOF;
This is teacher created text concerning this particular question.
Without explicit print statements, it must be entered using a
special format.
<br>The faculty owner of this question is $faculty_id.
<br>The student owner of this questions is $student_id.
EOF
print "<br>Answer = ",$query->textfield('ans','',50,80);
print"<P> Query, is the above formula/number correct?",$query->submit;
print $query->end_form;
After the form ends, we return here if the student presses the submit button.
if ( $query->param('ans') ne '')
{
$stu_ans = $query->param('ans');
$saved_stu_ans = $stu_ans;
&CleanUp($stu_ans);#this removes potential hacker imbedded illegal commands
As promised, we clean up the student's answer immediately, so that s/he can not hack into the system. The code for `CleanUp' follows:
sub CleanUp
{
if ( $_[0] ne '')
{
	$_[0] =~ s\/\//gi; 
	$_[0] =~ s/\$//gi; 
	$_[0] =~ s/\#//gi; 
	$_[0] =~ s/\~//gi;
	$_[0] =~ s/\^/**/gi;
}
}
return -1;
Notice that this subroutine blanks out offending text, since submitting a bad string to eval (see below) will not hurt anything.
$ans = "sqrt(4/x)"; 
We need to have the someone put in the right answer, so here it is.
$x = rand;
$ans =~s/x/$x/gi;
$stu_ans =~s/x/$x/gi;
We substitute the variable into both our answer and their answer. The text of the question should have told the student to use the variable `x'.
print "student_answer = $saved_stu_ans";
We echo the student's exact text back to him/her.
$stu_ans = eval($stu_ans);
$ans =  eval($ans);
We evaluate the randomly substituted expressions.
#print "student_answer  = $stu_ans <p>";
#print "student_answer evaluated = $stu_ans<p>";
#print "answer evaluated = $ans <p>";
These last three are debug statements which are uncommented while making up the question.
if (eval (($stu_ans - $ans)**2 - 0.0001  ) ge 0.0 ) 
	{print ", <EM> Wrong</EM>,
	<IMG SRC=../icons/checkno.gif>"}
 else {print ", <EM> Right! </EM>,
	<IMG SRC=../icons/check.gif>" };
};

In the simplest case, we just report right or wrong, with icons if we choose.
print $query->end_html;

Here is test_send_memo, a mailer which automatically transmits the test question's identity to me so that I can find it an correct errors in it without bothering the student.
Note that the variable `var' is the one being passed to this script. Here (below) it is called `$caller' while in the calling program (above) it is called `$scriptname'.
#!/usr/local/bin/perl -- -*- C -*-
use CGI;
$query = new CGI;
print $query->header;
@names = $query->param;
$caller = $query->param("var");
print "<P>";
print $query->start_form;
print "Please enter any comments, questions, or complaints you might have in the space below. If you think a question is being misgraded, it is very important
that you tell me as soon as possible, so that I can correct the grading
algorithm. Thank you.<br>";
print "What is your name? ", $query->textfield('username','',50,80);
print "<br>What is you electronic (return) address?",$query->textfield('realname','',30,80);
print "<br>This query refers to question:",$query->textfield(question,$caller,40,80);
print "<br>IMPORTANT: hit the 'return' key when your text 
reaches the right of this box to keep your rows fairly short
(<60 characters),  otherwise I won't be able to read most of your 
message in my mail reader. <p>";
print $query->textarea('comments','',10,80);
print "<br>";
print $query->submit('Submit','Send the comment');
print $query->reset;
print $query->end_form;

$username = $query->param('username');
$realname = $query->param('realname');
$comments = $query->param('comments');
$caller = $query->param('question');
if ($comments ne '') {


$mailprog = '/usr/lib/sendmail';
$recipient = 'david@uconnvm.uconn.edu';


open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!
";
print MAIL "Reply-to: $realname 
";
print MAIL "Subject: WWW comments (Forms submission)

";
print MAIL "username sent the following
";
print MAIL "Comments about the Physical Chemistry server:

";
print MAIL  "------------------------------------------------------------
";
print MAIL "What is your e-mail address?
";
print MAIL "$username

";
print MAIL "What is your real name?
";
print MAIL "$realname
";
print MAIL "What is the question?
";
print MAIL "$caller
";
print MAIL ":My comments: 

";
print MAIL "$comments

";
print MAIL  "
------------------------------------------------------------
";
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}
";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}
";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}
";
close (MAIL);

# Make the person feel good for writing to us
print "Thank you for sending comments to C. W. David.<P>";

# ------------------------------------------------------------


#print "<a href=http://www.sp.uconn.edu/~cdavid/cgi-bin/test_cdavid.pl?username=$username&realname=$realname&question=$called&comments=$comments>Click here once comment has been registered to actually send it.</a><br>";
};
print $query->end_html;