Annotation of ConnorCalendar/calendar.pl, revision 1.11

1.10      nick        1: #!/usr/bin/perl -w
1.1       nick        2: 
                      3: =begin comment info
                      4: +------------------------------------------------------------------------------
                      5: |
                      6: | See end of script for comments and 'pod2man $NAME | nroff -man' to
                      7: | view man page or pod2text $NAME for plain text.
                      8: |
                      9: |   Nicholas DeClario <nick@demandred.dyndns.org>
                     10: |   March 2009
1.11    ! nick       11: |      $Id: calendar.pl,v 1.10 2016/11/03 12:49:45 nick Exp $
1.1       nick       12: |
                     13: +------------------------------------------------------------------------------
                     14: =end comment
                     15: =cut
                     16: BEGIN {
                     17:         delete @ENV{ qw(IFS CDPATH ENV BASH_ENV PATH) };
                     18:         $ENV{'PATH'} = "/bin:/usr/bin";
                     19:       }
                     20: 
                     21: use strict;
                     22: use Getopt::Long;
                     23: use Pod::Usage;
                     24: use Data::Dumper;
                     25: use Calendar::Simple;
1.10      nick       26: use Date::Pcalendar::Year qw( :all );
                     27: use Date::Pcalendar::Profiles qw( $Profiles );
1.1       nick       28: 
1.11    ! nick       29: my $VERSION  = '$Id: calendar.pl,v 1.10 2016/11/03 12:49:45 nick Exp $';
1.1       nick       30: my $DEBUG    = "";
1.2       nick       31: my $URL             = "http://demandred.dyndns.org/cgi-bin/ConnorCalendar/index.cgi";
1.1       nick       32: my %post_in  = ( );
                     33: my %opts     = &fetchOptions( );
1.3       nick       34: my @list     = ( );
1.1       nick       35: my @months   = qw/ January February March April May June July 
1.5       nick       36:                   August September October November December /;
1.1       nick       37: my %holidays = ( 
1.7       nick       38:                 "Easter Sunday"        => 'even',
1.1       nick       39:                 "Christmas Day"        => 'even',
                     40:                 "Christmas Eve"        => 'odd',
                     41:                 "Father's Day"         => 'all',
                     42:                 "Independence Day"     => 'even',
                     43:                 "Labor Day"            => 'even',
                     44:                 "Memorial Day"         => 'odd',
1.8       nick       45:                 "New Year's Day"       => 'odd',
                     46:                 "New Year's Eve"       => 'odd',
1.1       nick       47:                 "Thanksgiving Day"     => 'odd', 
                     48:               );
                     49: 
                     50: my %specials = (
                     51:                "11/28"                 => "even",
                     52:                "5/6"                   => "odd",
                     53:                );
1.10      nick       54: ## Change this @weekend to 'qw/ 2011 8 12 /' for original schedule
                     55: my @weekend  = qw/ 2011 8 19 /;
1.3       nick       56: my %weekends = &calcWeekends( @weekend );
1.1       nick       57: 
                     58: &ReadParse( );
                     59: 
                     60: my $yr =  sprintf( "%d", $post_in{'cy'} ) || ( ( localtime )[5] + 1900 );
                     61: my $YEAR = sprintf( "%d", $yr );
1.9       nick       62: push @list, 'Easter Sunday' if ( $YEAR % 2 == 0 );
1.1       nick       63: 
                     64: print "Content-type: text/html\n\n";
1.5       nick       65: print &header( );
                     66: print &css( );
1.10      nick       67: my $year_us = Date::Pcalendar::Year->new( $YEAR, $Profiles->{'US-FL'} );
1.1       nick       68: my @hdays = $year_us->labels( );
                     69: 
1.7       nick       70: print "<h1><center><a href=\"$URL?cy=" . ( $YEAR - 1 ) .
                     71:       "\">&lt;--</a> " .
                     72:       "Calendar Days Connor Visits for $YEAR" .
