Quick Search for:  in language:    
Version,Calendar,Script,submited,previously,A
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Perl Stats

 Code: 74,273. lines
 Jobs: 25. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for Perl.
Click here to see a screenshot of this code!Mailing List v2.0
By Aaron L. Anderson on 1/7

(Screen Shot)

ShowIMG
By Jeff Mills on 1/5


Simple Perl Ping
By John Hass on 12/29


Very basic login script template with cookies
By Aaron L. Anderson on 12/29


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Calendar Script V2

Print
Email
 
VB icon
Submitted on: 3/15/2003 5:30:44 AM
By: Randy McCleary 
Level: Beginner
User Rating: By 12 Users
Compatibility:5.0 (all versions)

Users have accessed this code 3086 times.
 
(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 C
    =     alendar Script i submited previously. Ad
    =     ded a few new things to this version. It
    =     will display the current Month and year,
    =     with the current day selected. Also, nav
    =     igation 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://w
    =     ww.Planet-Source-Code.com/vb/scripts/Sho
    =     wCode.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 notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
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
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/17/2003 8:06:58 PM:Randy 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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/19/2003 4:29:21 PM:
Ha, ok... any idea why PSC won't show 
my name on comments?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/19/2003 4:39:48 PM:Randy 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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Perl Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.