#!/usr/bin/perl -w
#
# reads/parses the ASCII based (UTF-8 extended) file dml_items and
# transforms the data into several html lists.
# Author: Ulf Rehmann <rehmann@math.uni-bielefeld.de> 
# (Copyright 2003-2013)
# Version 0.3 (07.01.2012)
# 

use strict;

use locale;
use POSIX qw(locale_h);
setlocale(LC_CTYPE, qw(en_US.UTF-8));
# The following gives a wrong ordering for the Leibniz entries:
#setlocale(LC_COLLATE, qw(de_DE.ISO_8859-1));

my $stamp = '20130101';
my $new = "";
if ($stamp =~ /(\d\d\d\d)(\d\d)(\d\d)/ ) {
    $new = sprintf("<table border bgcolor=\"#ffffff\"><tr><td bgcolor=\"#ffff00\">
<a href=\"./dml_new.html\">New items here since %d. %d. %4d, most recent first</a></td><td> </td><td> <a href=\"./dml_links.html\">Start</a> </td></tr></table>",$3,$2,$1);
}

undef $/;
open(F,"./dml_items");
my $f = <F>;
close(F);
#$f =~ s/\\\#/___sharp___/sg;
$f =~ s/\n\#.*?\n/\n/sg;  # removing comment lines
#$f =~ s/___sharp___/\#/g;

$f =~ s/\,([^ ])/\, $1/g;

my @rep = split /nick:/, $f;

my $debug=0;
# put the repository into each item, collect the items in @A:
my @A = (); # Array of all items
foreach(@rep) {
    next if ( !/([A-z\-\*]+).*?\n(.*?\ncomm:.*?\n)(.*)/sg ); 
    #my ($n,$r,$i) = ($1,$2,$3);

    my $thisrep = "nick:$1\n".$2;  # put repository data into each item

    my @items = split /item_end:.*\n/, $3;
    foreach(@items) {
	if ($thisrep =~ /Gallica/) {
	    #print ">>>".$thisrep."$_\n";
	}
	push @A, $thisrep.$_;
##	if (/Japan/) { print $thisrep.$_; }
    }
}

# collect the stuff for each entry in %H:

sub pg{ # determines last number in a string like '324 p. xdc 675 p'
    my $t = $_[0];
    my $nr = 0;
    $nr  = $1 if ( $t  =~ /.*?(\d+)(, \[\d+\])* *p\.$/ );
    $nr -= $1 if ( $nr =~ /\d/ && $t =~ /\[*(\d+)\]*\-$nr/ );
    return $nr;
}

my %J = ();
my %keys = ();  # this keeps track of all occuring keys
#counters:
my $books=0;
my $bpages=0;
my $journals=0;
my $jpages=0;
my $errs=0;
my $cc=0;
foreach(@A) { # look at each item
    my $typ=0;

    if (/item_type: *book/ || /item_type: *multi/) {
	$typ=1;
    } elsif (/item_type: *journal/ ||  /item_type: *seminar/) {
	$typ=2;
    }
  # Hash of item components of given item"  $H{item_title} = <title> etc.
    my %H = ();
    $H{item_meta} = $_;
    my @B = split /\n/, $_; 
    foreach(@B) {
	next if ( ! /(\w+):(.*)/ );
	my $x = $1;
	my $y = $2;
	$y =~ s/^[\s\xa0]*//; # in data from Gallica, xa0 seems to occur
	$y =~ s/ *$//;
	if (/item_url/) {
	    $y =~ s/&(amp;)*/&amp;/g;
	    $y =~ s/^.*?http/http/;
	}
	$H{$x}=$y;
	if (/item_type: *book/ || /item_type: *multi/) {
	    $books++;
	} elsif (/item_type: *journal/  ||  /item_type: *seminar/ ) {
	    $journals++; 
	}
## this is much too complicated:
	if ($x =~ /item_pag/ && $typ==1 && &pg($y) =~ /\d/) {
	    $bpages+=&pg($y);
	}
	if ($x =~ /item_pag/ && $typ==2 && &pg($y) =~ /\d/) {
	    $jpages+=&pg($y);
	}
	$H{$x} =~ s/ +$//;
	$keys{$x} = "ok";
	$x=$y="";
	#if (/Bossut/ ) { print "$H{item_title}\n";}
    }
    if ( ! exists $H{item_title}) {
	if ( ! exists $H{comm} ) {
	    $errs++;
	    print "$errs : No Title:\n";
	    print;
	}
    } else {
	my $ttt = 0;
	foreach(keys %H) {
	    # install item:
	    # take care of multiple items with same title
            #  (should be a better solution!) 
	    if ( exists $H{$_}) {
		if (/Japan/) { print;}
		while ( $ttt == 0 && exists $J{$H{item_title}} ) {
		    $H{item_title} .= " *"; 
		    #print "$H{item_title}\n";
		}
		$ttt = 1;
		$J{$H{item_title}}{$_} = $H{$_};
	    } else {
		$J{$H{item_title}}{$_} ="";
	    }
	    if (/item_title/) {
		$J{$H{item_title}}{count}++;
	    }
	}
    }
}

