#! /usr/bin/perl -w

# List the messages in a user's log directory

# Copyright (c) 2003 by Rhyolite Software
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE
# BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
#	Rhyolite Software DCC 1.2.7-1.3 $Revision$
#	Generated automatically from list-log.in by configure.

# This file must protected with an equivalent to httpd.conf lines
#   in the README file.


use strict 'subs';

my($total_msgs, $msg, $next_date, $last_date, $now);

# get DCC parameters
local($list_msg_link, $user_dir);		# quiet -w warnings
do('/var/www/dcc-bin/common') || die("could not get DCC configuration: $!\n");

get_query();

local(%msgs_from, %msgs_subject);		# quiet -w warnings
get_log_msgs();

html_head("Messages Logged for $user at $hostname");

$total_msgs = keys %msgs_mtime;
if ($total_msgs) {
    print "<H3>$total_msgs messages logged for <EM>$user</EM> at $hostname</H3>\n<P>\n";
} else {
    print "<H3>No messages logged for <EM>$user</EM> at $hostname</H3>\n<P>\n";
}
print "<P class=warn><B>\n";
print $query{'result'} ? html_str_encode($query{'result'}) : "&nbsp;";
print "</B>\n<P>";
common_buttons();
print "</TABLE>\n";

if ($total_msgs) {
    print <<EOF;
<P>
<TABLE   border=1 cellpadding="2%"
    summary="messages logged for $user at $hostname">
<CAPTION><B>$total_msgs Messages</B></CAPTION>
EOF

    foreach $msg (sort {$msgs_mtime{$b} <=> $msgs_mtime{$a}}
		  keys %msgs_mtime) {
	$next_date = $msgs_date{$msg};
	$next_date =~ s/(.*) .*/$1/;
	if (! $last_date) {
	    print "<TR><TH>Message<TH>$next_date<TH>Author<TH>Subject\n";
	} elsif ($last_date ne $next_date) {
	    print "<TR><TH>&nbsp;<TH>$next_date<TH>&nbsp;<TH>&nbsp;\n";
	}
	$last_date = $next_date;

	print <<EOF;
<TR><TD class=mono>$list_msg_link?msg=$msg">$msg</A>
    <TD class=mono>$msgs_date{$msg}
    <TD>$msgs_from{$msg}
    <TD>$msgs_subject{$msg}
EOF
    }
    print "</TABLE>\n";
}

print <<EOF;
</BODY>
</HTML>
EOF


# re-enable mail notifications
unlink("$user_dir/notify.marker", "$user_dir/notify.pending",
       "$user_dir/notify.block");
close(MARK)
    if (open(MARK, "> $user_dir/notify.marker"));
