#!/usr/bin/perl
use DBD::mysql;
use CGI;

# Version mit Vorschaubild!

#require("gmd.pl"); 
#$kategorie=$akt; 

# Datum bestimmen
($aktsec, $aktmin, $akthour, $aktmday, $aktmon, $aktyear, $aktwday, $aktyday, $aktisdst)=localtime(time);
$aktyear += 1900;
$aktmon++;
$heute = "$aktmday.$aktmon.$aktyear";
$heutedb = sprintf("%04d-%02d-%02d", $aktyear, $aktmon, $aktmday);
$jetzt = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aktyear,$aktmon,$aktmday,$akthour,$aktmin,$aktsec);

$bilderpfad = "/usr/local/httpd/htdocs/resi-nr/gemeinden/bilder/redaktion";

$data = DBI->connect("DBI:mysql:ws:mysql.netpark.at","ws","ws4adr"); # open
if (! $data)                           # on error...
{
	print "Kann Datenbank nicht oeffnen!\n";
	exit 0;
}

#/usr/local/httpd/htdocs/resi-nr/gemeindenneu/hofkirchen/cgi/aktuelluebersicht.pl
#$script_filename = $ENV{SCRIPT_FILENAME};
$verzeichnis = `pwd`;
$kategorie = (split /\//, $verzeichnis)[7];
$gemeinde = $kategorie;

# Gemeinde Daten holen
$gtyp = "unknown";
$gname = "unknown";
$url = "unknown";
$sth = $data->prepare("Select Gtyp, Gname, Gurl from Gemeinde where Gkurz='$kategorie'");
$rv = $sth->execute || print "Fehler: " . $data->errstr;
if ($hash_ref = $sth->fetchrow_hashref)
{
  $gtyp = $hash_ref->{Gtyp};
  $gname = $hash_ref->{Gname};
  $gurl = $hash_ref->{Gurl};
}

$gurlkurz = $gurl;                
$gurlkurz =~ s/http:\/\///;

$sth = $data->prepare("Select * from beitraege where Kategorie='$kategorie' \ 
	and AnzeigeDatum <= '$heutedb' \
	order by AnzeigeDatum DESC, ErstDatum DESC LIMIT 0,9");
$rv = $sth->execute || print "Fehler: " . $data->errstr;

$i = 1;
$uebersicht = "";
$detail = "";
while ($hash_ref = $sth->fetchrow_hashref)
{
	$u1 = $hash_ref->{U1};
	$u2 = $hash_ref->{U2};
	$id = $hash_ref->{ID};
	$anzeigedatum = $hash_ref->{AnzeigeDatum};

#	$u1 =~ s/ö/&ouml;/g;
#	$u1 =~ s/ä/&auml;/g;
#	$u1 =~ s/ü/&uuml;/g;
#	$u1 =~ s/ß/&szlig;/g;
	
#	$u2 =~ s/ö/&ouml;/g;
#	$u2 =~ s/ä/&auml;/g;
#	$u2 =~ s/ü/&uuml;/g;
#	$u2 =~ s/ß/&szlig;/g;

        $u1 =~ s/&/&amp;/g;
        $u2 =~ s/&/&amp;/g;

	$detail .= <<"EndOfText";
<item>
   <title>$u1</title> 
   <link>$gurl/artikel.shtml?newsid=$id</link>
   <description>$u2</description>
</item> 
EndOfText


}


# alles ausgeben
print <<"EndOfText";
Content-type: application/xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="0.91">        
<channel>
  <title>$gurlkurz</title>
  <link>$gurl</link>
  <description>News von der $gtyp $gname</description>
  <language>de</language>

$detail

</channel>
</rss>
EndOfText