1.10      nick       73:        "<a href=\"$URL?cy=" . ( $YEAR + 1 ) . "\"> --&gt;</a></h1>";
1.1       nick       74: my $row = 0;
1.5       nick       75: print "<table align=center border=0><tr>";
1.1       nick       76: for( my $month = 1; $month <= 12; $month++ )
                     77: {
                     78:        if ( $row >= 3 ) 
                     79:        {
                     80:                $row = 0;
                     81:                print "</tr><tr>";
                     82:        }
                     83:        print "<td align=center valign=top>";
                     84:        print "<b>$months[($month - 1)]</b>\n";
                     85:        print "<pre>Su Mo Tu We Th Fr Sa\n";
                     86:        my @CALS = calendar( $month, $YEAR );
                     87:        foreach my $cal ( @CALS ) 
                     88:        {
                     89:                foreach my $day ( @$cal ) 
                     90:                {
                     91:                        if( defined $day ) 
                     92:                        {
                     93:                                my $h_day = ( $year_us->labels( $YEAR, $month, $day ) )[1];
                     94:                                if( &IHaveConnor( $h_day ) ) {
1.3       nick       95:                                        push @list, $h_day;
1.1       nick       96:                                        print sprintf "<font color=red><b>%2d</b> </font>", $day;
                     97:                                } elsif ( &isSpecial( $YEAR, $month, $day ) || 
                     98:                                          &isWeekend( $YEAR, $month, $day ) ) {
                     99:                                        print sprintf "<font color=green><b>%2d</b> </font>", $day;
                    100:                                } elsif ( &isToday( $YEAR, $month, $day ) ) {
                    101:                                        print sprintf "<font color=blue><b>%2d</b> </font>", $day;
                    102:                                } else {
                    103:                                        print sprintf "%2d ", $day;
                    104:                                }
                    105:                        } else {
                    106:                                print '   ';
                    107:                        }       
                    108:                }
                    109:                print "\n";
                    110:        }
                    111:        print "</pre></td>";
                    112:        $row++;
                    113: }
                    114: print "</tr></table>";
1.6       nick      115: print "<p class=\"Legend\">Holidays I have Connor are in <font color=red>Red</font>\n</br>";
                    116: print "Today is <font color=blue>Blue</font>\n</br>";
                    117: print "Weekends and special days I have Connor are in <font color=green>Green</font>\n</p>";
                    118: 
                    119: 
1.7       nick      120: print "<table width=35% align=center border=0><tr><td>List of Special/Holidays " .
                    121:       "I have Connor:<br /><p class=Legend>";
                    122: print map { $_ . "<br />\n" } sort @list;
                    123: print "</p></td></tr></table>\n";
1.6       nick      124: print "</pre><p class=\"footer\">Version: <font color=green>$VERSION</font><br />";
                    125: print "CVS: <a target=\"_new\" href=\"http://demandred.dyndns.org/cgi-bin/cvsweb/ConnorCalendar/\">http://demandred.dyndns.org/cgi-bin/cvsweb/ConnorCalendar/</a>";
                    126: print "</center></p>";
1.3       nick      127: 
1.1       nick      128: 
                    129: ###############################################################################
                    130: ###############################################################################
                    131: sub IHaveConnor 
                    132: {
                    133:        my $holiday = shift || return 0;
                    134:        my $y = ( $YEAR % 2 ) ? "odd" : "even";
                    135: 
                    136:        if ( defined $holidays{$holiday} )
                    137:        {
                    138:                return 1 if ( $holidays{$holiday} eq "all" );
                    139:                return 1 if ( $holidays{$holiday} eq $y );
                    140:        }
                    141: 
                    142:        return 0;
                    143: }
                    144: 
                    145: sub isSpecial
                    146: {
                    147:         my $y = shift || return 0;
                    148:         my $m = shift || return 0;
                    149:         my $d = shift || return 0;
                    150:        my $yr = ( $YEAR % 2 ) ? "odd" : "even";
                    151: 
                    152:        my $ref = "$m/$d";
                    153:        
                    154:        if ( defined $specials{$ref} )
                    155:        {
1.3       nick      156:                if ( $specials{$ref} eq "all" ||
                    157:                     $specials{$ref} eq $yr ) {
                    158:                        push @list, $ref;
                    159:                        return 1;
                    160:                }
1.1       nick      161:        }
                    162: 
                    163:        return 0;
                    164: }
                    165: 
                    166: sub isWeekend
                    167: {
1.3       nick      168:        my $y = shift || return 0;
1.10      nick      169:     my $m = shift || return 0;
                    170:     my $d = shift || return 0;
1.1       nick      171: 
1.3       nick      172:        $m--;
                    173:        my $ds = sprintf( "$y/$months[$m]/%02d", $d );
                    174: 
                    175:        return 1 if ( defined $weekends{$ds} );
                    176: 
1.1       nick      177:        return 0;
                    178: }
                    179: 
                    180: sub isToday
                    181: {
                    182:        my $y = shift || return 0;
                    183:        my $m = shift || return 0;
                    184:        my $d = shift || return 0;
                    185: 
                    186:        return 1 if ( $y eq ( ( localtime )[5] + 1900 ) &&
                    187:             $m eq ( ( localtime )[4] + 1 ) &&
                    188:             $d eq ( ( localtime )[3] ) );
                    189:        return 0;
                    190: }
                    191: 
