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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar

Status
Not open for further replies.

uniopp

Technical User
Oct 7, 2001
152
JP
Hello,
I have a perl script that generates a calendar layout something like the following:

----------------------------------October-2009-------------------------
Monday--Tuesday--Wednesday--Thursday--Friday--Saturday--Sunday
------------------------1--------2---------3-------4------40
------------------------------data----data-------data----data
--5--------6--------7----------8--------9--------10------11------41
-data-----data----data--------data----data-------data----data
--12-------13------14----------15------16---------17-----18------42
-data-----data----data--------data----data-------data----data
--19-------20------21----------22------23---------24-----25------43
-data-----data----data--------data----data-------data----data
--26-------27------28----------29------30---------31-------------43
-data-----data----data--------data----data-------data------------

I have been trying for hours (days actually) to add two additional table rows
under each row of data. I will be adding additional code to fetch more data but
each new cell should just print the day value for the cell it is under.
The first week (which doesn't have data in the first three days)should look like:

-----------------------October-2009-------------------------
Monday--Tuesday--Wednesday--Thursday--Friday--Saturday--Sunday
-------------------------------1--------2---------3-------4------40
------------------------------data----data-------data----data
-------------------------------1--------2---------3-------4------40
------------------------------data----data-------data----data
-------------------------------1--------2---------3-------4------40
with the following weeks having data/day numbers where day numbers are not blank.

I have tried inserting a new row in almost every part of the following subs but I just
can't get it to work.
Hopefully there is enough code included below for someone to show me how to do it and
where exactly to put the extra code.
Thanks.

Code:
sub create {

$requested_calendar=$_[1];
$calendar_year=$_[2];
$calendar_month=$_[3];
  
  my $this = shift;
  my ($html, $i, $start, $stop, $title, $daycount, $inThisMonth);
  my ($days, $weekNr, $ind, $class, $style, $content, $date);
  my ($sec, $min, $hr, $curDay, $curMonth, $curYear, $wday, $yday, $stime) = localtime(time);

  $curYear += 1900;
  $curMonth += 1;

  $this->{size} = ($this->{hFontSize} > $this->{dFontSize}) ? $this->{hFontSize} : $this->{dFontSize};
  if($this->{wFontSize} > $this->{size}) { $this->{size} = $this->{wFontSize}; }

  if($this->{year} < 1 || $this->{year} > 3999) { $html = '<b>' . $this->{error}[0] . '</b>'; }
  elsif($this->{month} < 1 || $this->{month} > 12) { $html = '<b>' . $this->{error}[1] . '</b>'; }
  else {
    $this->{mDays}[1] = $this->leap_year($this->{year}) ? 29 : 28;
    for($i = $days = 0; $i < $this->{month} - 1; $i++) { $days += $this->{mDays}[$i]; }

    $start = $this->get_weekday($this->{year}, $days);
    $stop = $this->{mDays}[$this->{month}-1];

    $html = $this->set_styles();
#cell days border lines table
$html .= '<table border=0 cellspacing=0 cellpadding=0><tr>';
$html .= '<td' . ($this->{borderColor} ? ' bgcolor=' . $this->{borderColor}  : '') . '>';
#cell days table
    $html .= '<table border=0 cellspacing=1 cellpadding=3>';
#prints the month and year title
    $title = $this->{months}[$this->{month}-1] . ' ' . $this->{year};
    $html .= $this->table_head($title);
    $daycount = 1;

    if(($this->{year} == $curYear) && ($this->{month} == $curMonth)) { $inThisMonth = 1; }
    else { $inThisMonth = 0; }

    if($this->{weekNumbers}) { $weekNr = $this->get_week($this->{year}, $days); }

    while($daycount <= $stop) {
      $html .= '<tr>';

      for($i = $wdays = 0; $i <= 6; $i++) {
        $ind = ($i + $this->{offset}) % 7;
        if($ind == 0) { $class = 'cssSaturdays'; }
        elsif($ind == 1) { $class = 'cssSundays'; }
        else { $class = 'cssDays'; }

        $style = '';
        $date = $this->{month} . '-' . $this->{month} . '-' . $daycount;
#prints blanks for days without numbers
        if(($daycount == 1 && $i < $start) || $daycount > $stop) { $content = '&nbsp;'; }
        else {

#Go and get some info based on the table cell date
#determine the cell date
$cell_year=$display_year;
$cell_month=$display_month;
$cell_day=$daycount;
$get_data = get_data($calendar_year,$calendar_month,$cell_day);
        

          $content = "$daycount<br>$get_data";
          if($inThisMonth && $daycount == $curDay) {
            $style = 'padding:0px;border:3px solid ' . $this->{tdBorderColor} . ';';
          }
          elsif($this->{year} == 1582 && $this->{month} == 10 && $daycount == 4) { $daycount = 14; }
          $daycount++;
          $wdays++;
          
        }
        $html .= $this->table_cell($content, $class . $cal_ID, $date, $style);
        
      }
  
      if($this->{weekNumbers}) {
        if(!$weekNr) {
          if($this->{year} == 1) { $content = '&nbsp;'; }
          elsif($this->{year} == 1583) { $content = 52; }
          else { $content = $this->get_week($this->{year} - 1, 365); }
        }
        elsif($this->{month} == 12 && $weekNr >= 52 && $wdays < 4) { $content = 1; }
        else { $content = $weekNr; }

        $html .= $this->table_cell($content, 'cssWeeks' . $cal_ID);
        $weekNr++;
      }
      $html .= '</tr>';

}
$html .= '</table></td></tr></table>';

  }
  return $html;
}



sub table_head {
  my ($this, $content) = @_;
  my ($html, $i, $ind, $wDay);
  my $cols = $this->{weekNumbers} ? 8 : 7;
#this prints the month and year title row
  $html = '<tr><td colspan=' . $cols . ' class="cssTitle' . $cal_ID . '" align=center><b>' .
          $content . '</b></td></tr><tr>';
          
  for($i = 0; $i < int @{$this->{weekdays}}; $i++) {
    $ind = ($i + $this->{offset}) % 7;
    $wDay = $this->{weekdays}[$ind];
#this prints the day names
    $html .= $this->table_cell($wDay, 'cssHeading' . $cal_ID);
  }
#if we are printing week numbers, this puts a blank cell at the top of the column  
  if($this->{weekNumbers}) { $html .= $this->table_cell('&nbsp;', 'cssHeading' . $cal_ID); }
  $html .= '</tr>';

  return $html;
}


sub table_cell {
  my ($this, $content, $class, $date, $style) = @_;
  my ($size, $html, $link);
  $size = _round($this->{size} * 1.5);
  
  $html = '<td align=center width=' . $size . ' class="' . $class . '"';

  if($content ne '&nbsp;' && $class =~ m/day/i) {
    $link = $this->{link};

    if($this->{specDays}{$content}) {
      if($this->{specDays}{$content}[0]) {
        $style .= 'background-color:' . $this->{specDays}{$content}[0] . ';';
      }
      if($this->{specDays}{$content}[1]) {
        $html .= ' title="' . $this->{specDays}{$content}[1] . '"';
      }
      if($this->{specDays}{$content}[2]) {
        $link = $this->{specDays}{$content}[2];
      }
    }
    if($link) {
      $html .= ' onMouseOver="this.className=\'cssHilight' . $cal_ID . '\'"';
      $html .= ' onMouseOut="this.className=\'' . $class . '\'"';
      $html .= ' onClick="document.location.href=\'' . $link . '?date=' . $date . '\'"';
    }
  }
  if($style) { $html .= ' style="' . $style . '"'; }
  $html .= '>' . $content . '</td>';
  
  return $html;
}

 
Can't you just include the extra data inside the same cell as the day number?

i.e.
Code:
print "<td>"
   . "$dayno<br>"
   . "extra data"
   . "</td>";

Alternatively, in your code between where it prints <tr> and </tr> for each row, copy the main loop that writes all the <td>'s twice, and in the second loop make it write the extra data. i.e.

Code:
print "<tr>";
# loop 1
for (1..7) {
   print "<td>$_</td>";
}
[blue]print "</tr><tr>"; # you add this here
# loop 2
for (1..7) {
   print "<td>extra data</td>";
}[/blue]
print "</tr>";

Note: all code snippits have nothing to do with your code; they're just isolated examples.

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
You won't be able to just add a new row because the data for each day occupies a whole cell of the HTML table, where each cell can contain multiple lines. So you will need to add your new data for each individual day to the $content with appropriate line breaks before it is passed to $this->table_cell() for insertion into the table.

It might help you to visualise if you replaced the <table border=0 tags with border=1 so you can actually see the resulting table layout.

Annihilannic.
 
Thank you Kirsle and Annihilannic for your replies.

I had already tried Kirsle fist suggestion but really need the extra data in different cells so I continued on the second suggestion which gave me the desired layout but the day number data was not available within each cell.

I then moved on to $content as suggested by Annihilannic which gave me the day data within each cell. Rather than using line breaks, I came up with the idea of using a nested table within each of the day cells.
This seems to do what I want but I'm wondering if there will be any browser/display problems using nested tables.

Code:
$content = "<table width=80 border=1 cellspacing=1 cellpadding=1><tr><td>$daycount</td></tr><tr><td>extra data</td></tr><tr><td>extra data</td></tr></table>"

Can you see any problems doing it like this?
Thank for your time and help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top