Hi All,
I am adding a calendar coded in cgi to my page.As i can use a JS calendar also but it have to do it with cgi only.
my present calendar prints current month on the page.Now here the problem comes.
I want each & every date to be hyperlinked so that i can select any date of any month and fetch the results for that date accordingly.
Please find below the code:
#!/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++;
}
}
Please help me in this. There is no bar that i have to use onnly this calenadar. if some has another calendar made in cgi with the required features, please share...
P.S. I am using it on UNIX box
Thanks in advance. :-)