1.3       nick      192: sub calcWeekends 
                    193: {
                    194:        my $y = shift;
                    195:        my $m = shift;
                    196:        my $d = shift;
                    197:        my %weekends = ( );
                    198: 
                    199:        print "Weekends I have Connor:\n";
                    200: 
                    201:        use Calendar;
                    202:        my $date = Calendar->new_from_Gregorian( $m, $d, $y );
                    203:                
                    204:        $weekends{$date->date_string( "%Y/%M/%d" )} = 1;
                    205:        &twoMore( $date );
                    206:        while ( $date->date_string( "%Y" ) <= 2026 ) 
                    207:        {
                    208:                $date += 14;
                    209:                $weekends{$date->date_string( "%Y/%M/%d" )} = 1;
                    210:                &twoMore( $date );
                    211:        }
                    212: 
                    213:        return %weekends;
                    214: 
                    215:        sub twoMore 
                    216:        {
                    217:                my $td = shift;
                    218:                
                    219:                $td++;
                    220:                $weekends{$td->date_string( "%Y/%M/%d" )} = 1;
                    221:                $td++;
                    222:                $weekends{$td->date_string( "%Y/%M/%d" )} = 1;
                    223:        }
                    224: }
                    225: 
1.1       nick      226: ###############################################################################
                    227: ###############################################################################
                    228: sub ReadParse
                    229: {
                    230:         my $a = $_[0] ? $_[0] : \%post_in;
                    231:         my ( $i, $in );
                    232:         my @in = ( );
                    233: 
                    234:         if ( defined $ENV{'SERVER_NAME'} ) {
                    235:                 my $SERVER = $ENV{'SERVER_NAME'};
                    236:         }
                    237: 
                    238:         if ( ( defined $ENV{'REQUEST_METHOD'} ) &&
                    239:              ($ENV{'REQUEST_METHOD'} eq 'POST') )
                    240:         {
                    241:                 read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
                    242:         }
                    243:         else
                    244:         {
                    245:                 $in = $ENV{'QUERY_STRING'} || "";
                    246:         }
                    247: 
                    248:         @in = split(/\&/, $in);
                    249: 
                    250:         foreach $i (@in)
                    251:         {
                    252:                 my ($k, $v) = split(/=/, $i, 2);
                    253:                 $k =~ s/\+/ /g; $k =~ s/%(..)/pack("c",hex($1))/ge;
                    254:                 $v =~ s/\+/ /g; $v =~ s/%(..)/pack("c",hex($1))/ge;
                    255:                 $a->{$k} = defined($a->{$k}) ? $a->{$k}."\0".$v : $v;
                    256:         }
                    257: 
                    258: }
                    259: 
                    260: ###############################################################################
                    261: ##
                    262: ## &fetchOptions( );
                    263: ##
                    264: ##      Grab our command line arguments and toss them in to a hash
                    265: ##
                    266: ###############################################################################
                    267: sub fetchOptions {
                    268:         my %opts;
                    269: 
                    270:         &GetOptions(
                    271:                         "help|?"        => \$opts{'help'},
                    272:                         "man"           => \$opts{'man'},
                    273:                    ) || &pod2usage( );
                    274:         &pod2usage( ) if defined $opts{'help'};
                    275:         &pod2usage( { -verbose => 2, -input => \*DATA } ) if defined $opts{'man'};
                    276: 
                    277:         return %opts;
                    278: }
                    279: 
