Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Could This EVER Have Worked? 1

Status
Not open for further replies.

artcabot

Programmer
Dec 14, 2003
12
0
0
US
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 = &quot;0$month&quot;; }

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 = &quot;0$lm&quot;; }
if ($nm < 10) { $nm = &quot;0$nm&quot;; }

my $start = &quot;${year}${month}01&quot;;
my $end = &quot;${year}${month}${dim}&quot;;
#print &quot;start: $start<br>\n&quot;;
#print &quot;end: $end<br>\n&quot;;

my $begin_dow = &strfCareDate(&quot;u&quot;,&quot;$start&quot;);
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,&quot;$db_dir/calendar.db&quot;);
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 == &quot;object&quot;) && (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=&quot;?nav_month=$lm&nav_year=$ly&quot;><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=&quot;?nav_month=$nm&nav_year=$ny&quot;><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 &quot;<tr>\n&quot;;
}
while ($begin_null_cnt < $begin_dow) {
print &quot;<td width=14% bgcolor=#cccccc> </td>\n&quot;;
$begin_null_cnt++;
$week_cnt++;
}
$day = $day_cnt;
if ($day < 10) { $day = &quot;0$day&quot;; }
$idx = &quot;$year$month$day&quot;;
$l_tit = $tit{$idx};
$l_tit =~ s/'/\\'/g;
$l_tit =~ s/&quot;/&quot;/g;
$b_tit = $tit{$idx};
$b_tit =~ s/&quot;/&quot;/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=&quot;clkCalBut('$idx','$l_tit');&quot; href=&quot;?nav_month=$month&nav_year=$year&quot;>$l_tit</a>
END
#<input type=button onClick=&quot;clkCalBut('$idx','$l_tit');&quot;
#value=&quot;ME $b_tit&quot;>
}
print <<END;
</font>
</td></tr></table>
</td>
END
$week_cnt++;
$day_cnt++;
if ($week_cnt == 7) {
print &quot;</tr>\n&quot;;
$week_cnt = 0;
}
}
while ($week_cnt > 0 && $week_cnt < 7) {
print &quot;<td width=14% bgcolor=#cccccc> </td>\n&quot;;
$week_cnt++;
}
print &quot;</table>\n&quot;;
}
 
artcabot,

Show &quot;us&quot; what work &quot;you've&quot; done to discern that it never worked.

--Paul

You want information, be specific

No I did not write the original code
 
I second that -- I'd like to help you but I got really tired of reading about 1/3 the way through.
 
1. I did not write the original code.
2. The client insists that it used to show multiple events for a given date.
3. Supposedly nothing has been done to this section, but the client can't remember when it stopped showing multiple events.
4. The events are in a pipe-delimited text file, calendar.db and are pulled out by this code:

open(DB,&quot;$db_dir/calendar.db&quot;);
while(<DB>) {
($show_date,$show_title) = split(/\|/,$_);
$tit{$show_date} = $show_title;
}
close(DB);

As you can see, $show_date (in the format yyyymmdd) is the index into $tit for each event, at least as I read it.

When putting the linkable event(s) into the individual cells of the displayed calendar, this is the code:

if ($tit{$idx}) {
print <<END;
<a onClick=&quot;clkCalBut('$idx','$l_tit');&quot; href=&quot;?nav_month=$month&nav_year=$year&quot;>$l_tit</a>
END
}
print <<END;

After this, the variable $day_cnt is incremented and it loops back to do the next day of the month.

Given this, I just don't see how more than one event, $tit($idx), can go into any one date cell.

That's what I'm trying to get some feedback on. Perl is not something I use on a regular basis, so I'd really appreciate some objective feedback. I'm sorry if I'm not providing enough information (or, in the case of the last reply, too much information).


Art Cabot
Strickland Technical Services, Inc.
Augusta GA
 
If it stores an event in a hash with the date the key and the value the title ([tt]$tit{$show_date} = $show_title;[/tt]), it can only store one event for that date. I don't see any way that code supports the functionality you're describing. Have you seen this code actully do that, or have you just been told that it does?

FFR: wrap any code inside [ignore]
Code:
 and
[/ignore] tags, it preserves whitespace and makes it more legible.

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
No, I've never seen it do what the client describes, and I can't see how it ever could've done it, at least as written here. I've already started re-writing it, but I just wanted to make sure I wasn't missing something obvious.

Art Cabot
Strickland Technical Services, Inc.
Augusta GA
 
It's definately only able to store 1 event per date. This guys blowin smoke out of his A**.

The following push each event into the hash. This will get you multiple event titles for each date.

Code:
while(<DB>) {
   ($show_date,$show_title) = split(/\|/,$_);
   chomp $show_title;
   push @{ $tit{$show_date} }, $show_title;
}

 
Got it working. This forum was a big help!

Art Cabot
Strickland Technical Services, Inc.
Augusta GA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top