#!/usr/local/bin/perl
#
# Apotheken-Notdienstplan Ausgabe
# by Peter Rohde (webmaster@kueste.de)
# Last Update 22.11.98
#



read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# VARIABLEN AUS HTML.Form holen....

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);

   # Un-Webify plus signs and %-encoding
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;

   if ($allow_html != 1) {
      $value =~ s/<([^>]|\n)*>//g;
   }

   $FORM{$name} = $value;
}



$ti =$stunde*60+$minute;
$monat = $FORM{'monat'} ;
$tag = $FORM{'tag'} ;
#$monat = "November";
#$tag = "29";

if ($tag eq "01")
{$tag = 1};
if ($tag eq "02")
{$tag = 2};

if ($tag eq "03")
{$tag = 3};

if ($tag eq "04")
{$tag = 4};

if ($tag eq "05")
{$tag = 5};

if ($tag eq "06")
{$tag = 6};

if ($tag eq "07")
{$tag = 7};

if ($tag eq "08")
{$tag = 8};

if ($tag eq "09")
{$tag = 9};

&datum();
$ti =$stunde*60+$minute;
$m = $zeit[4]+1;


print "Content-Type: text/html\n\n";

if ($monat eq "Januar")
{$m = 1}
if ($monat eq "Februar")
{$m = 2}
if ($monat eq "März")
{$m = 3}
if ($monat eq "April")
{$m = 4}
if ($monat eq "Mai")
{$m = 5}
if ($monat eq "Juni")
{$m = 6}
if ($monat eq "Juli")
{$m = 7}
if ($monat eq "August")
{$m = 8}
if ($monat eq "September")
{$m = 9}
if ($monat eq "Oktober")
{$m = 10}
if ($monat eq "November")
{$m= 11}
if ($monat eq "Dezember")
{$m= 12}

#
# Notdienst ausgeben.... html
#

$liste = 'apomeldorf.dat' ;
open (RXIN,"$liste");
@RX = <RXIN>;
chop (@RX);
close RXIN;
$SIZE=@RX;

$apo = "FAIL";

#
# Notdienst aus Datenbank holen...
# und Apotheke ausgeben....
#

for ($k=0;$k<=(int($SIZE));$k++) {
if ($RX[$k] eq "$tag.$m" )  {
$apo=$RX[$k+1];



if ($apo eq 1) {
$apoout = "<font size=3><br>Linden-Apotheke<br>Bahnhofstraße 1, 25712 Burg<br>Tel.(0 48 25) 9 39 90<br>";
}
if ($apo eq 2) {
$apoout = "<font size=3><br>Krabben-Apotheke<br>Koogstr. 64, 25718 Friedrichskoog<br>Tel.(0 48 54) 900 90<br>";
}
if ($apo eq 3) {
$apoout = "<font size=3><br>Priv. Stadt-Apotheke<br>Südermarkt 8, 25704 Meldorf<br>Tel.(0 48 32) 14 63<br>";
}
if ($apo eq 4) {
$apoout = "<font size=3><br>Neue Apotheke<br>Königstraße 1, 25709 Marne<br>Tel.(048 51) 7 64<br>";
}
if ($apo eq 5) {
$apoout = "<font size=3><br>Priv. Apotheke am Markt<br><font size=4>Am Markt 8, 25712 Burg<br>Tel.(0 48 25) 22 89<br>";
}
 if ($apo eq 6) {
$apoout = "<font size=3><br>Zingel-Apotheke<br><font size=4>Zingelstraße 43, 25704 Meldorf<br>Tel.(0 48 32) 9 58 10<br><br>";
} 
if ($apo eq 7) {
$apoout = "<font size=3><br>Kgl. priv. Sonnen-Apotheke<br>Markt 5, 25709 Marne<br>Tel.(0 48 51) 9 50 80<br>";
}
if ($apo eq 8) {
$apoout = "<font size=3><br>Donn-Apotheke<br>Johannssenstr. 2, 25693 St. Michaelisdonn<br>Tel.(0 48 53) 4 60<br>";
}
if ($apo eq 9) {
$apoout = "<font size=3><br>Öster-Apotheke<br><font size=4>Österstraße 27, 25704 Meldorf<br>Tel.(0 48 32) 9 59 40<br>";
}
if ($apo eq "FAIL") {$apoout ="Daten sind noch nicht verfügbar!<br>";}

  }
}

$org = 'apomeldorfout.htm';

#
# File einlesen!
#


print "<HTML><HEAD><TITLE>STAWO FRAME DATAOUT...</TITLE></HEAD>";

open (FILE,"$org") || die "HTML Source  $org: $! nicht gefunden...\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

#
# File ausgeben
#

for ($i=0;$i<=$SIZE;$i++) {
   $_=$LINES[$i];
   if (/<!--notdienst-->/) { 
     print "<font color=#808080 size=2 face=Arial>Apothekennotdienst am $tag. $mon :<br>$apoout<br></strong></font>\n";
   }
   else {
      print $_;
   }
}

#
# Serverdatum korrigieren...
#

sub datum {

@zeit = localtime(time);

($stunde, $minute, $sekunde) = ($zeit[2], $zeit[1], $zeit[0]);
# ($stunde) = ($stunde - 0);
$null="0";
$st=$stunde;
$min=$minute;
$sek=$sekunde;
$tag = $zeit[3];


if ($stunde < 10)
{$st="$null$stunde"}

if ($minute < 10)
{$min="$null$minute"}

if ($sekunde < 10)
{$sek="$null$sekunde"}


if ($zeit[4] eq 0)
{$mon="Januar"}
if ($zeit[4] eq 1)
{$mon="Februar"}
if ($zeit[4] eq 2)
{$mon="Maerz"}
if ($zeit[4] eq 3)
{$mon="April"}
if ($zeit[4] eq 4)
{$mon="Mai"}
if ($zeit[4] eq 5)
{$mon="Juni"}
if ($zeit[4] eq 6)
{$mon="Juli"}
if ($zeit[4] eq 7)
{$mon="August"}
if ($zeit[4] eq 8)
{$mon="September"}
if ($zeit[4] eq 9)
{$mon="Oktober"}
if ($zeit[4] eq 10)
{$mon="November"}
if ($zeit[4] eq 11)
{$mon="Dezember"}

$jahr=$zeit[5]+1900;
$datum = "$tag.$mon $jahr $st:$min:$sek";


}

# EOF  