File:  [Local Repository] / ConnorCalendar / calendar.pl
Revision 1.6: download - view: text, annotated - select for diffs
Wed May 29 03:27:02 2013 UTC (10 years, 11 months ago) by nick
Branches: MAIN
CVS tags: HEAD
Made things look cleaner.  Code does need some cleanup as well...

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

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