#! c:/perl/bin/perl # # maillist.cgi # Display matrix csv file with various format. # # 1.0 : 7/31/05 : Cleaned up for release # # $Id: maillist.cgi,v 1.3 2005/09/25 05:12:00 Hideki Kanayama Exp $ use File::Basename; #use CGI::Carp qw(fatalsToBrowser); $lastupdatedyear = 2005; $version = "1.0"; $script = basename($0); $setupfile = "maillist_setup.pl"; ##################################### # Page title $title = 'Maillist'; # Data file name $datafile = "maillist.csv"; # Back link 1:on 0:off $back_en = 1; $back = "../maillist.html"; # Back ground $bgcolor = 'white'; # Default display category # The right hand side next to the name:1, next to that:2 $default_menu = 1; # Menu item number to be displayed in one line $menu_cr = 10; $all1_name = "All1"; $all2_name = "All2"; $menu_back = "gray"; $menu_front = "white"; # style sheet 1:on 0:off $style_sheet_en = 1; $style_sheet = ' A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} '; # Insert sentences in 〜 1:on, 0:off $head_insert_en = 0; $head_insert = ''; # Time offset from GMTd Japan:+9 $offset = 9; #################################### require "$setupfile" if (-e "$setupfile"); $firsttitle = "Title"; $firstlink = "Link"; %link_prefix = ( mail => "mailto:", web => "http://", link => '', none => '', ); %in = &parsedata; &htmlhead($title); print "
\n"; print "

$title

\n"; print "back

\n" if ($back_en == 1); ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat $datafile; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($mtime + $offset*3600); printf("%2d/%2d/%4d %2d:%02d

\n",$mon+1,$mday,$year+1900,$hour,$min); $default_menu = 1 if ($default_menu < 1); $in{mode} = --$default_menu unless (exists $in{mode}); $title_flag = ''; $link_flag = ''; open(FILE,"< $datafile") || &error("データファイル$datafileが開けません"); while (){ chomp; next if /^\s*#/; next if /^\s*$/; @line = split /,/; if (/^\s*$firsttitle/ and $title_flag ne done) { shift @line; $cols = $#line + 1; print qq{\n} if ($title_flag ne done); $i = 0; foreach (@line){ s/^\s*//; s/\s*$//; if ($in{mode} !~ /^\d/ or $i ne $in{mode}) { print qq{\n}; } else { print qq{ }; } print "\n\n" if ($i != 0 and ($i+1) % $menu_cr == 0); $i++; } if ($in{mode} ne all1) { print qq{\n}; } else { print qq{\n}; } print "\n\n" if ($i != 0 and ($i+1) % $menu_cr == 0); if ($in{mode} ne all2) { print qq{\n}; } else { print qq{\n}; } print qq{
$_$_
$all1_name$all1_name
$all2_name$all2_name
} if ($title_flag ne done); @titlelist = @line; $title_flag = done; } elsif (/^\s*$firstlink/ and $link_flag ne done){ shift @line; foreach (@line){s/^\s*//; s/\s*$//;} @linklist = @line; $link_flag = done; } last if ($title_flag eq done and $link_flag eq done); } close(FILE); print "

\n"; if ($in{mode} =~ /^\d/ or $in{mode} eq all1) { print "\n"; } else { $cols=$#titlelist+1; print "
\n"; print "\n"; for ($i=0;$i<=$cols;$i++){ if ($i == 0){ print "\n"; } else { print "\n"; } } print "\n"; } open(FILE,"< $datafile") || &error("Cannot open $datafile"); while (){ chomp; next if /^\s*#/; next if /^\s*$/; @line = split /,/; foreach (@line) {s/^\s*//;s/\s*$//;} $addr = ''; if (!/^\s*$firsttitle/ and !/^\s*$firstlink/) { $name = shift @line; $name =~ s/^\s*//; $name =~ s/\s*$//; next if ($#line == -1); if ($in{mode} eq all1){ print "\n"; print "\n"; print "\n"; } elsif ($in{mode} eq all2){ print "\n"; print "\n"; for ($i=0;$i<=$cols-1;$i++){ if ($line[$i] =~ /^(\d+)$/){ $ref = $1 - 1; } else { $ref = $i; } $addr = $line[$ref]; if ($addr eq '' or $#line == -1){ print "\n"; } elsif ($linklist[$i] eq none or $linklist[$i] eq ''){ print "\n"; } else { print "\n"; } } print "\n"; } else { if ($line[$in{mode}] =~ /^(\d+)$/){ $ref = $1 - 1; } else { $ref = $in{mode}; } $addr = $line[$ref]; next if ($addr eq ''); print "\n"; print "\n"; if ($linklist[$in{mode}] eq none or $linklist[$in{mode}] eq ''){ print "\n"; } else { print "\n"; } print "\n"; } } } close(FILE); print "
 $titlelist[$i-1]
$name\n"; print "\n"; $wrote = 0; for ($i=0;$i<=$#line;$i++){ if ($line[$i] =~ /^(\d+)$/){ $ref = $1 - 1; } else { $ref = $i; } $addr = $line[$ref]; next if ($addr eq ''); print "\n"; print "\n"; if ($linklist[$i] eq none or $linklist[$i] eq ''){ print "\n"; } else { print "\n"; } print "\n"; $wrote = 1; } print "\n" if ($wrote == 0); print "
$titlelist[$i]:$addr$addr
 
\n"; print "
$name $addr$addr
$name$addr$addr
\n"; print "

\n"; &htmltail; sub parsedata { if ($ENV{"REQUEST_METHOD"} eq "GET"){ $data=$ENV{"QUERY_STRING"}; $method = 'GET'; } elsif ($ENV{"REQUEST_METHOD"} eq "POST"){ read(STDIN,$data,$ENV{"CONTENT_LENGTH"}); $method = 'POST' } @tmparray=split(/&/,$data); foreach $string (@tmparray){ ($key,$value)=split(/=/,$string); $in{"$key"}=$value; } return(%in); } sub htmlhead { my $title = shift; $bgimage = "bgcolor=\"$bgcolor\""; print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "$title\n"; if ($head_insert_en == 1){ print "$head_insert\n"; } if ($style_sheet_en == 1){ print "\n"; } print "\n"; print "\n"; } sub htmltail { print "
$script Ver. $version
\n"; print "
Copyright(C) 2002-$lastupdatedyear, Hideki
\n"; print "\n"; } sub error { my ($msg) = shift; unlink("$lockfile"); &htmlhead($msg); print "
$msg
\n"; &htmltail; exit; }