Your question was
I've been called in to fix an events calendar that supposedly used to show multiple events on a given day. However, it doesn't look like the code I inherited could EVER have done that because of the indexing method used. Am I missing something? The first two elements in each row of calendar.db are the event date (as yyyymmdd) and the event name.
The code is below.
Thanks.
The code:
sub viewCalendar() {
require "$lib_dir/dateLib.pl";
my($month,$year) = @_;
$month = $month - 0;
if ($month < 10 ) {$month = "0$month"; }
my @days = qw/Sunday Monday Tuesday Wednesday Thursday Friday Saturday/;
my ($dim) = &daysInMonth($month,$year);
# Get info needed for bag and next links
my $lm = $month - 1;
my $ly = $year;
my $nm = $month + 1;
my $ny = $year;
if ($lm == 0) {
$lm = 12;
$ly--;
}
if ($nm == 13) {
$nm = 1;
$ny++;
}
if ($lm < 10) { $lm = "0$lm"; }
if ($nm < 10) { $nm = "0$nm"; }
my $start = "${year}${month}01";
my $end = "${year}${month}${dim}";
#print "start: $start<br>\n";
#print "end: $end<br>\n";
my $begin_dow = &strfCareDate("u","$start"
if ($begin_dow == 7) { $begin_dow = 0; }
my $w_month = &convMonth($month - 1,'','L');
my $w_lm = &convMonth($lm - 1,'','L');
my $w_nm = &convMonth($nm - 1,'','L');
# Now that we have all the variable for the calendar
# out of the way we need to read in the data file
open(DB,"$db_dir/calendar.db"
while(<DB>) {
($show_date,$show_title) = split(/\|/,$_);
$tit{$show_date} = $show_title;
}
close(DB);
print<<END;
<script language=javascript>
<!--
function clkCalBut(tmp_date,tmp_title) {
document.calForm.tmp_date.value = tmp_date;
document.calForm.tmp_title.value = tmp_title;
popUp();
}
function popUp() {
if ( (typeof popupwindow == "object" && (popupwindow.closed != true)) {
popupwindow.focus();
} else {
popupwindow = window.open('calDetail.pl','_caldetail','resizeable=no,scrollbars=no,width=386,height=405');
popupwindow.focus();
}
document.calForm.target = '_caldetail';
document.calForm.action = 'calDetail.pl';
document.calForm.submit();
}
//-->
</script>
<form method=post target=_new name=calForm action=calDetail.pl>
<input type=hidden name=tmp_date>
<input type=hidden name=tmp_title>
</form>
<table width=95% bgcolor=#000000 border=0>
<tr><td colspan=7 bgcolor=#000000>
<table width=100%>
<tr><td width=22%>
<a href="?nav_month=$lm&nav_year=$ly"><font face=verdana color=white><b>$w_lm $ly</b></font></a>
</td><td width=56% align=center>
<font color=white face=verdana size=+2><b>$w_month<br>$year</b></font>
</td><td width=22% align=right>
<a href="?nav_month=$nm&nav_year=$ny"><font face=verdana color=white><b>$w_nm $ny</b></font></a>
</td></tr>
</table>
</td></tr>
END
$begin_null_cnt = 0;
$day_cnt = 1;
$week_cnt = 0;
while ($day_cnt <= $dim) {
if ($week_cnt == 0) {
print "<tr>\n";
}
while ($begin_null_cnt < $begin_dow) {
print "<td width=14% bgcolor=#cccccc> </td>\n";
$begin_null_cnt++;
$week_cnt++;
}
$day = $day_cnt;
if ($day < 10) { $day = "0$day"; }
$idx = "$year$month$day";
$l_tit = $tit{$idx};
$l_tit =~ s/'/\\'/g;
$l_tit =~ s/"/"/g;
$b_tit = $tit{$idx};
$b_tit =~ s/"/"/g;
print <<END;
<td width=14% bgcolor=#ffffff valign=top height=75>
<table border=0 width=100%>
<tr><td bgcolor=#cccccc>
<font size=-2 face=arial>$day_cnt</font></td></tr>
<tr><td bgcolor=#ffffff>
<font size=-2 face=arial>
END
if ($tit{$idx}) {
print <<END;
<a onClick="clkCalBut('$idx','$l_tit');" href="?nav_month=$month&nav_year=$year">$l_tit</a>
END
#<input type=button onClick="clkCalBut('$idx','$l_tit');"
#value="ME $b_tit">
}
print <<END;
</font>
</td></tr></table>
</td>
END
$week_cnt++;
$day_cnt++;
if ($week_cnt == 7) {
print "</tr>\n";
$week_cnt = 0;
}
}
while ($week_cnt > 0 && $week_cnt < 7) {
print "<td width=14% bgcolor=#cccccc> </td>\n";
$week_cnt++;
}
print "</table>\n";
}
I've been called in to fix an events calendar that supposedly used to show multiple events on a given day. However, it doesn't look like the code I inherited could EVER have done that because of the indexing method used. Am I missing something? The first two elements in each row of calendar.db are the event date (as yyyymmdd) and the event name.
The code is below.
Thanks.
The code:
sub viewCalendar() {
require "$lib_dir/dateLib.pl";
my($month,$year) = @_;
$month = $month - 0;
if ($month < 10 ) {$month = "0$month"; }
my @days = qw/Sunday Monday Tuesday Wednesday Thursday Friday Saturday/;
my ($dim) = &daysInMonth($month,$year);
# Get info needed for bag and next links
my $lm = $month - 1;
my $ly = $year;
my $nm = $month + 1;
my $ny = $year;
if ($lm == 0) {
$lm = 12;
$ly--;
}
if ($nm == 13) {
$nm = 1;
$ny++;
}
if ($lm < 10) { $lm = "0$lm"; }
if ($nm < 10) { $nm = "0$nm"; }
my $start = "${year}${month}01";
my $end = "${year}${month}${dim}";
#print "start: $start<br>\n";
#print "end: $end<br>\n";
my $begin_dow = &strfCareDate("u","$start"
if ($begin_dow == 7) { $begin_dow = 0; }
my $w_month = &convMonth($month - 1,'','L');
my $w_lm = &convMonth($lm - 1,'','L');
my $w_nm = &convMonth($nm - 1,'','L');
# Now that we have all the variable for the calendar
# out of the way we need to read in the data file
open(DB,"$db_dir/calendar.db"
while(<DB>) {
($show_date,$show_title) = split(/\|/,$_);
$tit{$show_date} = $show_title;
}
close(DB);
print<<END;
<script language=javascript>
<!--
function clkCalBut(tmp_date,tmp_title) {
document.calForm.tmp_date.value = tmp_date;
document.calForm.tmp_title.value = tmp_title;
popUp();
}
function popUp() {
if ( (typeof popupwindow == "object" && (popupwindow.closed != true)) {
popupwindow.focus();
} else {
popupwindow = window.open('calDetail.pl','_caldetail','resizeable=no,scrollbars=no,width=386,height=405');
popupwindow.focus();
}
document.calForm.target = '_caldetail';
document.calForm.action = 'calDetail.pl';
document.calForm.submit();
}
//-->
</script>
<form method=post target=_new name=calForm action=calDetail.pl>
<input type=hidden name=tmp_date>
<input type=hidden name=tmp_title>
</form>
<table width=95% bgcolor=#000000 border=0>
<tr><td colspan=7 bgcolor=#000000>
<table width=100%>
<tr><td width=22%>
<a href="?nav_month=$lm&nav_year=$ly"><font face=verdana color=white><b>$w_lm $ly</b></font></a>
</td><td width=56% align=center>
<font color=white face=verdana size=+2><b>$w_month<br>$year</b></font>
</td><td width=22% align=right>
<a href="?nav_month=$nm&nav_year=$ny"><font face=verdana color=white><b>$w_nm $ny</b></font></a>
</td></tr>
</table>
</td></tr>
END
$begin_null_cnt = 0;
$day_cnt = 1;
$week_cnt = 0;
while ($day_cnt <= $dim) {
if ($week_cnt == 0) {
print "<tr>\n";
}
while ($begin_null_cnt < $begin_dow) {
print "<td width=14% bgcolor=#cccccc> </td>\n";
$begin_null_cnt++;
$week_cnt++;
}
$day = $day_cnt;
if ($day < 10) { $day = "0$day"; }
$idx = "$year$month$day";
$l_tit = $tit{$idx};
$l_tit =~ s/'/\\'/g;
$l_tit =~ s/"/"/g;
$b_tit = $tit{$idx};
$b_tit =~ s/"/"/g;
print <<END;
<td width=14% bgcolor=#ffffff valign=top height=75>
<table border=0 width=100%>
<tr><td bgcolor=#cccccc>
<font size=-2 face=arial>$day_cnt</font></td></tr>
<tr><td bgcolor=#ffffff>
<font size=-2 face=arial>
END
if ($tit{$idx}) {
print <<END;
<a onClick="clkCalBut('$idx','$l_tit');" href="?nav_month=$month&nav_year=$year">$l_tit</a>
END
#<input type=button onClick="clkCalBut('$idx','$l_tit');"
#value="ME $b_tit">
}
print <<END;
</font>
</td></tr></table>
</td>
END
$week_cnt++;
$day_cnt++;
if ($week_cnt == 7) {
print "</tr>\n";
$week_cnt = 0;
}
}
while ($week_cnt > 0 && $week_cnt < 7) {
print "<td width=14% bgcolor=#cccccc> </td>\n";
$week_cnt++;
}
print "</table>\n";
}