#! /srvtools/http/bin/perl
#############################################################################
#  
#   File:        PrintHeader.pl
#
#   Author:      Jungmin Kim
#
#   Created:     03/05/95
#   Modified: 
#   Version: 
#
#   Input:       path name, file name, user information, 
#                address of array
#   Output:      HTML text
#          
#
#   Description: Print out headers of messages in the directory 'path name'.
#                If a message is a reply or reply of the reply .. of 
#                'file name', add the message into the array passed.
#
#############################################################################

require "GetDate.pl";

sub PrintHeader{
    # ************************************************************* modified
    local($dir, $no, $user, $subdir, *array) = @_;
    local($number, $date, $name, $title, $tno, $temp, $prefix, $filename);
    # **********************************************************************

    $filename = "$webboardhome/$subdir/$dir/$index";

    open(INFILE,"< $filename") ||
	print "Content-type\: text/html\n\n\n Cannot open $filename\: $!";
    print "<pre>";
    while(<INFILE>) {

        # separator for each field is eot(\005) ****************** modified
	($number, $date, $name, $title) = split(/\005/, $_);

	# replace <BR> and <P> with a space
	$temp = $title;
	$title =~ s/\<P\>/ /ig;
	$title =~ s/\<BR\>/ /ig;
        # *****************************************************************

	$number =~ /^([0-9]+).*/;
	$prefix = $1;
	#### if there is no file name passed, take last message.
	$no = $prefix if $no eq "";

	#### if the prefix of the file name is matched, add it to array
	if ($prefix > $no - $range && $prefix < $no + $range) {
	    # separator is eot(\005) ***************************** modified
	    $array{$number} = "$date\005$name\005$temp";
	    # *************************************************************
        }

        next if &CutoffDate($date); #***************************** modified

        $number =~ /^([0-9]+).*/;
        $tno = $1;                 # prefix of file name (root message)

	chop($title);
        $title = substr($title, 0, 50);   # Crop the title length
	$title .= "</A>";
        $url = "<A HREF=\"$action/$subdir\:read\:${dir}\:${tno}\:${user}#${number}\">"; 
      printf("%-8s %-8s %s%-54s  %-20s\n", $number, $date, $url, $title, $name);
    }
    close(INFILE);		       
    print "</pre>";
}
1;

# Figure out if the date of the message is within the cutoff date:
# 1 means no
sub CutoffDate
{
    local($docdate) = @_;
    local($month, $date, $cmonth, $cdate, $cutdate);

    # get the cutoff date
    $cutdate = &GetDate($cutoff*24*3600);
    
    ($cmonth, $cdate, $cyear) = split(/\//, $cutdate);
    ($month, $date, $year) = split(/\//, $docdate);

#print "$month **** $cmonth $cutdate <p>";
#print "ll <P>" if $month == $cmonth;

    # Sort out the year
    if ($year) {
      $yeardiff = $year - $cyear;
    }
    else {
      $yeardiff = 0;
    }
    return 0 if $month == $cmonth && $date >= $cdate && $yeardiff == 0;
    return 0 if $month == $cmonth + 1 && $yeardiff == 0;
    return 0 if $month == 1 && $cmonth == 12 && $yeardiff == 1;
    1;
}
1;
