use Time::Local; ################################################################ ### Get the formatting ready to print the small calendar ### Could change this to print multiple calendars ################################################################ sub print_update_league_calendar{ my $league = shift; my $month = shift; my $year = shift; my $form = shift; my $input_name = shift; ### if the month and year are not defined, use the current info if(!(defined($month))){ $month = get_current("month"); } if(!(defined($year))){ $year = get_current("year"); } print "
\n"; my ($next_month, $next_year) = get_next_month($month, $year, "next"); my ($prev_month, $prev_year) = get_next_month($month, $year, "prev"); print "
\n"; #print_calendar_small($prev_month,$prev_year,$league); #print "\n"; print_calendar_small($month,$year,$league,1,$form,$input_name); #print "\n"; #print_calendar_small($next_month,$next_year,$league); print "
\n"; print "
\n"; #print_calendar($month,$year,$league); print "
\n"; } ################################################################ ### print_calendar prints a calendar as a table give month and ### year ################################################################ sub print_calendar_small { my $current_month = shift; my $current_year = shift; my $league = shift; my $coach = shift; my $form = shift; my $input_name = shift; my $first_day_of_month = 0; my $last_day_of_month = 0; print_calendar_header_small($current_month,$current_year,$league,$form,$input_name); ($current_last,$current_last_dow) = get_last_day($current_month, $current_year); ### get the first day (mon, tue, etc) of the month to see if an extra days ### are needed from the previous month $first_day_of_month = get_day_of_week($current_month, 1, $current_year); if($first_day_of_month != 0){ for($i=$first_day_of_month;$i>0;$i--){ print_extra_day_small($current_month,$current_year,"previous",$i,1,$league, $coach); } } ### Loop through the days of the month to print them for($i=1;$i<=$current_last;$i++){ #print "$current_month/$i/$current_year\n"; print_calendar_day_small($current_month, $i, $current_year, "white", $league, $coach); } ### get the last day (mon, tue, etc) of the month to see if an extra days ### are needed from the next month $last_day_of_month = get_day_of_week($current_month, $current_last, $current_year); if($last_day_of_month != 6){ for($i=1;$i<=6-$last_day_of_month;$i++){ print_extra_day_small($current_month,$current_year,"following",$i,$current_last,$league,$coach); } } print_calendar_footer(); } ################################################################ ### print_calendar_day is used to print any day given the ### day, month and year ################################################################ sub print_calendar_day_small { my $current_month = shift; my $current_day = shift; my $current_year = shift; my $bgcolor = shift; my $league = shift; my $coach = shift; $coach = 1; my $current_time = timelocal(0,0,0,$current_day,$current_month-1,$current_year-1900); my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst); my ($obj_id,$time,$event_type,$home_team,$home_score,$away_team,$away_score,$description); ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($current_time); if($wday == 0){ print " \n"; } print " \n"; if($coach){ print " $current_day\n"; }else{ print " $current_day\n"; } print " \n"; if($wday == 6){ print " \n"; } } ################################################################ ### print_calendar_header is used to start the calendar ################################################################ sub print_calendar_header_small { my $current_month = shift; my $current_year = shift; my $league = shift; my $form = shift; my $input_name = shift; my $file_name = "print_cal.pl"; my $bgcolor = "#006699"; my $current_month_name = get_month_name_small($current_month); my ($next_month, $next_year) = get_next_month($current_month, $current_year, "next"); my ($prev_month, $prev_year) = get_next_month($current_month, $current_year, "prev"); print "\n"; print "\n"; } ################################################################ ### Get the Month name given the month number ################################################################ sub get_month_name_small{ my $month_number = shift; @months = ('','Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); return $months[$month_number]; } ################################################################ ### Get the Month before or after the given month ################################################################ sub get_next_month{ my $current_month = shift; my $current_year = shift; my $next_or_prev = shift; my $current_day = 27; my $next_month = $current_month; my $next_year = 0; my $current_time = timelocal(0,0,0,$current_day,$current_month-1,$current_year-1900); my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst); while($next_month == $current_month){ if($next_or_prev eq "next"){ $current_time = $current_time + (60*60*24); }else{ $current_time = $current_time - (60*60*24); } ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($current_time); $month = $month +1; if($month != $current_month){ $next_month = $month; $next_year = $year + 1900; } } return $next_month, $next_year; } ################################################################ ### Get the current (month or year) ### Inputs: Month or year ### Return: Current (Month Or Year) ################################################################ sub get_current { my $return_type = shift; my $current_time = timelocal((localtime)[0..5]); my $return_string = 0; my($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($current_time); if($return_type eq "year"){ #Add 1900 to Years, because it begins at 1900, ex 2004=104; $year = $year + 1900; $return_string = $year; }elsif($return_type eq "month"){ #Jan = 0 $month = $month +1; $return_string = $month; } return $return_string; } ################################################################ ### Get the last day of the month ### Inputs: Month and year of the last day ### Return: Last day of the month ################################################################ sub get_last_day { my $current_month = shift; my $current_year = shift; my $return_string = 0; my $last_day = 28; my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst); $month = $current_month; $current_time = timelocal(0,0,0,$last_day,$current_month-1,$current_year-1900); while($month == $current_month){ $current_time = $current_time + (60 * 60 * 24); ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($current_time); #Jan = 0 so add one $month++; if($month != $current_month){ $return_day = $last_day; }else{ $last_day = $day; } } return $return_day,$return_dow; } ################################################################ ### Get the day of week (mon, tue, etc) ### Inputs: Month day year ### Return: Day of the week ################################################################ sub get_day_of_week { my $current_month = shift; my $current_day = shift; my $current_year = shift; my $return_string = 0; my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst); $current_time = timelocal(0,0,0,$current_day,$current_month-1,$current_year-1900); ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($current_time); $return_string = $wday; return $return_string; } ################################################################ ### print_extra_day is used to print the days before and ### after the month to fill the calendar - This is for small cal ################################################################ sub print_extra_day_small { my $current_month = shift; my $current_year = shift; my $extra_type = shift; my $days_offset = shift; my $start_day = shift; my $league = shift; my $coach = shift; my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst); my $current_time = timelocal(0,0,0,$start_day,$current_month-1,$current_year-1900); ### Determine if the day is before or after the month ### and Calculate the offset in epoch seconds if($extra_type eq "previous"){ $current_time = $current_time - (60*60*24*$days_offset); }elsif($extra_type eq "following"){ $current_time = $current_time + (60*60*24*$days_offset); } ### Change to Real Date ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($current_time); $month++; $year = $year + 1900; ### Print the day print_calendar_day_small($month, $day, $year, "gray", $league, $coach); #print "$month/$day/$year\n"; } ################################################################ ### print_calendar_footer closes the calendar ################################################################ sub print_calendar_footer { print "
<<     $current_month_name $current_year     >>
SMTWTFS
\n"; } ################################################################ ### Style Sheet for Calendar ################################################################ sub print_cal_style{ print <<__HTML__; __HTML__ } 1;