my %X = ();
# all keys should occur for each $J{$k}
foreach(keys %J) {
    my $k = $_;
    foreach(keys %keys) {
#	print ">>>$_\n";
	my $kk = $_;
	if ( ! exists $J{$k}{$kk} ) {
	    if ( $kk =~ /item_stamp/ ) {
		$J{$k}{$kk} = $stamp;
	    } else {
		$J{$k}{$kk} = " ";
		$X{$kk}++;
	    }
	}
    }
#    print "\n\n";
}

# printout all keys like "item_title etc.
#foreach(sort keys %X) { printf("%-20s %5d\n",$_,$X{$_}); }

my @books    = (0,0);
my @journals = (0,0);
my %R = ();
foreach(keys %J) {
    my $nick = $J{$_}{nick};
    if ($J{$_}{count} > 1 ) { print "$J{$_}{item_title} $J{$_}{count}\n"; }
    if ($J{$_}{item_type} =~ /book/ ||$J{$_}{item_type} =~ /multi/ ) {
	$R{$nick}{number_of_books}++;
	$books[0]++;
	$R{$nick}{pages_of_books} += &pg($J{$_}{item_pag});
	$R{$nick}{all_pages} += &pg($J{$_}{item_pag});
	$books[1]+= &pg($J{$_}{item_pag});
    } elsif ($J{$_}{item_type} =~ /journal/ || $J{$_}{item_type} =~ /seminar/) {
	$R{$nick}{number_of_journals}++;
	$journals[0]++;
	$R{$nick}{pages_of_journals} += &pg($J{$_}{item_pag});
	$R{$nick}{all_pages} += &pg($J{$_}{item_pag});
	$journals[1]+= &pg($J{$_}{item_pag});
    }
    $R{$nick}{name} = $J{$_}{name};
    $R{$nick}{addr} = $J{$_}{addr};
}


### Header of most html pages :------------------------------------------------------------
my $pre = << 'END_PRE';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="DC.Description"       content="DML Digital Mathematics Library Retrodigitized Mathematics Journals and Monographs">
<meta name="DC.Description"       content="DML Digital Mathematical Library Retrodigitized Mathematics Journals and Monographs">
<meta name="DC.Description"       content="WDML World Digital Mathematics Library Retrodigitized Mathematics Journals and Monographs">
<meta name="keywords" content="Digital Mathematics Library">
<meta name="keywords" content="Digital Mathematics Registry">
<meta name="keywords" content="World Digital Mathematics Library">
<meta name="keywords" content="World Digital Mathematical Registry">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DML: Digital Mathematics Library: Retrodigitized Mathematics Journals and Monographs</title>
<link rel="alternate" type="application/rss+xml"
   title="RSS" href="./dml_links_feed.rss">
</head>
<body>
<center>
<a href="./dml_links.html"><font size=5><b>DML: Digital Mathematics Library</b></font></a><br>
<b>Also: WDML: World Digital Mathematics Library</b><p>
<b>Retrodigitized Mathematics Journals and Monographs</b>
<p>__DT__<p>
Contains links to ___BOOKS___ digitized books (> ___BPAGES___ pages )<br> and to ___JOURNALS___
digitized journals/seminars (> ___JPAGES___ pages).<br>
(Numbers of pages are preliminary; not all informations are already available.)<p>


Includes all the links mentioned on page 920 of:
Allyn Jackson, "The Digital Mathematics Library",<br>
<a href="http://www.ams.org/notices/200308/200308-toc.html">
Notices Amer. Math. Soc., vol. 50 (8), 2003</a> 
[<a href="./Articles/ams_notices.50.8_Sep_2003.pdf">Local Copy</a>]<br>
A similar list is offered at <a href="http://www.wdml.org">http://www.wdml.org</a>.<p>


