#!/bin/perl

require "ADMIN/config";

use lib '..';
use CGI;
$query = new CGI;

if ($get_args = $query->param('keywords')) {
    ($thread,$message) = split(/,/,$get_args,2);

# get the original post to insert into the reply
    open(DATAFILE,"DATA/$thread.th");
    $x = -1;
    while(<DATAFILE>) {
	$x++;
	if ($x == $message) {
	    ($title,$junk) = split(/\t/,$_,2);
	    last;
	}
    }

# don't put 'Re:' in front of the title if it's already there from
# a previous reply
    if (!($title =~ /^Re: /)) {
	$title = "Re: $title";
    }

    $html_field = qq(
Use your own HTML formatting?: 
<INPUT TYPE="radio" NAME="html" VALUE="y"> Yes
<INPUT TYPE="radio" NAME="html" VALUE="n" CHECKED> No
		     <BR>);

    $prev_field = qq(
<BR>Preview the message?:
<INPUT TYPE="radio" NAME="preview" VALUE="y"> Yes
<INPUT TYPE="radio" NAME="preview" VALUE="n" CHECKED> No
		     <P>);


    print "Content-type: text/html\n\n";

    open(TEMPLATE,"TEMPLATES/add.html");
    while(<TEMPLATE>) {
        s/\<TEXTAREA/$html_field<BR><TEXTAREA/;
        s/\<\/TEXTAREA\>/\<\/TEXTAREA\>$prev_field/;
	s/NAME\=\"title\"/NAME\=\"title\" VALUE\=\"$title\"/io;
	print;
	if (/\<FORM/) {
	    print "<INPUT TYPE=\"hidden\" NAME=\"thread\" VALUE=\"$thread\">\n";
	}
    }
}
else {
    print "Content-type: text/html\n\nThere is no message to reply to.\n";
}





