#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); # (c) NueDream Inc. 2000-2001 ############## GLOBAL VARS AND CONSTS ############ $file = "questions.db"; # This is the name of your questions file $quizname = "NueQuiz"; # This is what appears in the TITLE $editurl = "thearma.org/nuequiz/edit.cgi"; # Location of the edit page $passurl = "thearma.org/nuequiz/password.htm"; # Location of Password Check file ############ THESE ARE OPTIONAL CHANGES ########### $spacer = '|'; # leave it unless you already have a database @list = ('a','b','c','d','e','f'); ############## GET INFO FROM WEBPAGE ############ if($ENV{'HTTP_REFERER'} =~ /$passurl/ || $ENV{'HTTP_REFERER'} =~ /$editurl/) { print "Content-type: text/html\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name,$value) = split (/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c", hex($1))/eg; $value =~ s/\n/ /g; # newlines are now spaces $value =~ s/\r//g; # removes hard returns $value =~ s/\cM//g; # deletes ^M's $FORM{$name} = $value; } ############## MAIN PROGRAM ############ if ($FORM{'action'} eq "") { print < :::: NueQuiz Administration Page :::: Administrative Menu

Choose what action you wish to perform and click on the Submit button.

Modify Beginner Quiz Questions.
Modify Novice Quiz Questions
Modify Expert Quiz Questions

Add Beginner Quiz Question
Add Novice Quiz Question
Add Expert Quiz Question


NueQuiz - (c) 2000 NueDream Inc.
EndADMIN } elsif ( $FORM{'action'} eq "Submit" ) { $edit = $FORM{'edit'}; if ($edit =~ /\w+beg$/) { $quiz = "beginner"; } elsif ($edit =~ /\w+nov$/) { $quiz = "novice"; } elsif ($edit =~ /\w+exp$/) { $quiz = "expert"; } else { dienice("Invalid quiz type go to the Admin Page and try again"); } if ($edit =~ /^mod\w+/) { $type = "modify"; } elsif ($edit =~ /^add\w+/) { $type = "add"; } else { dienice("Invalid action to perform go to the Admin Page and try again"); } open(DATA,$file) or dienice("Couldn't open $file :: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server seek(DATA,0,0); @data = ; close(DATA); ##### GENERAL ADMIN DISPLAY ##### print ":::: Quiz Administration Page :::: $ENV{'HTTP_REFERER'}\n"; print ""; print "Administrative Menu
"; print "
"; print "You are ".$type."ing a record in the $quiz quiz.\n"; print "
"; if ($type eq "add") { print "Complete the required(*) information and hit add.
"; print "You may leave some of the questions empty if you choose.
"; print "To display no reason just use a blank space in the Reason area.
"; print "
"; print ""; print "\n"; print "\n"; print "\n"; foreach $i (@list) { print "\n"; print "\n"; } print "\n"; print "\n"; print ""; print "
*Question:
*Answer#*Choices
$i)
*Reasoning for answer
\n
\n"; print "
"; print "NueQuiz - (c) 2000 NueDream Inc.\n"; } elsif ($type eq "modify") {# modifying a database of quizzes print ""; foreach $line (@data) { ($quizin,$num,$question,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\Q$spacer/,$line); if ($quizin eq $quiz) { print ""; print "\n"; print ""; } } print "
$num) $question
"; print "
"; print "NueQuiz - (c) 2000 NueDream Inc.\n"; } } elsif ($FORM{'action'} eq "Add") { #check if input is correct and put it into the database if ($FORM{'reason'} eq "" || $FORM{'answer'} eq "" || $FORM{$FORM{'answer'}} eq "" || $FORM{'question'} eq ""){ print "

ERROR :: Information Incomplete


Please hit your browser's back button and complete the information"; } else { open(DATA,$file) or dienice("Couldn't open $file :: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server @data = ; close(DATA); $count = 0; foreach $line (@data) { ($quizin,$num,$question,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\Q$spacer/,$line); if ($quizin eq $FORM{'quiz'}) { if ($count < $num) { $count = $num; } } } $count++; $line = $FORM{'quiz'}.$spacer.($count).$spacer.$FORM{'question'}.$spacer.$FORM{'answer'}.$spacer; foreach $i (@list){ $line .= $FORM{$i}.$spacer; } $line .= $FORM{'reason'}; open(DATA,">>".$file) or dienice("Couldn't open $file :: $!\n"); print DATA $line."\n"; close(DATA); print ":::: $quizname Administration Page ::::\n"; print ""; print "Administrative Menu
"; print "
"; print "You have successfully Added a question in the $FORM{'quiz'} $quizname quiz
\n"; print "
"; print "
You may now return to the administration page.