The database for this table is an ASCII based 
(UTF-8 extended) <a href="dml_items">list</a>, 
which may be parsed by <a href="dml_mk_links_pl">this PERL script</a>.<br>

If you want items to be added here,
please send <a href="mailto:rehmann@math.uni-bielefeld.de">me [rehmann@math.uni-bielefeld.de]</a> the necessary
data.<p> 


Lists ordered by "Journal", "Repository" (Journals only) or by "Author
name", "Title" are provided, as well as an<br> <a
href="dml_links_total_repositories_ordered.html">overview of the
repositories</a>. <p>

<form method=GET action="http://www.google.de/search">
	<p>Google search for this registry:<br>
	<input TYPE=text name=q size=40 maxlength=255 value="">
	<input type=hidden name=q
	VALUE="site:www.math.uni-bielefeld.de OR site:www.mathematik.uni-bielefeld.de inurl:~rehmann/DML/">
        </p>
</form>

<table>
<tr>
<th align="left"><b>Author:</b></th><th>[___AU_LINKS___]</th>
</tr>
<tr>
<th align="left"><b>Title:</b></th><th>[___TI_LINKS___]</th>
</tr>
</table> 
</center>
<p>
<center>
Remark: Repositories marked by '*' require paid subscription.
</center>
<p>

<center>
<table border>
<tr><th align="center">Nr.</th>
<th align="center"><a href="./dml_links_repositories.html">Repository:</a></th>
<th align="center">___TTT___:</th>
<th align="center">Pages:</th>
<th align="center">Year(s):</th>
<th align="center">Type:</th></tr>
END_PRE

my $rss='<?xml version="1.0" encoding="utf-8"?>
 
<rss version="2.0">
 
  <channel>
    <title>DML: Digital Mathematics Library</title>
    <link>http://www.math.uni-bielefeld.de/~rehmann/DML/dml_links.html</link>
    <language>en-en</language>
      <pubDate>__Date__</pubDate>
    <copyright>Ulf Rehmann</copyright>
    <item>
      <title>New Entries __Date__</title>
      <link>http://www.math.uni-bielefeld.de/~rehmann/DML/dml_new.html</link>
      <author>Ulf Rehmann rehmann@math.uni-bielefeld.de</author>
      <pubDate>__Date__</pubDate>
    </item>
   </channel>
 
</rss>
';


### End of header of html pages ---------------------------------------------------------------------

if (exists $ARGV[0] && $ARGV[0] =~ /new/) {
    my $date = `date`;
    $rss =~ s/__Date__/$date/sg;
    open(F,">dml_links_feed.rss");
    print F $rss;
    close F;
}

$pre =~ s/__DT__/$new/;
    
my $title_links="";
my $author_links="";

my @Z = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
foreach(@Z) {
    $title_links .="\<a href=\"\.\/dml_links_title_$_\.html\"\>$_\<\/a\> | \n";
    $author_links.="\<a href=\"\.\/dml_links_author_$_\.html\"\>$_\<\/a\> | \n";
}
$title_links=~s/\| \n$//s;
$author_links=~s/\| \n$//s;

$pre =~ s/___AU_LINKS___/$author_links/;
$pre =~ s/___TI_LINKS___/$title_links/;

### Trailer of html pages ---------------------------------------------------------------------------    
my $post = << 'END_POST';
</table>

<hr>
<address>
<a href="http://validator.w3.org/check/referer"><img border="0"
   src="http://www.w3.org/Icons/valid-html401"
   align=right alt="Valid HTML 4.01!" height="31" width="88"></a>
&copy; 2003 -- __THISYEAR__
<a href="mailto:rehmann@mathematik.uni-bielefeld.de">Ulf Rehmann</a>
Fakult&auml;t f&uuml;r Mathematik, Universit&auml;t Bielefeld, Germany
</address>
</center>
</body>
</html>
END_POST
### End of Trailer of html pages --------------------------------------------------------------------


my $thisyear = `date +%Y`; chop $thisyear;

$post =~ s/__THISYEAR__/$thisyear/;

$pre =~ s/___BOOKS___/$books/sg;
$pre =~ s/___BPAGES___/$bpages/sg;
$pre =~ s/___JOURNALS___/$journals[0]/sg;
$pre =~ s/___JPAGES___/$journals[1]/sg;

