Important alert: (current site time 7/15/2013 8:37:58 PM EDT)
 

VB icon

Calendar Script V2

Email
Submitted on: 3/15/2003 5:30:44 AM
By: Randy McCleary 
Level: Beginner
User Rating: By 12 Users
Compatibility: 5.0 (all versions)
Views: 14831
(About the author)
 
     This is Version 2 of the Calendar Script i submited previously. Added a few new things to this version. It will display the current Month and year, with the current day selected. Also, navigation links were added to advance and go back to previous months, year, etc

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Calendar Script V2
= Description:This is Version 2 of the Calendar Script i submited previously. Added a few new things to this version. It will display the current Month and year, with the current day selected. Also, navigation links were added to advance and go back to previous months, year, etc
= By: Randy McCleary
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=425&lngWId=6=for details.=**************************************

#!/usr/bin/perl -w
###################################################
## Calendar Script V2
## This script will display the current Month and
## year, with the current day selected. Also,
## navigation links were added to advance and go
## back to previous months, year, etc
###################################################
use POSIX;
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Time::Local;
###################################################
## Define Globals
###################################################
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $month_name= 'jan';
my $time_t=0;
my @attribs = ();
my $start_day=0;
my @month_days = ();
my $days_in_month=0;
my $prev_mon =0;
my $next_mon =0;
my $curr_mon = $mon;
my $prev_year=0;
my $next_year=0;
my $curr_year = $year + 1900;
	
&init();
&Display_Calendar();
	
	
###################################################
## Sub to Initiate the calendar
###################################################
sub init {
		print header;
		$year += 1900;
		
		#########################################
		## If the Month and Year Params exist 
		## then get the values
		#########################################
		if (param()) {
			$mon = param('m');
			$year = param('y');
		}
		
		#################################################
		## If Current Mon is Jan then make the previous
		## month December of the previous year
		#################################################
		if ($mon == 0) {
			$prev_mon = 11;
			$prev_year= $year - 1;
		}
		else {
			$prev_mon = $mon - 1;
			$prev_year= $year;
		}
		
		#################################################
		## If Current Mon is Dec then make the Next
		## month Jan of the Next year
		#################################################
		if ($mon == 11) {
			$next_mon = 0;
			$next_year = $year + 1;
		}
		else {
			$next_mon = $mon + 1;
			$next_year= $year;
		}
		$time_t = POSIX::mktime(0, 0, 1, 1, $mon, $year-1900);
		@attribs = localtime($time_t);
		$start_day = @attribs[6] + 1;
		
		@month_days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		$days_in_month = @month_days[$mon];
		$month_name = ("January", "February", "March", 
								"April", "May", "June", "July", 
								"August", "September", "October", 
								"November", "December")[$mon];
		
		
		
		#########################
		## Check for leap year
		#########################
		if($mon == 1) {
			if($year%4 == 0 && $year%100 == 0 && $year%400 == 0) {
				$days_in_month = 29;
			} 
			elsif($year%4 == 0 && $year%100 != 0) {
				$days_in_month = 29;
			}
		}
				
		$days_in_month += $start_day - 1;
}
###################################################
## Sub to Diplay the generated Calendar Month
###################################################
sub Display_Calendar {
		
		###################################################
		## Begin to Print out the Calendar in a Table
		###################################################
		print "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" bgcolor=\"#336699\">\n";
		print "	<tr>\n";
		print "		<th>< a href=\"?m=$prev_mon&y=$prev_year\"><font color=\"#FFFFFF\"><<</font></ a>";
		print "		<th colspan=\"5\"><font color=\"#FFFFFF\">$month_name $year</font></th>\n";
		print "		<th>< a href=\"?m=$next_mon&y=$next_year\"><font color=\"#FFFFFF\">>></font></ a>";
		print "	</tr>\n";
		print "	<tr>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">S</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">M</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">T</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">W</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">T</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">F</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">S</th>\n";
		print "	</tr>\n";
		
		my $day = 1;
		my $count = 0;
		my $temp = 0;
		
		for(my $i=1; $i<=$days_in_month; $i++) {
			if($count == 0) { 
				print "		<tr>\n"; 
			}
			
			if($count % 7 == 0 && $count != 0) { 
				print "		</tr><tr>\n"; 
			}
			
			if($i < $start_day) {
				print "			<td bgcolor=\"#EFEFEF\" align=\"center\">-</td>\n";
			} 
			else {
				if($day == $mday && $year == $curr_year && $mon == $curr_mon) {
					print "			<td bgcolor=\"#FFFF00\" align=\"center\"><b>$day</b></td>\n";
				} 
				else {
					print "			<td bgcolor=\"#FFFFFF\" align=\"center\">$day</td>\n";
				}
				
				$day++;
			}
			
			if($i == $days_in_month && $count % 7 != 6 ) {
				$temp = 6 - $count % 7;
				
				for(my $j=1; $j <= $temp; $j++) {
					print "			<td bgcolor=\"#EFEFEF\" align=\"center\">-</td>\n";
				}
				
				print "		</tr></table>\n";
			}
			
			$count++;
		}
}
	
	
	
	
	
	
	


Other 28 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/17/2003 5:58:40 PM

This is good. It didn't render right at first because of the space between the "a" and the "href", but it works great now
(If this comment was disrespectful, please report it.)

 
3/17/2003 8:06:58 PMRandy McCleary

Yeah, PSC doen't allow you to upload scripts with HREF, A, Input, and other Fields so i put a space in there so you can view the code.
(If this comment was disrespectful, please report it.)

 
3/19/2003 4:29:21 PM

Ha, ok... any idea why PSC won't show my name on comments?
(If this comment was disrespectful, please report it.)

 
3/19/2003 4:39:48 PMRandy McCleary

It's not showing your name, because your not a register Author. When you sign up to Upload code, then it'll start showing your name. Don't know why they don't display the name you type in the textbox anymore.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.