#! /usr/local/bin/perl -- ######################################################################## # qa-ann.pl Version 4.1 January 22, 1997 # Copyright (c) 1996-1997 Matthew J. Walker # Written for the UCLA Virtual Office Hours Project # Code can be freely distributed for educational use, as long as header # remains intact. See included Copyright and Licensing information. # For info send email to voh@chem.ucla.edu # # Edit this file, replacing "/" with ":" for Mac in paths ######################################################################## require 'voh-lib.pl'; &SetupVOH; $file_number = 0 ; # initial value $lecture_path ="$root_path/$in{lecture}"; $qa_file_name = "$lecture_path/qa.html"; $announcement_file ="$lecture_path/announcements.html"; if ($in{request}) { # coming from qaarf.html ($in{request} eq "announcement") && (&CreateAnnForm); #announcement? ($in{verification} !~ /$verification_string/) && (&Failure(24)); &GetQuestion ; &CreateAnswerForm("None"); } elsif ($in{question_file}) { # coming from qa form if ($in{killit} eq "killit") { # delete the question? if (-e "$questions_path/$in{question_file}") { unlink "$questions_path/$in{question_file}"; } $file_number = $in{file_number} ; &GetQuestion; &CreateAnswerForm("Deleted"); } elsif ($in{skip} eq "skip") { # skip the question? $file_number = ++$in{file_number} ; &GetQuestion; &CreateAnswerForm("Skipped"); } else { # answer the question. unless ($in{answer}) { &Failure(04) ;} &WriteFile(Question_Answer); if (-e "$questions_path/$in{question_file}") { unlink "$questions_path/$in{question_file}"; } $file_number = $in{file_number} ; &GetQuestion; &CreateAnswerForm("Answered Successfully"); } } elsif ($in{announcement}) { # coming from announcement form &WriteFile(Announcement); $success = "Announcement Posted Successfully"; &Success; } else { # shouldn't get here, but... &Failure(07) ; } # CreateAnswerForm # Generates Question Answer Form and sends it to the client # The HTML Generated by this subroutine will need to be edited to # reflect the content of your site! sub CreateAnswerForm { local($html); $html = <<"EOC"; $HTTP_header $HTML_title // Question Answer Form

Question Answer Form


Question:


If you want to delete this question without answering it.
If you want to skip this question and answer it later.

Answer:

$warning


$HTML_footer EOC if ($system_type eq "Mac") { MacPerl::Reply($html); } else { print ($html); } exit; } # GetQuestion # Retrieves the first question from the proper directory sub GetQuestion { $question = "" ; opendir(QUESTIONS, "$questions_path") || (&Failure(11)) ; @questions = sort (grep(!/^\.\.?$/, readdir(QUESTIONS))); if (-T "$questions_path/$questions[$file_number]") { open(QUESTION, "$questions_path/$questions[$file_number]") || (&Failure(12)) ; while() { $question .= $_ ; } close(QUESTION); closedir(QUESTIONS) ; } else { # If the file isn't text then the dir was empty. # This is is monster hack, but.... $success = "All questions have been answered." ; &Success; } } # CreateAnnForm # Creates Announcement Submission form and sends it to client # Again, edit the HTML! sub CreateAnnForm { local($html); $html = <<"EOA" ; $HTTP_header $HTML_title // Announcement Submission Form

Announcement Submission Form


Announcement:

$warning


$HTML_footer EOA if ($system_type eq "Mac") { MacPerl::Reply($html); } else { print ($html); } exit; } # WriteFile # Writes formated QA pair or announcement to proper file. sub WriteFile { local($test,$new_text,$html) = @_ ; if ($test eq "Question_Answer"){ $open_file_name = $qa_file_name ; $html = &FormatQA; } elsif ($test eq "Announcement") { $open_file_name = $announcement_file; $html = &FormatAnnouncement; } open(FILE, "$open_file_name") || (&Failure(13)) ; while () { $new_text .= $_ ; } close FILE ; $new_text =~ s/()/$1\n$html/ ; open(FILE, ">$open_file_name") || &Failure(13) ; print FILE ($new_text) ; close FILE ; } # FormatQA # Formats form input for public posting to file. sub FormatQA { local($output); $output .= "

Question:

\n" ; $output .= $in{question} ; $output .= "

Answer:

\n" ; $output .= "

$in{answer}



\n "; return $output; } # FormatAnnouncement # Formats form input for posting to announcements file. sub FormatAnnouncement { local($output); $output .= "

$date

\n" ; $output .= "

$in{announcement}


\n "; return $output; } # Success # Creates HTML text to send to client after post. # Edit HTML!! sub Success { local($html, $temp); ($temp = $in{lecture}) =~ s#:# #; $html = <<"EOS" ; $HTTP_header $HTML_title // Success!

$success

Go back to the: $HTML_footer EOS if ($system_type eq "Mac") { MacPerl::Reply($html); } else { print ($html); } exit; }