1.5       nick      280: sub header {
                    281:        return <<EOF;
                    282: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    283: 
                    284: <html xmlns="http://www.w3.org/1999/xhtml">
                    285: <head>
                    286: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
                    287:     <title>Calendar Days Connor Visits</title>
                    288:   </head>
                    289: <body bgcolor="#FFFFFF">
                    290: EOF
                    291: }
                    292: 
                    293: sub css {
                    294:        return <<EOF;
                    295: <style type="text/css">
                    296: body {
                    297: 
                    298: padding-top: 0px;
                    299: padding-left: 0px;
                    300: padding-right: 0px;
                    301: padding-bottom: 0px;
                    302: 
                    303:  text-align:left;
                    304:  margin:0;
                    305:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    306:  #font-family: Geneva, Arial, Helvetica, sans-serif;
                    307:  font-size: 12pt;
1.7       nick      308:  background: #eeeeee;
1.5       nick      309:  color:#000000;
                    310: 
                    311: 
                    312: }
                    313: 
                    314: .name { 
                    315:  color: #191970; 
                    316:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    317:  #font-family: Verdana, Arial, sans-serif;
                    318:  font-size: 18pt; font-weight: bold; line-height: 38pt;
                    319:  text-align: center;
                    320: }
                    321: 
1.6       nick      322: p.Legend {
                    323:  color: #000000;
                    324:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    325:  font-size: 8pt;
                    326:  margin: auto;
1.7       nick      327:  width: 300px;
1.6       nick      328:  background-color : transparent;
                    329:  border-top: 1px solid #888888;
                    330:  border-left: 1px solid #888888;
                    331:  border-right: 1px solid #888888;
                    332:  border-bottom: 1px solid #888888;
                    333:  padding-top: 3px;
                    334:  padding-bottom: 3px;
                    335:  padding-left: 3px;
                    336:  padding-right: 3px;
                    337: }
                    338: 
1.5       nick      339: h1 { 
                    340:  color: #191970; 
                    341:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    342:  #font-family: Verdana, Arial, sans-serif;
                    343:  font-size: 12pt; font-weight: bold; line-height: 15pt;
1.6       nick      344:  background-color : transparent;
                    345:  margin-left: 20px;
                    346:  margin-right: 20px;
                    347:  border-top: 1px solid black;
                    348:  border-bottom: 1px solid black;
1.5       nick      349: }
                    350: 
                    351: 
                    352: h2 {
                    353:  color: #191970; 
                    354:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    355:         font-weight: bold;
                    356:         font-size: 18px;
                    357: }
                    358:         
                    359: h3 {
                    360:  color: #191970; 
                    361:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    362:         font-weight: bold;
                    363:         font-size: 14px;
                    364: }
                    365: 
                    366: 
                    367: textarea { width:100%; }
                    368: 
                    369: .gallery {
                    370: padding-top: 80px;
                    371: padding-left: 60px;
                    372: padding-right: 50px;
                    373: line-height: 120%;
                    374: background:url('topleft.jpg') no-repeat top left;
                    375: }
                    376: .browse {
                    377: padding-top: 80px;
                    378: padding-left: 60px;
                    379: padding-right: 50px;
                    380: line-height: 120%;
                    381: background:url(topleft.jpg) no-repeat top left;
                    382: }
                    383: .content, .rc {
                    384: padding-top: 100px;
                    385: padding-left: 80px;
                    386: padding-right: 50px;
                    387: line-height: 120%;
                    388: }
                    389: 
                    390: 
1.6       nick      391: p.footer {
                    392:  color: #000000;
                    393:  font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
                    394:  font-size: 8pt;
                    395:  margin: auto;
1.7       nick      396:  width: 500px;
1.6       nick      397:  background-color : transparent;
                    398:  border-top: 1px solid #888888;
                    399:  padding-top: 3px;
                    400:  padding-bottom: 3px;
                    401:  padding-left: 3px;
                    402:  padding-right: 3px;
                    403:  text-align: center;
1.5       nick      404: }
                    405: 
                    406: 
                    407: .header {
                    408: float: right;
                    409: margin-top: 30px;
                    410: margin-right: 50px;
                    411: padding: 10px;
                    412: padding-top: 10px,10px,10px,10px;
                    413: 
                    414: }
                    415: pre {
                    416:     border: #777777 1px dashed;
                    417:     padding: 0.5em;
                    418:     margin-left: 1em;
                    419:     margin-right: 2em;
                    420:     white-space: pre;
                    421:     background-color: #fbfdff;
                    422:     color: black;
                    423:     font-size:12px;
                    424: }
                    425: 
                    426: .refer {
                    427:        padding-left: 60px;
                    428:        padding-right: 50px;
                    429:        margin-right: 50px;
                    430:        margin-left: 50px;
                    431:        font-size:80%;
                    432: }
                    433: 
                    434: .gotobar {
                    435:        color: #191970; 
                    436:        font-size:10px;
                    437: }
                    438: 
                    439: .edit bar {
                    440:        color: #949ce5; 
                    441: }
                    442: 
                    443: .contactInfo {
                    444:        font-size:12px;
                    445:        text-align:center;
                    446: }
                    447: 
                    448: .workHeader {
                    449:        text-align:left;
                    450:        font-size:13px;
                    451:        text-decoration:none;
                    452:        font-weight:normal;
                    453: }
                    454: 
                    455: .workHeaderDate {
                    456:        float: right;
                    457: }
                    458: 
                    459: .workHeaderStrong {
                    460:        font-size:15px;
                    461:        text-decoration:none;
                    462:        font-weight:bolder;
                    463: }
                    464: 
                    465: .jobDescription {
                    466:        padding-top:15px;
                    467:        font-size:13px;
                    468: }
                    469: 
                    470: .bulletContent {
                    471:        font-size:13px;
                    472: }
                    473: 
                    474: .leftCol {
                    475:        width:10.2em;
                    476:        position:absolute;
                    477:        top:0;
                    478:        font-size:13px;
                    479:        padding-left:1%;
                    480:        padding-right:1%;
                    481: }
                    482: 
                    483: .rightCol {
                    484:        width:10.2em;
                    485:        position:absolute;
                    486:        top:0;
                    487:        font-size:13px;
                    488:        padding-left:1%;
                    489:        padding-right:1%;
                    490: }
                    491: 
                    492: a:link {color:#082e58;  text-decoration: none; font-weight:bolder;}
                    493: a:visited {color:#7795b7; font-weight:normal; text-decoration:none;}
                    494: a:hover {color:#949ce5;}
                    495: 
                    496: 
                    497: a.definition:before { content:"[::"; }
                    498: a.definition:after { content:"]"; }
                    499: a.alias { text-decoration:none; border-bottom: thin dashed; }
                    500: a.near:link { color:#093; }
                    501: a.near:visited { color:#550; }
                    502: a.upload:before { content:"<"; }
                    503: a.upload:after { content:">"; }
                    504: a.outside:before { content:"["; }
                    505: a.outside:after { content:"]"; }
                    506: img.logo { float: right; clear: right; border-style:none; }
                    507: div.diff { padding-left:5%; padding-right:5%; }
                    508: div.old { background-color:#FFFFAF; }
                    509: div.new { background-color:#CFFFCF; }
                    510: div.message { background-color:#FEE; }
                    511: div.journal h1 { font-size:large; }
                    512: table.history { border-style:none; }
                    513: td.history { border-style:none; }
                    514: span.result { font-size:larger; }
                    515: span.info { font-size:smaller; font-style:italic; }
                    516: div.rss { background-color:#EEF; }
                    517: div.sister { float:left; margin-right:1ex; background-color:#FFF; }
                    518: div.sister p { margin-top:0; }
                    519: div.sister img { border:none; }
                    520: div.near { background-color:#EFE; }
                    521: div.near p { margin-top:0; }
                    522: </style>
                    523: EOF
                    524: 
                    525: }
                    526: 
1.1       nick      527: __END__
                    528: 
                    529: =head1 NAME
                    530: 
                    531: masterbuild.pl - blurb
                    532: 
                    533: =head1 SYNOPSIS
                    534: 
                    535: masterbuild.pl [options]
                    536: 
                    537:  Options:
                    538:         --help,?        Display the basic help menu
                    539:         --man,m         Display the detailed man page
                    540: 
                    541: =head1 DESCRIPTION
                    542: 
                    543: =head1 HISTORY
                    544: 
                    545: =head1 AUTHOR
                    546: 
                    547: Nicholas DeClario <nick@declario.com>
                    548: 
                    549: =head1 BUGS
                    550: 
                    551: This is a work in progress.  Please report all bugs to the author.
                    552: 
                    553: =head1 SEE ALSO
                    554: 
                    555: =head1 COPYRIGHT
                    556: 
                    557: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>