#!/usr/local/bin/perl

$file = "./digest.html";

$dropdown = "/home/kirkjerk/SITES/MAIN/loveblender.com/dropdown.html";

$hitwhore = "/home/kirkjerk/SITES/MAIN/loveblender.com/hitwhore.txt";

$surveyfile = "/home/kirkjerk/SITES/MAIN/DATA/data-loveblender/survey/current";

open(READ,$file);
@lines = <READ>;
$text = join("\n",@lines);
close READ;

open(READ,$dropdown);
@lines = <READ>;
$dropdowntext = join("\n",@lines);
close READ;





open(READ,"$hitwhore");
$hitwhoretext = <READ>;
close READ;

open(READ,$surveyfile);
$askid =  <READ>;
chomp $askid;
$ask = <READ>;
chomp $ask;
close READ;


$surveytable = <<__EOQ__;
<table align="right"><tr>
<td bgcolor="#dddddd" align="center" width=250>
<font size=-1>
<b>Current Blender Survey:</b><br>
$ask<br>
<a href="/blend/surveyask.html">Your Response?</a>
/ <a href="/blend/surveyview.cgi?num=$askid">View Responses</a>
<a href="">
</font>
</td>
</table>


__EOQ__



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


@months = ("january","february","march","april","may","june","july","august","september","october","november","december");
$uri = $ENV{'REQUEST_URI'};
if($uri =~ /\/(\d\d\d\d)(.*)\//){
    $thisyear = $1;
    $thismonthname = $2;
    $thismonth = -1;
    for($ptr = 0; $ptr < 12; $ptr++){
        if($months[$ptr] eq $thismonthname){
            $thismonth = $ptr;
        }
    }
    $prevmonth = $thismonth-1;
    $prevyear = $thisyear;
    if($prevmonth < 0) {$prevmonth = 11; $prevyear--;}
    $prevmonthname = $months[$prevmonth];
    $nextmonth = $thismonth+1;
    $nextyear = $thisyear;
    if($nextmonth >= 12) {$nextmonth = 0; $nextyear++;}
    $nextmonthname = $months[$nextmonth];

    $justdate=qq($thismonthname $thisyear);
    $datelink=qq(<a style="text-decoration: none" href="/$prevyear$prevmonthname/">&lt;</a> $justdate);

    if(-d "/home/kirkjerk/SITES/MAIN/loveblender.com/$nextyear$nextmonthname"){
	$datelink .= qq( <a style="text-decoration: none" href="/$nextyear$nextmonthname/">&gt;</a>);
    }
}
$text =~ s/\[\[justdate\]\]/$justdate/;
$text =~ s/\[\[datelink\]\]/$datelink/;



$text =~ s/[[dropdown]]/$dropdowntext/;

$text =~ s/\[\[hitwhore\]\]/$hitwhoretext/;
$text =~ s/\[\[webcounter\]\]//;

$text =~ s/\[\[survey\]\]/$surveytable/;

print $text;
