#!/usr/bin/perl
####################################################################
#
#This software is released under the GPL. Please
#see the included LICENSE file.
#
#Copyright (C) 2001 Michael Spiceland
#Copyright (C) 2001 Jay Kline
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#Use this script at your own risk! I make no
#warranties that it is hack proof!
#
#
# This script is part of the Fuzzymonkey Perl Script Archive at
# www.fuzzymonkey.org/perl/
#
# Edited by Jay Kline www.slushpupie.com
#
####################################################################
$version = "2.6";
use CGI qw(:standard);
require "common.pl";
require "sitevariables.pl";
############ BEGIN MAIN PROGRAM ################################
$cur = CGI->new();
$mode = "default";
if($cur->param("mode")) {
$mode = $cur->param("mode");
}
if($cur->param("month") && $cur->param("year")){
$month = $cur->param("month");
$year = $cur->param("year");
($sec,$min,$hr,$mday,$mon,$year_localtime,$wday,$yday,$isdst) = localtime(time());
}else{
($sec,$min,$hr,$mday,$mon,$year_localtime,$wday,$yday,$isdst) = localtime(time());
$year = $year_localtime + 1900;
$month = $mon + 1;
}
@pretty_months = ("","January","February","March","April","May","June","July","August","September","October","November","December");
%apps = get_appointments("appointments.txt");
%apps = add_appointments("appointments-imported.txt",%apps);
if($cur->param("day")){
$day = $cur->param("day");
$content .= print_full_day($month,$day);
print "Content-type: text/html\n\n
$content";
exit(1);
} else {
$content.= print_month($month,$day);
}
printpage($content);
############ BEGIN SUBROUTINES #################################
# Print the calendar
#
sub print_month($$) {
my $return;
my $month = $_[0];
my $day = $_[1];
$calendar = '';
$calendar .= "| ";
#create previous month button
$month_button = $month-1;
if($month_button == 0){
$month_button = 12;
$year_button = $year-1;
}else{
$year_button = $year;
}
$calendar .= " <--$pretty_months[$month_button], $year_button";
$calendar .= " | ";
#create "today" button
$month_button = $mon + 1;
$year_button = $year_localtime + 1900;
$calendar .= "Today";
$calendar .= " | ";
#create next month button
$month_button = $month+1;
if($month_button == 13){
$month_button = 1;
$year_button = $year+1;
}else{
$year_button = $year;
}
$calendar .= "$pretty_months[$month_button], $year_button -->";
$calendar .= " |
";
$cal = `cal $month $year`;
@weeks= split(/\n/,"$cal");
shift @weeks; shift @weeks;
$calendar .= "";
$calendar .= "
| Sunday |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
";
foreach $week (@weeks){
$calendar .= "";
@days= split " ",$week;
# Pad @days with leading blanks if it's the first week
if ($days[0] == 1) {
foreach (0 .. (6 - $days[-1])) {
$calendar .= "| | ";
}
}
foreach my $day (@days){
$calendar .= print_day($month,$day);
}
unless($days[0] ==1){
$left = 7-@days;
until ($left == 0){
$calendar .= " | ";
$left--;
}
}
$calendar .= "
";
}
$calendar .= "
| Sunday |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
";
$calendar .= "
";
if($pscal){
$pdf_link = "printable version";
}
if($import =~ /yes/i){
$import_link = "import from Outlook";
}
$return .= "| | $pretty_months[$month], $year | ";
$return .= "$pdf_link |
\n";
$return .= $calendar;
$return .= "
$pdf_link
$import_link";
return $return;
}
# Print one day at a time
#
sub print_full_day($$) {
my $return;
my $month = $_[0];
my $day = $_[1];
my $appointment;
my $appointment_text;
my @appointment_array;
if(($year == ($year_localtime+1900)) && ($mon == ($month-1)) && ($mday == $day)){
$color = "$todaybg";
}else{
$color = "$daybg";
}
@appointments_array = @{$apps{"$month-$day-$year"}};
@appointments_array = (@appointments_array,@{$apps{"$month-$day-*"}});
@appointments_array = (@appointments_array,@{$apps{"*-$day-*"}});
foreach $appointment (@appointments_array){
# ($appointment) = /(.{0,5})/; #get only the first 100chars
$appointment_text .=" |
\n";
}
$return .= "
| Today\'s Events |
$appointment_text
| |
";
return $return;
}
sub print_day($$) {
my $return;
my $month = $_[0];
my $day = $_[1];
my $appointment;
my $appointment_text;
my @appointment_array;
#$appointments = "$apps{$day}";
#@appointments_array = split(/##/,$appointments);
@appointments_array = @{$apps{"$month-$day-$year"}};
@appointments_array = (@appointments_array,@{$apps{"$month-$day-*"}});
@appointments_array = (@appointments_array,@{$apps{"*-$day-*"}});
$numapps=0;
foreach $appointment (@appointments_array){
$numapps++;
if ($numapps > 3) {
$appointment_text .= "...";
last;
}
$_ = $appointment;
$count = tr///c; #dont display more than 20 chars
#if ($count > 40) {
# $appointment = substr($appointment,0,40) . "...";
#}
$appointment_text .="$appointment
";
}
if(($year == ($year_localtime+1900)) && ($mon == ($month-1)) && ($mday == $day)){
$color = "$todaybg";
} elsif ("$appointment_text") {
$color = "$busydaybg";
} else {
$color = "$daybg";
}
$return .= "
$appointment_text
| ";
return $return;
}
#####################################################
#subs from slashdot to remove bad html
#####################################################
# Thanks to Slashdot for these
# Approved HTML tags for HTML posting
@approvedtags = (
'B','I','P .*','P','A',
'LI','OL','UL','EM','BR',
'STRONG','BLOCKQUOTE',
'HR','DIV .*','DIV','TT'
);
sub stripBadHtml
{
my ($str) = @_;
$str =~ s/(\S{90})/$1 /g;
$str =~ s/<(?!.*?>)//;
$str =~ s/<(.*?)>/approvetag($1,@approvedtags)/sge; #replace
tags with approved ones
return $str;
}
sub approvetag
{
my ($tag,@apptag) = @_;
$tag =~ s/^\s*?(.*)\s*?$/$1/e; #trim leading and trailing spaces
if (uc(substr ($tag, 0, 2)) eq 'A ')
{
$tag =~ s/^.*?href="?(.*?)"?$/A HREF="$1"/i; #enforce "s
return "<" . $tag . ">";
}
foreach my $goodtag (@apptag)
{
$tag = uc $tag;
if ($tag eq $goodtag || $tag eq '/' . $goodtag)
{return "<" . $tag . ">";}
#check against my list of tags
}
return "";
}