import rt 3.8.9
[freeside.git] / rt / share / html / Dashboards / Subscription.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %#
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %#
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %#
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => $title &>
49 <& /Dashboards/Elements/Tabs,
50     current_subtab => $current_subtab,
51     Title => $title,
52     DashboardObj => $DashboardObj &>
53
54 <& /Elements/ListActions, actions => \@results &>
55
56 <form action="<%RT->Config->Get('WebPath')%>/Dashboards/Subscription.html" method="post" enctype="multipart/form-data" name="SubscribeDashboard">
57 <input type="hidden" class="hidden" name="DashboardId" value="<% $fields{'DashboardId'} %>" />
58 <table width="100%" border="0">
59 <tr>
60
61 <td valign="top" class="boxcontainer">
62 <&| /Widgets/TitleBox, title => loc('Dashboard') &>
63
64 <table>
65 <tr><td class="label">
66 <&|/l&>Dashboard</&>:
67 </td><td class="value">
68 <% $DashboardObj->Name %>
69 </td></tr>
70
71 <tr><td class="label">
72 <&|/l&>Queries</&>:
73 </td><td class="value">
74 % my @portlets = grep { defined } $DashboardObj->Portlets;
75 % if (!@portlets) {
76 (<&|/l&>none</&>)
77 % } else {
78 <ol class="dashboard-queries">
79 %    for my $portlet (@portlets) {
80         <li class="dashboard-query">
81             <% loc($portlet->{description}, $fields{'Rows'}) %>
82         </li>
83 %    }
84 </ol>
85 % }
86 </td></tr>
87
88 </table>
89 </&>
90
91 <&| /Widgets/TitleBox, title => loc('Subscription') &>
92
93 <table>
94 <tr><td class="label">
95 <&|/l&>Frequency</&>:
96 </td><td class="value">
97
98 <input type="radio" name="Frequency" value="daily" <% $fields{'Frequency'} eq 'daily' ? 'checked="checked"' : "" %>>
99     <&|/l&>daily</&>
100 </input><br />
101
102 <input type="radio" name="Frequency" value="m-f" <% $fields{'Frequency'} eq 'm-f' ? 'checked="checked"' : "" %>>
103     <&|/l&>Monday through Friday</&>
104 </input><br />
105
106 <input type="radio" name="Frequency" value="weekly"<% $fields{'Frequency'} eq 'weekly' ? 'checked="checked"' : "" %>>
107 <&|/l&>weekly</&></input>, <&|/l&>on</&>
108 <select name="Dow">
109     <option value="Monday" <% $fields{'Dow'} eq 'Monday' ? 'selected="selected"' : '' %>><&|/l&>Monday</&></option>
110     <option value="Tuesday" <% $fields{'Dow'} eq 'Tuesday' ? 'selected="selected"' : '' %>><&|/l&>Tuesday</&></option>
111     <option value="Wednesday" <% $fields{'Dow'} eq 'Wednesday' ? 'selected="selected"' : '' %>><&|/l&>Wednesday</&></option>
112     <option value="Thursday" <% $fields{'Dow'} eq 'Thursday' ? 'selected="selected"' : '' %>><&|/l&>Thursday</&></option>
113     <option value="Friday" <% $fields{'Dow'} eq 'Friday' ? 'selected="selected"' : '' %>><&|/l&>Friday</&></option>
114     <option value="Saturday" <% $fields{'Dow'} eq 'Saturday' ? 'selected="selected"' : '' %>><&|/l&>Saturday</&></option>
115     <option value="Sunday" <% $fields{'Dow'} eq 'Sunday' ? 'selected="selected"' : '' %>><&|/l&>Sunday</&></option>
116 </select>
117 <&|/l&>every</&>
118 <select name="Fow">
119 % for my $f ( qw/1 2 3 4/ ) {
120     <option value="<%$f%>" <% $fields{'Fow'} == $f ? 'selected="selected"' : '' %>><% $f %></option>
121 % }
122 </select>
123 <&|/l&>weeks</&>
124 <br />
125
126 <input type="radio" name="Frequency" value="monthly"<% $fields{'Frequency'} eq 'monthly' ? 'checked="checked"' : "" %>>
127 <&|/l&>monthly</&></input> , <&|/l&>on day</&>
128 <select name="Dom">
129 %   for my $dom (1..31) {
130     <option value="<% $dom %>" <% $fields{'Dom'} == $dom ? 'selected="selected"' : '' %>><% loc($dom) %></option>
131 %   }
132 </select>
133 <br />
134
135 <input type="radio" name="Frequency" value="never" <% $fields{'Frequency'} eq 'never' ? 'checked="checked"' : "" %>>
136     <&|/l&>never</&>
137 </input>
138
139 </td></tr>
140 <tr><td class="label">
141 <&|/l&>Hour</&>:
142 </td><td class="value">
143 <select name="Hour">
144 % for my $hour (0..23) {
145 %     my $formatted = sprintf '%02d:00', $hour;
146 %     my $selected = $formatted eq $fields{'Hour'}
147 %                  ? 'selected="selected"'
148 %                  : '';
149
150     <option value="<% $formatted %>" <%$selected%>><% $formatted %></option>
151 % }
152 </select>
153 (<%$timezone%>)
154 </td></tr>
155 <tr><td class="label">
156 <&|/l&>Rows</&>:
157 </td><td class="value">
158 <select name="Rows">
159 %   for my $rows (1, 2, 5, 10, 15, 20, 25, 50, 75, 100, 0) {
160     <option value="<% $rows %>" <% $fields{'Rows'} eq $rows ? 'selected="selected"' : '' %>><% loc($rows || 'Unlimited') %></option>
161 %   }
162 </select>
163 </td></tr>
164
165 <tr><td class="label">
166 <&|/l&>Recipient</&>:
167 </td><td class="value">
168 <input name="Recipient" id="Recipient" size="30" value="<%$fields{Recipient} ? $fields{Recipient} : ''%>" />
169 <div class="hints"><% loc("Leave blank to send to your current email address ([_1])", $session{'CurrentUser'}->UserObj->EmailAddress) %></div>
170 </td></tr>
171 </table>
172 </&>
173 </td>
174 </tr>
175 </table>
176
177 % if ($SubscriptionObj->Id) {
178     <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &>
179 % } else {
180     <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &>
181 % }
182 </form>
183
184 <%INIT>
185
186 my $current_subtab = 'Dashboards/Subscription.html?DashboardId=' . $DashboardId;
187
188 my ($title, @results);
189 my ($val, $msg);
190 my $Loaded = 0;
191 my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Timezone');
192
193 use RT::Dashboard;
194 my $DashboardObj = RT::Dashboard->new($session{'CurrentUser'});
195
196 my $SubscriptionObj = RT::Attribute->new($session{'CurrentUser'});
197
198 # first let's see if we already have a subscription to this DashboardId
199 for my $sub ($session{'CurrentUser'}->UserObj->Attributes->Named('Subscription')) {
200     next unless $sub->SubValue('DashboardId') == $DashboardId;
201     $SubscriptionObj = $sub;
202     last;
203 }
204
205 $DashboardId = $SubscriptionObj->Id
206              ? $SubscriptionObj->SubValue('DashboardId')
207              : $ARGS{'DashboardId'};
208
209 ($val, $msg) = $DashboardObj->LoadById($DashboardId);
210 $val || Abort(loc("Couldn't load dashboard [_1]: [_2].", $DashboardId, $msg));
211
212 my %fields = (
213     DashboardId => $DashboardId,
214     Frequency   => 'daily',
215     Hour        => '06:00',
216     Dow         => 'Monday',
217     Dom         => 1,
218     Rows        => 20,
219     Recipient   => '',
220     Fow         => 1,
221     Counter     => 0,
222 );
223
224 # update any fields with the values from the subscription object
225 if ($SubscriptionObj->Id) {
226     for my $field (keys %fields) {
227         $fields{$field} = $SubscriptionObj->SubValue($field);
228     }
229 }
230
231 # finally, update any fields with arguments passed in by the user
232 for my $field (keys %fields) {
233     next if $field eq 'DashboardId'; # but this one is immutable
234     $fields{$field} = $ARGS{$field}
235         if defined($ARGS{$field});
236 }
237 # this'll be defined on submit
238 if (defined $ARGS{Save}) {
239     # update
240     if ($SubscriptionObj->Id) {
241         $DashboardId = delete $fields{'DashboardId'}; # immutable
242         ($val, $msg) = $SubscriptionObj->SetSubValues(%fields);
243         $fields{'DashboardId'} = $DashboardId;
244
245         # not so good to spew base64-encoded data at the user :)
246         if ($msg =~ /^Content changed from/) {
247             $msg = "Subscription updated.";
248         }
249
250         push @results, $msg;
251     }
252     # create
253     else {
254         Abort(loc("Unable to subscribe to dashboard [_1]: Permission denied", $DashboardId))
255             unless $DashboardObj->CurrentUserCanSubscribe;
256
257         my ($val, $msg) = $SubscriptionObj->Create(
258             Name        => 'Subscription',
259             Description => 'Subscription to dashboard ' . $DashboardId,
260             ContentType => 'storable',
261             Object      => $session{'CurrentUser'}->UserObj,
262             Content     => \%fields,
263         );
264         if ($val) {
265             push @results, loc("Subscribed to dashboard [_1]", $DashboardObj->Name);
266             push @results, loc("Warning: you have no email address set, so you will not receive this dashboard until you have it set")
267                 unless $session{'CurrentUser'}->EmailAddress || $fields{Recipient};
268         }
269         else {
270             push @results, loc('Subscription could not be created: [_1]', $msg);
271         }
272     }
273 }
274
275 if ($SubscriptionObj->Id) {
276     $title = loc("Modify the subscription to dashboard [_1]", $DashboardObj->Name);
277 }
278 else {
279     $title = loc("Subscribe to dashboard [_1]", $DashboardObj->Name);
280 }
281
282 </%INIT>
283 <%ARGS>
284 $DashboardId => undef
285 $Frequency   => undef
286 $Hour        => undef
287 $Dow         => undef
288 $Dom         => undef
289 $Rows        => undef
290 $Recipient   => undef
291 </%ARGS>
292