********** July 23rd calendar application handout ********** --------------------------------------------------------------------------- **> calendar.cgi <** Displays FORM, submits its data to showCalendar.cgi --------------------------------------------------------------------------- #!/usr/bin/perl -w use CGI ':standard'; require "myCGI.lib"; &printHeader; print &first_html('Calendar Display by month or entire year'), &ruler, start_form(-action => 'showCalendar.cgi'), "\n

\n", "\nMonth(s): ", br, textfield('months'), br, "\nYear: ", br, textfield('year'), p, "\n", submit('show calendar'), "\n", "\n

\n", &end_form, &ruler, &heading (4, "
    \n
  1. This month? Leave both fields blank. \n" . "
  2. Months from this year? Leave the year blank.\n" . "
  3. 12 month calendar for a year? \n" . " Fill in the year value. \n" . " Leave the months field blank. \n" . "
  4. Months must be separated by commas. 1,3,8,12\n" . " or specify a range with a hyphen, such as: \n" . " 5-8 or 9-12 or 8-5, for example. " . "\n
\n"), &ruler, &heading(1, "Thanks for using the Wright Calendar!", "center"), &last_html; ----------------------------------------------------------------------------- **> showCalendar.cgi <** This is the -action => script for calendar.cgi ----------------------------------------------------------------------------- #!/usr/bin/perl -w # Written on Sunday, July 22nd, 2001 -- Filename: showCalendar.cgi use CGI qw(:standard); require "myCGI.lib"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$dst) = localtime(time); $M12 = "1,2,3,4,5,6,7,8,9,10,11,12"; $theYear = ((length param('year') == 0) ? $year + 1900 : param('year')); if (length param('months') == 0) { $months = ((length param('year') == 0) ? $mon : $M12); } else { $months = param('months'); } $calOut = "\n
\n";

if ($months eq $M12)
{
   $calOut .= `cal $theYear`;
   $headingSize = 2;
}
else
{
   @m = (split /,/, $months);

   foreach (@m)
   {
      if ($_ =~ /-/)
      {
         $calOut .= &hyphenatedMonths($_, $theYear);
      }
      else
      {
         $calOut .= `cal $_ $theYear`;
      }
   }
   $headingSize = 1;
}

$calOut .= "
"; print header; print first_html("Calendar Display"), hr, heading($headingSize, $calOut), hr, &last_html; ############################ hyphenatedMonths ########################### sub hyphenatedMonths { $h = shift @_; $y = shift @_; ($startMonth, $stopMonth) = split /-/, $h; $s2 = ""; if ($startMonth > $stopMonth) { $nextYear = $y + 1; for ($month = 1; $month <= $stopMonth; $month++) { $s2 .= `cal $month $nextYear`; } $stopMonth = 12; } $s = ""; for ($month = $startMonth; $month <= $stopMonth; $month++) { $s .= `cal $month $y`; } return $s . $s2; } ---------------------------------------------------------------------------- **> myCGI.lib <** ---------------------------------------------------------------------------- require "guestBook.lib"; # Created on Thursday 07/19/2001 during lab. # myCGI.lib has first_html(), last_html(), ruler() and heading() # printHeader() ----- added on Sunday, July 22nd. sub printHeader { print "Content-type: text/html\n\n"; } sub first_html { @a = &rgbValue; $st = "\n$_[0]\n" . qq( \n ) . "

$_[0]

\n"; return $st; } sub last_html { return "\n\n\n"; } sub ruler { return "\n
\n"; } sub center { return "\nCENTER>\n $_ \n\n"; } sub heading { if ($_[0] >= 1 && $_[0] <= 5) { $n = shift (@_); } else { $n = 1; #

is the default heading style } $h = shift (@_); if (pop @_ eq "center") { return "\n
\n $h \n\n
\n"; } else { return "\n $h \n \n"; } } 1; ----------------------------------------------------------------------------- VIEW SOURCE for **>showCalendar.cgi<** (months was 11-2 and year was empty) ----------------------------------------------------------------------------- Calendar Display

Calendar Display


   November 2001
 S  M Tu  W Th  F  S
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30

   December 2001
 S  M Tu  W Th  F  S
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31                        <----- Notice the slimer or bug here!
   January 2002                     SHOULD BE DOUBLE SPACED!
 S  M Tu  W Th  F  S                Needs 1 BLANK LINE before January 2002
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31


   February 2002
 S  M Tu  W Th  F  S
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28


----------------------------------------------------------------------------- VIEW SOURCE for ** calendar.cgi ** ** calendar.cgi OUTPUT ** ----------------------------------------------------------------------------- Calendar Display by month or entire year

Calendar Display by month or entire year


Month(s):

Year:


  1. This month? Leave both fields blank.
  2. Months from this year? Leave the year blank.
  3. 12 month calendar for a year? Fill in the year value. Leave the months field blank.
  4. Months must be separated by commas. 1,3,8,12 or specify a range with a hyphen, such as: 5-8 or 9-12 or 8-5, for example.


Thanks for using the Wright Calendar!