sub uc_sort {
    my $x = $_[0];
    $x =~ s/^\s*[Tt]he\s+//;
    $x =~ s/^\s*[Aa]n*\s+//;
    return uc($x);
}

#-------------- journals: sort by title
my $pre1=$pre;
$pre1 =~ s/___TTT___/<a href=\"dml_links.html\">Journal<\/a>/sg;
my @BA = sort { &uc_sort($J{$a}{item_title}) cmp &uc_sort(${J}{$b}{item_title}) } keys %J;
open(F,">dml_links.html");
print F $pre1;
my $count=0;
foreach(@BA) {
    next if ($J{$_}{item_type} !~ /journal/ && $J{$_}{item_type} !~ /seminar/ );
    my $a = "";
    if ( $J{$_}{item_author} =~ /\w/) {
	$a = "(by $J{$_}{item_author})";
    } 
    my $p=&pg($J{$_}{item_pag});
    if ($p == 0) { $p = " ";}
    $count++;
    print F "<tr>
<td align=\"center\">$count</td>
<td align=\"center\"><a href=\"$J{$_}{addr}\">$J{$_}{nick}</a>: ($J{$_}{name})</td>
<td align=\"left\"><a href=\"$J{$_}{item_url}\">$J{$_}{item_title}</a> 
$a $J{$_}{comm}</td>
<td align=\"center\">$p</td>
<td align=\"center\">$J{$_}{item_years}</td>
<td align=\"center\">$J{$_}{item_type}</td>
</tr>";
}
print F $post;
close F;
#-------------- journals: sort by repository
$pre1=$pre;
$pre1 =~ s/___TTT___/<a href=\"dml_links.html\">Journal<\/a>/sg;
@BA = sort { uc($J{$a}{name}) cmp uc(${J}{$b}{name})
       || &uc_sort($J{$a}{item_title}) cmp &uc_sort(${J}{$b}{item_title}) } keys %J;
open(F,">dml_links_repositories.html");
print F $pre1;
$count=0;
foreach(@BA) {
    next if ($J{$_}{item_type} !~ /journal/ && $J{$_}{item_type} !~ /seminar/ );
    my $a = "";
    if ( $J{$_}{item_author} =~ /\w/) {
	$a = "(by $J{$_}{item_author})";
    } 
    my $p=&pg($J{$_}{item_pag});
    if ($p == 0) { $p = " ";}
    $count++;
    print F "<tr>
<td align=\"center\">$count</td>
<td align=\"center\"><a href=\"$J{$_}{addr}\">$J{$_}{nick}</a>: ($J{$_}{name})</td>
<td align=\"left\"><a href=\"$J{$_}{item_url}\">$J{$_}{item_title}</a> 
$a $J{$_}{comm}</td>
<td align=\"center\">$p</td>
<td align=\"center\">$J{$_}{item_years}</td>
<td align=\"center\">$J{$_}{item_type}</td>
</tr>";
}
print F $post;
close F;
#-------------- sort by type
$pre1 = $pre;
$pre1 =~ s/___TTT___/Journal/sg;
my @BB = sort { uc($J{$a}{item_type}) cmp uc(${J}{$b}{item_type})
       || &uc_sort($J{$a}{item_title}) cmp &uc_sort(${J}{$b}{item_title}) } keys %J;
open(F,">dml_links_type.html");
print F $pre1;
$count=0;
foreach(@BB) {
    next if ($J{$_}{item_type} =~ /book/);
    $count++;
    my $a = "";
    if ( $J{$_}{item_author} =~ /\w/ ) {
	$a = "(by $J{$_}{item_author})";
    }
    my $p=&pg($J{$_}{item_pag});
    if ($p == 0) { $p = " ";}
    print F "<tr>
<td align=\"center\">$count</td>
<td align=\"center\"><a href=\"$J{$_}{addr}\">$J{$_}{nick}</a>: ($J{$_}{name})</td>
<td align=\"left\"><a href=\"$J{$_}{item_url}\">$J{$_}{item_title}</a> 
$a $J{$_}{comm}</td>
<td align=\"center\">$p</td>
<td align=\"center\">$J{$_}{item_years}</td>
<td align=\"center\">$J{$_}{item_type}</td>
</tr>";
}
print F $post;
close F;

