no need for FS calendar buttons in RT 4.2
[freeside.git] / rt / share / html / Elements / MyCalendar
1 <&|/Widgets/TitleBox,
2     title => loc("Calendar"),
3     title_href => "Search/Calendar.html" &>
4
5 <table class="rtxcalendar">
6 <thead>
7 <tr>
8 % my $date = $begin->clone;
9 % while ( $date <= $end ) {
10 <th width="14%"><%$rtdate->GetWeekday($date->day_of_week % 7)%></th>
11 % $date = $set->next($date);
12 % }
13 </tr>
14 </thead>
15 <tbody>
16 <tr>
17 % $date = $begin->clone;
18 % while ($date <= $end) {
19 <td>
20 <p class="date"><%$date->day%></p>
21 % for my $t (@{ $Tickets{$date->strftime("%F")} }) {
22 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
23 % }
24 </td>
25 % $date = $set->next($date);
26 % }
27 </tr>
28 </tbody>
29 </table>
30
31  </&>
32
33 <%INIT>
34
35 use RTx::Calendar;
36
37 my $title = loc("Calendar");
38
39 my $rtdate = RT::Date->new($session{'CurrentUser'});
40
41 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
42
43 my $today = DateTime->today;
44
45 # this line is used to debug MyCalendar
46 # $today = DateTime->new(year => 2007, month => 4, day => 11);
47
48 my $begin = $today->clone->subtract( days => 3);
49 my $end   = $today->clone->add( days => 3);
50
51 # use this to loop over days until $end
52 my $set = DateTime::Set->from_recurrence(
53     next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
54 );
55
56 my $Query = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
57  AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
58  AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
59 my $Format = "__Starts__ __Due__";
60
61 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
62   $Format = $Search->SubValue('Format');
63   $Query = $Search->SubValue('Query');
64 }
65
66 # we search all date types in Format string
67 my @Dates = grep { $Format =~ m/__${_}(Relative)?__/ } @DateTypes;
68
69 # used to display or not a date in Element/CalendarEvent
70 my %DateTypes = map { $_ => 1 } @Dates;
71
72 $Query .= RTx::Calendar::DatesClauses(\@Dates, $begin->strftime("%F"), $end->strftime("%F"));
73
74 # print STDERR $Query, "\n";
75
76 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $Query, \@Dates);
77
78 </%INIT>