
<%args>
$Query => "id > 0"
$Month => undef
$Year => undef
</%args>

<%init>
use HTML::CalendarMonth;
use HTML::AsSubs;
use RT::Tickets;

my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
$Tickets->FromSQL( $Query );

my (%tickets);
while ( my $ticket = $Tickets->Next ){
  $tickets{$ticket->Id}{subject} = $ticket->Subject;
  my $date = RT::Date->new( $session{'CurrentUser'} );
  $date->Set( Value => $ticket->Due, Format => 'ISO' );
  my $day = (split /-/, $date->Date)[2];
  $day =~ s/^0(\d)/$1/;
  $tickets{$ticket->Id}{due} = $day;
}

</%init>

<%perl>

my $c = HTML::CalendarMonth->new( month => $Month, year => $Year, width => '100%' );
$c->item($c->year, $c->month)->attr(bgcolor => 'wheat');
$c->item($c->year, $c->month)->wrap_content(font({size => '+2'}));
my $days = $c->first_week_row();
$c->row($days)->attr('width', '14%');

foreach my $rt_ticket ( keys %tickets ){
   my $href = $RT::WebPath . "/Ticket/Display.html?id=$rt_ticket";
   my $a = HTML::Element->new('a', 'href' => $href);
   $a->push_content($tickets{$rt_ticket}{subject});
   $c->item($tickets{$rt_ticket}{due})->push_content(br(),$a, br());
}

print $c->as_HTML;

</%perl>