#-------------- sort by title 
$pre1 = $pre;
$pre1 =~ s/___TTT___/Title, Author/sg;
my @BC = sort { &uc_sort($J{$a}{item_title}) cmp &uc_sort(${J}{$b}{item_title}) } keys %J;
foreach(@Z) {
    my $z=$_;
    open(F,">dml_links_title_$z.html");
    print F $pre1;
    $count=0;
    foreach(@BC) {
	next if (&uc_sort($J{$_}{item_title}) !~ /^ *$z/ );
	my $a = "";
	if ( $J{$_}{item_author} =~ /\w/ ) { 
	    $a = "(by $J{$_}{item_author})";
	}
	my $p = &pg($J{$_}{item_pag});
	if ($p == 0) { $p = " ";}
	$count++;
	print F "<tr>
<td align=\"center\">$count</td>
<td align=\"center\"><a href=\"$J{$_}{addr}\">$J{$_}{nick}</a></td>
<td align=\"left\"><a href=\"$J{$_}{item_url}\">\<b\>$J{$_}{item_title}\<\/b\></a> 
$a $J{$_}{comm}</td>
<td align=\"center\">$p</td>
<td align=\"center\">$J{$_}{item_years}</td>
<td align=\"center\">$J{$_}{item_type}</td>
</tr>";
    }
    print F $post;
    close F;
}

#-------------- sort by author
$pre1 = $pre;
$pre1 =~ s/___TTT___/Author, Title (Books only)/sg;
my @BD = sort { ($J{$a}{item_author} cmp ${J}{$b}{item_author}) || ($a cmp $b) } keys %J;

foreach(@Z) {
    my $z = $_;
    open(F,">dml_links_author_$z.html");
    print F $pre1;
    $count=0;
    foreach(@BD) {
	my $a = "";
	next if ($J{$_}{item_author} !~ /^ *$z/ );
	if ( $J{$_}{item_author} =~ /\w/) {
	    $a = "\<b\>$J{$_}{item_author}\<\/b\>: ";
	} else { next;}
	my $p;
	$p = &pg( $J{$_}{item_pag} );
	if (!$p) { $p="";}
	##my $x = uc($_);
	##print "$J{$_}{item_author}:$_\n" if ($J{$_}{item_title} =~ /Reihe +[iIV]/);
	$count++;
	print F "<tr>
<td align=\"center\">$count</td>
<td align=\"center\"><a href=\"$J{$_}{addr}\">$J{$_}{nick}</a></td>
<td align=\"left\"><a href=\"$J{$_}{item_url}\">$a $J{$_}{item_title}</a> 
$J{$_}{comm}</td>
<td align=\"center\">$p</td>
<td align=\"center\">$J{$_}{item_years}</td>
<td align=\"center\">$J{$_}{item_type}</td>
</tr>";
    }
    print F $post;
    close F;
}

$pre1 = $pre;
$pre1 =~ s/Includes all the .*//sg;

### Header2 of Repository page ----------------------------------------------------------
my $pre2 = << 'END_PRE2';
<a href="./dml_links_repositories.html">Back to Title Page</a><p>
<p>
<center>
Remark: Repositories marked by '*' require paid subscription.
</center>
<p>
<table border>
<tr><th align="center"></th>
<th align=center>Overview of Repositories:</th>
<th align="center">Number of Books</th>
<th align="center">Number of Journals</th>
<th align="center">Number of Pages</th>
<th align="center"></th></tr>
END_PRE2
### End of Header2 ---------------------------------------------------------------------

$pre1 .= $pre2;
$pre1 =~ s/___TTT___/Repositories/sg;

open(F, ">dml_links_total_repositories.html");
print F $pre1;

my $na = "-";

foreach(sort keys %R) {
    if (! exists $R{$_}{all_pages} ) {
	$R{$_}{all_pages} = 0;
    }
    if (! exists $R{$_}{pages_of_books} || $R{$_}{pages_of_books}==0) {
	$R{$_}{pages_of_books} = "$na";
    } 
    if (! exists $R{$_}{number_of_books} || $R{$_}{number_of_books}==0 ) {
	$R{$_}{number_of_books} = "$na";
    }
    if (! exists $R{$_}{pages_of_journals} || $R{$_}{pages_of_journals}==0 ) {
	$R{$_}{pages_of_journals} = "$na";
    } 
    if (! exists $R{$_}{number_of_journals} || $R{$_}{number_of_journals}==0) {
	$R{$_}{number_of_journals} = "$na";
    }
    my $pg = $na; 
    if ($R{$_}{all_pages} != 0) {
	$pg = $R{$_}{all_pages};
    } 
    print F "<tr>
<td align=\"left\">$_</td>
<a href=\"$R{$_}{addr}\">$R{$_}{name}</a></td>
<td align=\"center\">$R{$_}{number_of_books}</td>
<td align=\"center\">$R{$_}{number_of_journals}</td>
<td align=\"center\">$pg</td>
</tr>";
}
   printf("%-20s :: %5d : %10d, %5d : %10d\n", "Total",
   	   $books[0],$books[1],$journals[0],$journals[1]);
