#!/usr/bin/perl -w #################################### # # COPYRIGHT NOTICE: # # Copyright 2000 Aytekin Tank. # # This program may be used and modified free of charge by anyone, so # long as this copyright notice and the header above remain intact. # Selling the code for this program without prior written consent is # expressly forbidden. Obtain permission before redistributing this # program over the Internet or in any other medium. In all cases # copyright and header must remain intact. # # This program is distributed "as is" and without warranty of any # kind, either express or implied. All responsibility is belong to # you if any damage or loss occurs. #################################### ############################### # VARIABLES ############################### ############################### # Place you password here: ############################### $password = "admin"; ############################### # Directory # # if using NT, put the whole path like (/whole/path/) # leave it blank like I did for unix: ############################### $directory = ""; ############################### # FAQ files you will use: ############################### @faq_files = ("faq.html", "other/faq.html", "other_fql.html"); ############################### # To give the looka and feel you want # you can edit these parts in the FAQ tags # # they should be only one line: ############################### $before_question = "
";
$after_question = "
";
$before_answer = "";
$after_answer = "";
###############################
# Don't touch anything after this
# unless you know who is Larry Wall..
###############################
###############################
# MENU
###############################
$addon = "
Powered by FAQ Manager
";
&readQuery();
print "Content-type: text/html\n\n";
&initilize();
if($password ne $input{'pass'})
{ &logOnForm(); &Exit(); }
elsif ($input{'action'} eq "list")
{
&ReadFile();
&List();
}
elsif
(($input{'action'} eq "add") or
($input{'action'} eq "edit") or
($input{'action'} eq "delete"))
{
&ReadFile();
&ChangeForm();
}
elsif ($input{'action'} eq "editnow")
{
&EditQuestion();
}
elsif ($input{'action'} eq "addnow")
{
&AddNewQuestion();
}
elsif ($input{'action'} eq "deletenow")
{
&DeleteQuestion();
}
elsif ($input{'action'} eq "order")
{
&ReadFile();
&ChangeOrder();
}
&Exit;
###############################
# change order of the questions
###############################
sub ChangeOrder
{
for ($i=1; $i<@questions; $i++)
{
if(not defined($input{$i}))
{
print "
Error: $i is undefined!
"; &Exit; } } for ($i=1; $i<=@questions; $i++) { $newquestions[$input{$i}] = @questions[$i]; $newanswers[$input{$i}] = @answers[$i]; } @questions = @newquestions; @answers = @newanswers; &CreateHtmlFile(); &Exit(); } ############################### # Add a new question ############################### sub AddNewQuestion { &ReadFile(); push(@questions, $input{'question'}); push(@answers, $input{'answer'}); &CreateHtmlFile(); &Exit(); } ############################### # Delete a question ############################### sub DeleteQuestion { &ReadFile(); for ($i=0; $i<@questions; $i++) { if($i != $input{'no'}) { push(@newquestions, $questions[$i]); push(@newanswers, $answers[$i]); } } @questions = @newquestions; @answers = @newanswers; &CreateHtmlFile(); &Exit(); } ############################### # Delete a question ############################### sub EditQuestion { &ReadFile(); for ($i=0; $i<@questions; $i++) { if($i == $input{'no'}) { $questions[$i] = $input{'question'}; $answers[$i] = $input{'answer'}; } } &CreateHtmlFile(); &Exit(); } ############################### # Parse the FAQ files ############################### sub ReadFile { &get_html_page(); foreach (@faqfile) { chomp; if($_ =~ m"" ) {$save=0; $end_start=1; next} elsif($_ =~ m"" ) {$save=1; $start_end=1; next;} elsif($_ =~ m"^" ) { $start_field=$1; next; } elsif($_ =~ m"^" ) { $start_field=0; next; } if($save) { if($_ =~ m"^" ) { $question_field=$1; next; } elsif($_ =~ m"^" ) { $question_field=0; next; } elsif($_ =~ m"^" ) { $answer_field=$1; next; } elsif($_ =~ m"^" ) { $answer_field=0; next; } if($question_field != 0) { $questions[$question_field] .= $_; next; } if($answer_field != 0) { $answers[$answer_field] .= $_; next; } } if(!$start_end){$before_faq .= "$_\n";} if($end_start){$after_faq .= "$_\n";} } } ############################### # List all questions for admin purposes ############################### sub List { my $question_lenght = 70; print "
\n";
print qq~
~;
}
}
###############################
# Footer of the pages
###############################
sub Exit
{
if(not $input{'image'} eq "nope")
{
if(defined($input{'action'}))
{
print qq~