#! /srvtools/http/bin/perl
#############################################################################
#
#   Copyright 1995 by the Northeast Parallel Architectures Center at 
#   Syracuse University and Global Business Network, Inc..
#  
#   File:         Preferences.pl
#
#   Authors:      Jungmin Kim and Paul Coddington (paulc@npac.syr.edu)
#
#   Created:      July 11 1995
#   Version: 
#
#   Description:  Subroutines of Change.pl to modify preferences for
#                 the configuration of each WeBBoard
#
#
#############################################################################


#############################################################################
#
#  ChangeOptions
# 
#############################################################################

sub ChangeOptions{
    local($user, $subdir, $file, $letter) = @_;

    $file = "< $webboardhome\/$subdir\/$check\/letter";

    if(open(INFILE,  $file)) {
	while(<INFILE>) {
	    $letter .= $_;
	}
	close(INFILE);
    }

print "Content-type: text/html\n\n\n ";
print "<TITLE> Change Preferences of the WeBBoard</TITLE>\n";
print "<H1> Change Preferences of the WeBBoard</H1>\n";

print "<HR><P>\n";
print "<FORM METHOD=\"POST\" ACTION=\"$change/$subdir\:changeopt\:$user\">\n";
print "<B>Cutoff</B> time for messages in days:\n";
print "<INPUT SIZE=5 NAME=\"cutoff\" VALUE=$cutoff><BR>\n";
print "<B>Range</B> of messages to be printed:\n";
print "<INPUT SIZE=5 NAME=\"range\" VALUE=$range><BR>\n";
print "<B>Authorization</B> for everyone to post a message:\n";
print "<INPUT SIZE=3 NAME=\"allow\" VALUE=$allow><BR>\n";
# print "<B>Automatic e-mail</B> for a reply:\n";
# print "<INPUT SIZE=3 NAME=\"autoreply\" VALUE=$autoreply><P>\n";
# print "<B>Message to be e-mailed</B><br>:\n";
# print "<TEXTAREA NAME=\"emailletter\" ROWS=2 COLS=50>";
# print "$letter</TEXTAREA><P>\n";

print "<P>\n";
print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
print "Click on this button to update the preferences.\n";
print "</FORM>\n";
print "<P>\n";
print "<HR>\n";

# Address and copyright
Address();

}
1;

#############################################################################
#
#  SaveOptions
# 
#############################################################################

sub SaveOptions{
    local($user, $subdir) = @_;
    local($file, $comm);
    
    $file = "$webboardhome\/$subdir\/$check\/global";
    # $comm = "rm $fcheckfile\/global";
    # system($comm); 

    open(OUTFILE, "> $file");
    print OUTFILE "cutoff $in{'cutoff'}\n";
    print OUTFILE "range $in{'range'}\n";
    print OUTFILE "allow $in{'allow'}\n";
    print OUTFILE "autoreply $in{'autoreply'}\n";
    close(OUTFILE);

    $file = "$webboardhome\/$subdir\/$check\/letter";
    open(OUTFILE, "> $file");
    print OUTFILE "$in{'emailletter'}\n";
    close(OUTFILE);

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

    print "<TITLE> CHANGE OPTIONS </TITLE>\n";
    print "<H1> Options have been changed</H1>\n";
    print "<IMG SRC=\"$gif/pointer.xbm\" ALIGN=\"left\" ALT=\"\">";
    print "<A HREF=\"$action/$subdir\:select\:\:\:${user}\">\n";
    print "<B>RETURN to the index of forums</B>\n";
    print "</A>\n";
    print "<P>\n";

# Address and copyright
Address();
}
1;


#############################################################################
#
#  ReadOptions
# 
#############################################################################

sub ReadOptions{
    local($glb, $letter);
    $glb = "< $webboardhome\/$in{'subdir'}\/$check/global";
    if( open(INFILE,  $glb)) {
	while(<INFILE>) {
	    chop;
	    /([^\s]*)\s+([^\s]*)/;
	    if ($1 eq "cutoff") {$cutoff = $2;}
	    elsif ($1 eq "range") {$range = $2;}
	    elsif ($1 eq "allow") {$allow = $2;}
	    elsif ($1 eq "autoreply") {$autoreply = $2;}

	}
    }
}
1;

