File:  [Local Repository] / ConnorCalendar / calendar.pl
Revision 1.12: download - view: text, annotated - select for diffs
Thu Jun 15 01:52:15 2017 UTC (6 years, 11 months ago) by nick
Branches: MAIN
CVS tags: HEAD
Some coding errors I made a long time ago finally reared up.

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

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