#!/usr/bin/perl -w

use CGI;

my($request,$param_name,@param_names,%param);

$request = new CGI;
@param_names = ( 'new_newsgroup' );
foreach $param_name (@param_names) {
    $param{$param_name} = $request->param($param_name);
}
$newsgroup = $param{'new_newsgroup'};
$dir_name = $newsgroup;
$dir_name =~ s/\.//g;


## WRITE_CONF_FILE
##
sub write_conf_file
{
    $file_prefix = $newsgroup;
    $file_prefix =~ s/\./\_/g;
    copy('template.conf',$conf_file);
    $conf_file = $file_prefix.'.conf';
    open(CONF,'>>'.$conf_file);
    print CONF "\nNewsgroup\t\t$newsgroup\n";
    print CONF "\nFileNameOfArchive\t\t$file_prefix"."_messages.txt\n";
    print CONF "\nDirectoryForOutput\t\t$dirname\n";
    print CONF "\nMailingListAddress\t\t$newsgroup\n";
    print CONF "\nFileNameOfLog\t\t$file_prefix"."_log.txt\n";
    close(CONF);
}

    
## REWRITE_EXAMPLES_FILE
##
sub rewrite_examples_file
{
    my($example_file,$new_example_file,$line);
    $example_file = '/Library/WebServer/Agonistics/examples.html';
    $new_example_file = 'new_example.html';
    open(EXAMPLE,$example_file);
    open(NEW,'>'.$new_example_file);
    while($line = <EXAMPLE>) {
	chomp($line);
	print NEW $line."\n";
	if ( $line =~ /^add additional newsgroups/ ) {
	    print NEW '<a href="http://localhost/Agonistics/'.$dir_name.'/Interface/agon1.html">'.$newsgroup.'</a>'."\n";
	}
    }
    close(EXAMPLE);
    close(NEW);
    unlink($example_file);
    copy($new_example_file,$example_file);
    unline($new_example_file);
}






