#!/usr/bin/perl
use Env;
#$override = "1";
$domain = "www.ywcaulstercounty.org";
$serverpath = "/home/sites/www.spinningwebz.com/web/addons/events";
$webpath = "/cgi-bin/calendar";
$blurbcount = 40;
$template = "templates/template.shtml";
$CalCMD = "/usr/bin/cal";
$SSI = 1;
$Border = 1;
$Days = "Su Mo Tu We Th Fr Sa";
$imagewidth = 150;
if ((-e "onserver")) {$lock = 1;}
$mail_program = "/usr/sbin/sendmail -t";
&get_date;
&ReadQuery;
&GetCookies;
$action = $query{'ACTION'};
#$action = "PREVIEW";
if ($action eq "EXIT")
{
&SetCookie("USERNAME","");
$outpage = &LoadPage("manager6.htm");
goto ExitOut;
}
if ($action eq "SIGNIN")
{
&ReadParse;
open(FILE,"admin.%");
if ($lock){flock(FILE,2);}
while( ";
}
}
if (@wdbf > 0)
{
@dbf = sort @wdbf;
foreach $temp (@dbf)
{
@sdbf = split(/\t/,$temp);
$outpage .= $sdbf[2];
open(FILE,"data/$sdbf[1].txt");
if ($lock){flock(FILE,2);}
while( ";
}
}
if ($extraout ne ""){$extraout = "This Month: $in{'BLURBTEXT'}\n~;
}
$sponsor = "";
if ($in{'SPONSOR'} ne ""){$sponsor = " Sponsored by: $in{'SPONSOR'}\n";}
$out = qq~ $in{'BYLINE'}$sponsor $in{'DATE'}$in{'TIME'} - $in{'STORY'} $link ~;
if ($in{'PHOTO'} ne "")
{
$temp = qq~ \n~;
#if ($thistempdate * 1 >= $compdate)
#{
# $out .= qq~Register for this event
~;
$wdbf[@wdbf] = $dbf[2]."\t".$dbf[0]."\t".$wtemp;
# $outpage .= qq~$dbf[2]: $dbf[1]
~;
$count--;
$datecheck .= $dbf[2]."| ";
goto SkipIt;
}
if (substr($when,0,2) ne substr($fulldate,0,2) && substr($when,-4) eq substr($fulldate,-4) && substr($fulldate,0,2) eq substr($dbf[2],0,2) && substr($fulldate,-4) eq substr($dbf[2],-4))
{
$wtemp = qq~$dbf[2]: $dbf[1]
~;
$tdbf[@tdbf] = $dbf[2]."\t".$dbf[0]."\t".$wtemp;
# $extraout .= qq~$dbf[2]: $dbf[1]
~;
$count--;
}
SkipIt:
}
}
close(FILE);
if (@tdbf > 0)
{
@dbf = sort @tdbf;
foreach $temp (@dbf)
{
@sdbf = split(/\t/,$temp);
$extraout .= $sdbf[2];
open(FILE,"data/$sdbf[1].txt");
if ($lock){flock(FILE,2);}
while(
/ /gi;
@ttdbf = split(/\ /,$ttlip{'STORY'});
for($zz = 0;$zz < 8 && $zz < @ttdbf;$zz++)
{
$extraout .= $ttdbf[$zz]." ";
}
$extraout .= "...
/ /gi;
@ttdbf = split(/\ /,$ttlip{'STORY'});
for($zz = 0;$zz < 8 && $zz < @ttdbf;$zz++)
{
$outpage .= $ttdbf[$zz]." ";
}
$outpage .= "...
\n".$extraout;}
$myoutpage = &RetCal($CalCMD, $when, $Border);
$myoutpage =~ s//$outpage$extraout/gi;
$outpage = $myoutpage;
if ($query{'TEMPLATE'} eq "YES")
{
$out = &LoadPage($template);
$out =~ s//$outpage/gi;
$outpage = $out;
}
goto ExitOut;
}
if ($action eq "SHOW" && $query{'ID'} ne "")
{
$thisdate = "99999999";
$thisid = 0;
if ($query{'ID'} eq "CURRENT")
{
open(FILE,"data/headlines.txt");
if ($lock){flock(FILE,2);}
while(!PHOTO!$in{'HEADLINE'}
~;
}
else
{
$temp = "";
}
if ($query{'MORE'} eq "YES"){$temp = "";}
$out =~ s/!PHOTO!/$temp/gi;
$thistempdate = substr($in{'DATE'},-4).substr($in{'DATE'},0,2).substr($in{'DATE'},3,2);
$out .= qq~
\n~;
#}
$out .= qq~Show All Events\n~;
$outpage =~ s//$out/gi;
if ($query{'TEMPLATE'} eq "NO"){$outpage = $out;}
goto ExitOut;
}
open(FILE,"admin.%");
if ($lock){flock(FILE,2);}
while(
Check here to delete this photo~;
$outpage =~ s/!PHOTO!/$temp/gi;
$outpage =~ s/!PHOTONAME!/$dbf[1]/gi;
}
else
{
$outpage =~ s/!PHOTONAME!//gi;
$outpage =~ s/!PHOTO!//gi;
}
}
$dbf[1] =~ s/
/\n/gi;
$in{$dbf[0]} = $dbf[1];
}
close(FILE);
@dbf = split(/\//,$in{'DATE'});
$in{'MONTH'} = $dbf[0];
$in{'DAY'} = $dbf[1];
$in{'YEAR'} = $dbf[2];
$outpage = &FillData($outpage);
$outpage =~ s/!ID!/$query{'ID'}/gi;
goto ExitOut;
}
if ($action eq "PREVIEW")
{
$outpage = &LoadPage("manager3.htm");
open(FILE,"data/$query{'ID'}.txt");
if ($lock){flock(FILE,2);}
while(~;
}
$outpage =~ s/!$dbf[0]!/$dbf[1]/gi;
}
close(FILE);
$outpage =~ s/!ID!/$query{'ID'}/gi;
goto ExitOut;
}
if ($action eq "KILL")
{
open(FILE,"data/headlines.txt");
if ($lock){flock(FILE,2);}
while(
~;
}
$outpage =~ s/!$dbf[0]!/$dbf[1]/gi;
}
close(FILE);
$outpage =~ s/!ID!/$query{'ID'}/gi;
goto ExitOut;
}
if ($action eq "ADMIN")
{
ShowList:
$outpage = &LoadPage("manager1.htm");
require "tables.pl";
$string = $tablestart;
$color = 0;
open(FILE,"data/headlines.txt");
if ($lock){flock(FILE,2);}
while(
/gi;
$in{'STORY'} =~ s/$tt//gi;
$in{'STORY'} =~ s/\t/ /gi;
$ID = &GetNextID;
$in{'PHOTO'} = &UploadFile();
$data = "";
foreach $temp (keys(%in))
{
$data .= "$temp\t$in{$temp}\n";
}
&SaveFile("data/$ID.txt",$data);
open(FILE,"data/headlines.txt");
if ($lock){flock(FILE,2);}
while(
/gi;
$in{'STORY'} =~ s/$tt//gi;
$in{'STORY'} =~ s/\t/ /gi;
$ID = $in{'ID'};
if ($in{'DELETE'} ne "")
{
unlink("data/photos/$in{'DELETE'}");
$in{'OLDPHOTO'} = "";
}
$in{'PHOTO'} = &UploadFile();
if ($in{'PHOTO'} eq ""){$in{'PHOTO'} = $in{'OLDPHOTO'};}
$data = "";
foreach $temp (keys(%in))
{
$data .= "$temp\t$in{$temp}\n";
}
&SaveFile("data/$ID.txt",$data);
open(FILE,"data/headlines.txt");
if ($lock){flock(FILE,2);}
while(
~;
$outpage = $start.$img.substr($finis,$a + 2);
}
print "Content-type: text/html\n$THEcookie\n\n";
print $outpage;
exit;
# Get cookies using $mycookies{}
sub GetCookies
{
my $cookie = "";
my $value = "";
foreach (split(/; /,$ENV{'HTTP_COOKIE'}))
{
($cookie,$value) = split(/=/);
$cookie = uc($cookie);
$mycookies{$cookie} = $value;
}
return;
}
# Strip HTML from passed variable
sub StripHtml
{
my $string = shift;
my $result = $string;
$result =~ s/<.+?>\|//gi;
return ($result);
}
# Read the command line into $query{}
sub ReadQuery
{
local (*query) = @_ if @_;
$query = $ENV{'QUERY_STRING'};
@query = split(/&/,$query);
foreach $i (0 .. $#query)
{
# Convert plus's to spaces
$query[$i] =~ s/\+/ /gi;
# Remove any HTML stuff
$query[$i] = StripHtml($query[$i]);
# Split into key and value.
($key,$val) = split(/=/,$query[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$key = uc($key);
$val =~ s/!/! /gi;
$val =~ s/! /! /gi;
$val = &Shrink($val);
# Associate key and value
# \0 is the multiple separator
$query{$key} .= "\0" if (defined($query{$key}));
if (index($key,".") == -1)
{
$query{$key} .= uc($val);
}
else
{
$query{$key} .= $val;
}
}
return length($query);
}
# Read the passed form fields into $in{}
sub ReadParse
{
my $results = "";
my $tt = "";
local (*in) = @_ if @_;
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
@in = split(/&/,$in);
$tt = chr(13);
foreach $i (0 .. $#in)
{
# Convert plus's to spaces
$in[$i] =~ s/\+/ /gi;
# Remove any HTML stuff
$in[$i] = StripHtml($in[$i]);
# Split into key and value.
($key,$val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$key = uc($key);
if ($key eq "ACTION")
{
$val = uc($val);
}
$val =~ s/\t/ /gi;
$val =~ s/\n/
/gi;
$val =~ s/$tt//gi;
$val =~ s/ / /gi;
# Associate key and value
# \0 is the multiple separator
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= &Shrink($val);
$in{$key} =~ s/þ//gi;
}
return ($results);
}
# Remove leading and trailing spaces
sub Shrink
{
my $results = shift;
while(substr($results,0,1) eq " ")
{
$results = substr($results,1);
}
while(substr($results,-1) eq " ")
{
$results = substr($results,0,length($results) - 1);
}
return ($results);
}
# Load page passed, only inside of BODY tags
sub LoadBlankPage
{
my $page = shift;
my $results = &LoadPage($page);
$results = substr($results,index($results,"") + 1);
$results = substr($results,0,index($results,";
close(LPFILE);
$results = join(' ',@LPFILE);
return ($results);
}
# Set cookies using $mycookies{}
sub SetCookie
{
my $cookie = shift;
my $value = shift;
$THEcookie = $THEcookie."Set-Cookie: $cookie=$value; expires=$cookiedate; path=\/; domain=$domain;\n";
$mycookies{$cookie} = $value;
return;
}
# Get todays date, cookie expire date, log date etc
sub get_date
{
my @daynames = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
my @monthnames = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
my @daysinmonth = (31,28,31,30,31,30,31,31,30,31,30,31);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$thour = $hour;
if ($year > 100)
{
$year = $year - 100;
}
if ($hour < 12 || $hour == 23)
{
$zz = "am";
}
else
{
$zz = "pm";
}
if ($hour > 12)
{
$hour = $hour - 12;
}
$cwday = $wday + 1;
if ($cwday == 7){$cwday = 0;}
$cmday = $mday + 1;
$cmon = $mon;
$cyear = $year;
if ($cmday > $daysinmonth[$mon]){$cmday = 1;$cmon++;}
if ($cmon > 11){$cmon = 0;$cyear++;}
$cookiedate = "$daynames[$cwday], $cmday-$monthnames[$cmon]-20".sprintf("%02i %02i:%02i:%02i GMT",$cyear,$thour,$min,$sec);
$today = sprintf("%02i/%02i/%02i",$mon + 1,$mday,$year);
$fulldate = sprintf("%02i/%02i/20%02i",$mon + 1,$mday,$year);
$yeardate = $year * 365 + $yday;
$now = sprintf("%02i:%02i:%02i",$thour,$min,$sec);
$tempsession = sprintf("%02i%02i%02i%02i%02i%02i",$year,$mon + 1,$mday,$hour,$min,$sec);
$logdate = sprintf("%02i%02i%02i",$mon + 1,$mday,$year);
$compdate = sprintf("20%02i%02i%02i",$year,$mon + 1,$mday);
$mon++;
return;
}
sub GetTemplate
{
my $content = shift;
my $results = "";
my $t = "";
my $template = "";
if (index($content,"");
$template = substr($template,0,$t).".htm";
}
else
{
$template = "default.htm";
}
$results = &LoadPage($template);
return ($results);
}
sub GetTempSession
{
my $count = 0;
while(-e "temp/$tempsession$count")
{
$count++;
}
open(FILE,">temp/$tempsession$count");
if ($lock){flock(FILE,2);}
close(FILE);
chmod(0755, "temp/$tempsession$count");
return ("$tempsession$count");
}
sub FillData
{
my $what = shift;
my $temp = "";
my $t2 = "";
my $t3 = "";
my $beg = "";
my $fin = "";
my $part = "";
foreach $temp (keys(%in))
{
if (index($what,"");
$fin = substr($part,$t2);
$part = substr($part,0,$t2);
if (index($part,"