$OrderBy => undef
$RowsPerPage => undef
$NewQuery => 0
+$WeekDay => undef
+$WeekMonth => undef
+$WeekYear => undef
+$OrigMonth => undef
+$OrigYear => undef
</%args>
<& /Elements/Header, Title => $title &>
<& /Elements/Tabs &>
+% my $title;
+% if ( $WeekMonth ) {
+% if ( $date->month == $end->month ) {
+% $title = $rtdate->GetMonth( $date->month -1 ). ' '.
+% $date->day. '-'. $end->day. ', '. $date->year;
+% } elsif ( $date->year == $end->year ) {
+% $title =
+% $rtdate->GetMonth( $date->month -1 ). ' '. $date->day. ' - '.
+% $rtdate->GetMonth( $end->month -1 ). ' '. $end->day. ', '. $end->year;
+% } else {
+% $title =
+% $rtdate->GetMonth( $date->month -1 ). ' '.$date->day. ', '. $date->year.
+% ' - '.
+% $rtdate->GetMonth( $end->month -1 ). ' '.$end->day. ', '. $end->year;
+% }
+% } else {
+% $title = $rtdate->GetMonth($Month) . " $Year"
+% }
<&| /Widgets/TitleBox,
- title => loc('Calendar for ') . $rtdate->GetMonth($Month) . " $Year" ,
+ title => loc('Calendar for '). $title,
title_class=> 'inverse',
color => "#993333" &>
-<table width="100%">
-<tr>
-<td align="left">
-% my ($PMonth, $PYear) = ($Month - 1, $Year);
+% my($PMonth, $PYear, $NMonth, $NYear);
+% unless ( $WeekDay ) {
+
+ <table width="100%">
+ <tr>
+ <td align="left">
+% ($PMonth, $PYear) = ($Month - 1, $Year);
% if ($PMonth < 0) {
% $PYear--;
% $PMonth = 11;
% }
-<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
-</td>
-<th align="center">
- <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
-</th>
-<td align="right">
-% my ($NMonth, $NYear) = ($Month + 1, $Year);
+ <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
+ </td>
+ <th align="center">
+ <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
+ </th>
+ <td align="right">
+% ($NMonth, $NYear) = ($Month + 1, $Year);
% if ($NMonth > 11) {
% $NYear++;
% $NMonth = 0;
% }
-<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
-</td>
-</tr>
-</table>
+ <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
+ </td>
+ </tr>
+ </table>
+% }
<table class="rtxcalendar">
<thead>
<tr>
+<td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
% for ( @{$week{$weekstart}} ) {
<th width="14%"><%$rtdate->GetWeekday($_)%></th>
% }
<tbody>
<tr>
-% while ($date <= $end) {
+
+% if ( $WeekDay ) {
+ <td class="controls" rowspan=<% $rowspan+1 %> valign="middle">
+ <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
+ </td>
+ </td>
+% } else {
+ <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
+% }
+
+% if ( $WeekDay ) {
+
+ <td class="labels"></td>
+
+% $date = $start;
+% while ($date <= $end) {
+%
+% my $is_today = (DateTime->compare($today, $date) == 0);
+% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
+% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
+
+ <td class="<% $is_today ? 'today'
+ : $is_yesterday ? 'yesterday'
+ : $is_aweekago ? 'aweekago'
+ : ''
+ %>"
+ >
+ <div class="<% $is_today ? 'todays'
+ : ''
+ %>calendardate"
+ ><% $rtdate->GetMonth($date->month-1). ' '. $date->day %></div>
+
+ </td>
+
+% $date = $set->next($date);
+% if ( $date->day_of_week == $startday_of_week ) {
+ </tr>
+% if ( $date <= $end ) { #a second week? not going to work for week view yet
+ <tr>
+ <td class="controls" rowspan=<% $rowspan + 1 %> valign="middle">
+ <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
+ </td>
+% }
+% }
+
+% } #while ($date <= $end)
+
+% foreach my $row ( @week_rows ) {
+
+ <& td_time, $row &>
+
+% $date = $start;
+% while ($date <= $end) {
%
-% my $offmonth = $date->month != ($Month + 1);
-% my $is_today = (DateTime->compare($today, $date) == 0);
-% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
-% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
+% my $is_today = (DateTime->compare($today, $date) == 0);
+% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
+% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
+
+ <td class="<% $is_today ? 'today'
+ : $is_yesterday ? 'yesterday'
+ : $is_aweekago ? 'aweekago'
+ : ''
+ %>"
+ >
+
+% #XXX display these in a time aware fashion
+%#% my $sp = 3;
+%#% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
+%#% $sp--;
+%# <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
+%#% }
+%# <% ($sp>0) ? '<BR>'x$sp : '' |n %>
+
+ </td>
+
+% $date = $set->next($date);
+% if ( $date->day_of_week == $startday_of_week ) {
+ </tr>
+% if ( $date <= $end ) { #a second week? not going to work for week view yet
+ <tr>
+ <td class="controls" rowspan=<% $rowspan + 1 %> valign="middle">
+ <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
+ </td>
+% }
+% }
+
+% } #while ($date <= $end)
+% } #foreach my $row ( @week_rows )
+
+% } else {
- <td class="<% $offmonth ? 'offmonth'
+% while ($date <= $end) {
+%
+% my $offmonth = !$WeekDay && $date->month != ($Month + 1);
+% my $is_today = (DateTime->compare($today, $date) == 0);
+% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
+% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
+
+ <td class="<% $offmonth ? 'offmonth'
: $is_today ? 'today'
: $is_yesterday ? 'yesterday'
: $is_aweekago ? 'aweekago'
: ''
- %>"
- >
- <div class="<% $is_today ? 'todays'
+ %>"
+ >
+ <div class="<% $is_today ? 'todays'
: $offmonth ? 'offmonth'
- :'' %>calendardate"
- ><%$date->day%></div>
+ : ''
+ %>calendardate"
+ ><% $date->day %></div>
+
+% my $sp = 3;
+% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
+% $sp--;
+ <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
+% }
+ <% ($sp>0) ? '<BR>'x$sp : '' |n %>
-% my $sp = 3;
-% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
-% $sp--;
- <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
-% }
- <% ($sp>0) ? '<BR>'x$sp : '' |n %>
+ </td>
- </td>
+% $date = $set->next($date);
+% if ( $date->day_of_week == $startday_of_week ) {
+ </tr>
+% if ( $date <= $end ) {
+ <tr>
+ <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
+% }
+% }
-% $date = $set->next($date);
-% if ( $date->day_of_week == $startday_of_week ) {
- </tr><tr>
-% }
+% } #while ($date <= $end)
% }
-</tr>
</tbody>
</table>
-<table width="100%">
-<tr>
-<td align="left">
-<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
-</td>
+% unless ( $WeekDay ) {
-<td valign="top" align="center">
-<form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">
+ <table width="100%">
+ <tr>
+ <td align="left">
+ <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
+ </td>
-<select name="Month">
-% for (0..11) {
-<option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
-% }
-</select>
-% my $year = (localtime)[5] + 1900;
-<select name="Year">
-% for ( ($year-5) .. ($year+5)) {
-<option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
-% }
-</select>
+ <td valign="top" align="center">
+ <form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">
+
+ <select name="Month">
+% for (0..11) {
+ <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
+% }
+ </select>
+
+% my $year = (localtime)[5] + 1900;
+ <select name="Year">
+% for ( ($year-5) .. ($year+5)) {
+ <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
+% }
+ </select>
%# <& /Elements/Submit&>
-<input type="submit" value="<% loc('Submit') %>" class="button" />
+ <input type="submit" value="<% loc('Submit') %>" class="button" />
-</form>
-</td>
+ </form>
+ </td>
-<td align="right">
-<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
-</td>
-</tr>
-</table>
+ <td align="right">
+ <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
+ </td>
+ </tr>
+ </table>
+
+% }
+% #XXX an option to turn off "Calendar Preferences and Help" for embedded
+% # (and weekly?) use
<table width="100%">
<tr>
'starts_due' => ['Starts','Due'],
);
+my $stime = 480; #8am
+my $etime = 1080; #6pm
+my $timestep = 30; #1/2h
+#my $timestep = 120; #2h
+my $rowspan = ($etime-$stime) / $timestep;
+
+my $wt = $stime;
+my @week_rows = ();
+while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
+
</%ONCE>
<%INIT>
-use RTx::Calendar qw(FirstDay LastDay);
+use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
my $title = loc("Calendar");
my $rtdate = RT::Date->new($session{'CurrentUser'});
+my $time_zone = $session{'CurrentUser'}->UserObj->Timezone
+ || RT->Config->Get('Timezone');
+
my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
my %week = (
'Saturday' => [6,0..5],
my $startday_of_week = ${$week{$weekstart}}[0] || 7;
my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
-my $today = DateTime->today;
+my $today = DateTime->today( time_zone=>$time_zone );
my $yesterday = $today->clone->subtract( days=>1 );
my $aweekago = $today->clone->subtract( days=>7 );
-my $date = FirstDay($Year, $Month + 1, $startday_of_week );
-my $end = LastDay ($Year, $Month + 1, $endday_of_week );
+
+my( $start, $end );
+if ( $WeekDay ) {
+ $start = DateTime->new( year => $WeekYear,
+ month => $WeekMonth+1,
+ day => $WeekDay,
+ time_zone => $time_zone,
+ );
+ $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week );
+} else {
+ $start = FirstDay($Year, $Month + 1, $startday_of_week );
+ $end = LastDay ($Year, $Month + 1, $endday_of_week );
+}
+my $date = $start;
# use this to loop over days until $end
my $set = DateTime::Set->from_recurrence(
my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
</%INIT>
+<%def td_week_expand>
+<%args>
+ $date => undef
+ $Month => undef
+ $Year => undef
+ $QueryString => undef
+</%args>
+ <td class="controls">
+ <a href="<%$RT::WebPath%>/Search/Calendar.html?WeekDay=<% $date->day %>&WeekMonth=<% $date->month -1 %>&WeekYear=<% $date->year %>&OrigMonth=<% $Month %>&OrigYear=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-expand.gif"></a>
+ </td>
+</%def>
+
+<%def week_collapse>
+<%args>
+ $date => undef
+ $Month => undef
+ $Year => undef
+ $QueryString => undef
+</%args>
+ <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<% $Month %>&Year=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-collapse.gif" STYLE="height:384px;width:11px"></a>
+</%def>
+
+<%def td_time>
+% my( $min ) = shift;
+ <td class="labels"><% pretty_time($min) |n %></td>
+<%init>
+sub pretty_time {
+ my $t = shift;
+
+ return 'Midnight' if $t == 0 || $t == 1440;
+ return 'Noon' if $t == 720;
+
+ my $h = int( $t / 60 );
+ my $m = $t % 60;
+
+ my $ap = 'AM';
+ if ( $h == 0 || $h == 24 ) { $h = 12; }
+ elsif ( $h == 12 ) { $ap = 'PM'; }
+ elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; }
+
+ sprintf('%02d:%02d '.$ap, $h, $m);
+
+}
+</%init>
+</%def>