"; print "
"; print "NueQuiz - (c) 2000 NueDream Inc.\n"; } } elsif ($FORM{'action'} eq "Update") {# going to update a specific question open(DATA,$file) or dienice("Couldn't open $file :: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server seek(DATA,0,0); @data = ; close(DATA); foreach $line (@data) { chomp($line); ($quizin,$num,$question,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\Q$spacer/,$line); if ($quizin eq $FORM{'quiz'} && $num eq $FORM{'number'}) { $string = $FORM{'quiz'}.$spacer.$FORM{'number'}.$spacer.$FORM{'question'}.$spacer.$FORM{'answer'}.$spacer; foreach $i (@list){ $string .= $FORM{$i}.$spacer; } $string .= $FORM{'reason'}; push (@result, $string); } else { push (@result, $line); } } open(DATA,">".$file) or dienice("Couldn't open $file for overwriting:: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server seek(DATA,0,0); sort @result; foreach $line (@result) { print DATA $line."\n"; } close(DATA); ##### MODIFIED QUESTION DISPLAY ##### print ":::: $quizname Administration Page ::::\n"; print ""; print "Administrative Menu
"; print "
"; print "You have successfully Modified a question in the $FORM{'quiz'} $quizname quiz
\n"; print "
"; print "
You may now return to the administration page.


"; print "
"; print "NueQuiz - (c) 2000 NueDream Inc.\n"; } elsif ($FORM{'action'} eq "Edit") {# going to edit a specific question open(DATA,$file) or dienice("Couldn't open $file :: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server seek(DATA,0,0); @data = ; close(DATA); ##### EDITING QUESTION DISPLAY ##### print ":::: $quizname Administration Page ::::\n"; print ""; print "Administrative Menu
"; print "
"; print "You are Editing a record in the $FORM{'quiz'} quiz.\n"; print "
"; foreach $line (@data) { ($quizin,$num,$question,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\Q$spacer/,$line); if ($quizin eq $FORM{'quiz'} && $question eq $FORM{'question'} && $num eq $FORM{'number'}) { print "
"; print ""; print ""; print "\n"; print "\n"; print "\n"; $addon = ($ans eq "a")?" checked":""; print "\n"; print "\n"; $addon = ($ans eq "b")?" checked":""; print "\n"; print "\n"; $addon = ($ans eq "c")?" checked":""; print "\n"; print "\n"; $addon = ($ans eq "d")?" checked":""; print "\n"; print "\n"; $addon = ($ans eq "e")?" checked":""; print "\n"; print "\n"; $addon = ($ans eq "f")?" checked":""; print "\n"; print "\n"; print "\n"; print "\n"; print ""; print "
Question:
Answer#Choices
a)
b)
c)
d)
e)
f)
Reasoning for answer
\n
\n"; print "
"; print "NueQuiz - (c) 2000 NueDream Inc.\n"; last; } } } elsif ($FORM{'action'} eq "Remove") {# going to remove a specific question open(DATA,$file) or dienice("Couldn't open $file :: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server seek(DATA,0,0); @data = ; close(DATA); foreach $i ("beginner", "novice", "expert") { $nextnum{$i} = 0; } foreach $line (@data) { chomp($line); ($quizin,$num,$question,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\Q$spacer/,$line); if ($quizin eq $FORM{'quiz'} && $question eq $FORM{'question'} && $num eq $FORM{'number'}) { } else { $nextnum{$quizin}++; $string = $quizin.$spacer; $string .= $nextnum{$quizin}.$spacer.$question.$spacer.$ans.$spacer; $string .= $a.$spacer.$b.$spacer.$c.$spacer.$d.$spacer.$e.$spacer.$f.$spacer; $string .= $reason; push (@result, $string); } } open(DATA,">".$file) or dienice("Couldn't open $file for overwriting:: $!\n"); #flock(DATA,0); # uncomment this line if using unix based server seek(DATA,0,0); sort @result; foreach $line (@result) { print DATA $line."\n"; } close(DATA); ##### REMOVED QUESTION DISPLAY ##### print ":::: $quizname Administration Page ::::\n"; print ""; print "Administrative Menu
"; print "
"; print "You have successfully Removed a question in the $FORM{'quiz'} $quizname quiz
\n"; print "
"; print "
You may now return to the administration page.


"; print "
"; print "NueQuiz - (c) 2000 NueDream Inc.\n"; } else { print "Content-type: text/html\n\n"; dienice("You have not used a valid way to access this program go to the Admin Page"); } } else { print "Content-type: text/html\n\n"; dienice("You have not used a valid way to access this program."); } ############## DYING SUBROUTINE ############ sub dienice { my($msg) = @_; print ("


FATAL ERROR



\n"); print ($msg); exit; }