print F $post; close F;


$pre1 =~ s/___TTT___/Repositories/sg;

open(F, ">dml_links_total_repositories_ordered.html");
print F $pre1;

#my @SR = sort { $R{$b}{all_pages} <=> $R{$a}{all_pages} } keys %R;
my @SR = sort { uc($R{$a}{name}) cmp uc($R{$b}{name}) } keys %R;
my $nr = 0;
foreach(@SR) {
    $nr++;
    my $pg = $na; 
    if ($R{$_}{all_pages} != 0) {
	$pg = $R{$_}{all_pages};
    }
    print F "<tr>
<td align=\"left\">$nr. $_</td>
<td><a href=\"$R{$_}{addr}\">$R{$_}{name}</a></td>
<td align=\"center\">$R{$_}{number_of_books}</td>
<td align=\"center\">$R{$_}{number_of_journals}</td>
<td align=\"center\">$pg</td>
</tr>";
}
print F $post; close F;

#-------------- new things

$pre1 = $pre;
$pre1 =~ s/Contains links to .*//sg;
### Header3 of news page --------------------------------------------------------------
my $pre3 = << 'END_PRE3';
<table border>
<tr><th align="center">New here since (nr):</th>
<th align=center>Repository:</th>
<th align="center">Title/Journal:</th>
<th align="center">Pages:</th>
<th align="center">Years:</th>
<th align="center">Type:</th></tr>
END_PRE3
$pre3 =~ s/__DT__/$new/;
### End of Header3 ---------------------------------------------------------------------
$pre1 .= $pre3;

foreach(keys %J) {
    next if exists $J{$_}{item_name};
    $J{$_}{item_name} = "";
}

@BA = sort {  
        uc($J{$b}{item_stamp}) cmp uc(${J}{$a}{item_stamp}) 
	    || uc($J{$a}{item_name}) cmp uc(${J}{$b}{item_name}) 
	    || uc($J{$a}{item_author}) cmp uc(${J}{$b}{item_author}) 
	    || &uc_sort($J{$a}{item_title}) cmp &uc_sort(${J}{$b}{item_title}) 
} keys %J;

open(F,">dml_new.html");
print F $pre1;
$count=0;
my $content = "";
my $this_stamp = "";

foreach(@BA) {
    next if ( $J{$_}{item_stamp} le $stamp );
    if ( $J{$_}{item_stamp} ne $this_stamp ) {
	$this_stamp = $J{$_}{item_stamp}; 
    }

    print "$J{$_}{item_stamp} .. $stamp\n";
    my $a = "";
    if ( $J{$_}{item_author} =~ /\w/) {
	$a = "(by $J{$_}{item_author})";
    } 
    my $p=&pg($J{$_}{item_pag});
    if ($p == 0) { $p = " ";}
    $count++;
    my $date = $this_stamp;
    $date =~ s/^\d\d//;
    $date =~ s/(\d\d)(\d\d)(\d\d)/$3.$2.$1/;
    $content .= "<tr>
<td align=\"center\">$date ($count)</td>
<td align=\"center\"><a href=\"$J{$_}{addr}\">$J{$_}{nick}</a></td>
<td align=\"left\"><a href=\"$J{$_}{item_url}\">$a $J{$_}{item_title}</a> 
$J{$_}{comm}</td>
<td align=\"center\">$p</td>
<td align=\"center\">$J{$_}{item_years}</td>
<td align=\"center\">$J{$_}{item_type}</td>
</tr>";
}
print F $content;
print F $post;
close F;



exit(0);

foreach(keys %J) {
    if ( ($J{$_}{item_type} =~ /journal/ || $J{$_}{item_type} =~ /seminar/) && $J{$_}{count} == 1 ) {
	print "$J{$_}{count} : $_\n";
    }
}
