#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI qw(:standard);
print header();
warningsToBrowser(1);

####
# Fehlerausgabe auskommentieren, wenn das Script luft und eingesetzt wird!!
####

### Variablen konfigurieren ###
# relativer Pfad vom cgi-bin Verz. zum htdocs-Verzeichnis
my $htdocs_rel = "../texnik";
my $htdocs_abs = "/texnik";

my $q;
$q = new CGI;
my $titel = $q->param('titel');
my $datum = $q->param('datum');
my $woche = $q->param('woche');
my $artikel = $q->param('artikel');


chomp ($titel,$datum,$woche,$artikel);

# Wert fuer $woche pruefen
if (($woche =~ /\D/) || (($woche < 0) || ($woche > 53)))
	{die "falsche Wocheneingabe $!"}

# extra Variabel, um Eingabewoche und Speicherwoche zu unterscheiden
my $speicher = $woche;
# die Wochenzahl in die passende SSI-Form bringen
# Woche 53 ist das gleiche wie Woche 01
if ($speicher == 53) {$speicher = "0"}
else {$speicher--}

# Zahlen unter 10 werden 2-stellig geschrieben
if ($speicher < 10){
	$speicher = "0" . $speicher;
}

$titel =~ s/<.+?>//g;
$datum =~ s/<.+?>//g;
$artikel =~ s/<.+?>//g;

open (NEW, ">$htdocs_rel/aktuell_$woche.txt")||die "Datei konnte nicht geschrieben werden $!";

print NEW <<EINTRAG;
	<h2>$datum</h2>
	<div class="news">
	<h3>$titel</h3>
	<p>$artikel</p>
	</div>
EINTRAG
close NEW;

print <<BACK;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Artikel Woche ($woche)</title>
    <link rel="stylesheet" href="$htdocs_abs/aktuell.css" type="text/css">
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>

<body>
<p style="color:#ffffff;margin-bottom:10px;">Der Artikel in Woche $woche:</p>

<h1>Diese Woche aktuell</h1>
<h2>$datum</h2>
<div class="news">
<h3>$titel</h3>
<p>$artikel</p>
</div>

<p><a style="color:#ffffff;line-height:40px" href="$htdocs_abs/maske.html">zur Eingabemaske</a></p>
</body>
</html>
BACK
