Initial commit 4.0.5-3
[usit-rt.git] / share / html / Dashboards / Subscription.html
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
5%# This software is Copyright (c) 1996-2012 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<& /Elements/Tabs &>
50
51<& /Elements/ListActions, actions => \@results &>
52
53<form action="<%RT->Config->Get('WebPath')%>/Dashboards/Subscription.html" method="post" enctype="multipart/form-data" name="SubscribeDashboard">
54<input type="hidden" class="hidden" name="id" value="<% $fields{'DashboardId'} %>" />
55<table width="100%" border="0">
56<tr>
57
58<td valign="top" class="boxcontainer">
59<&| /Widgets/TitleBox, title => loc('Dashboard') &>
60
61<table>
62<tr><td class="label">
63<&|/l&>Dashboard</&>:
64</td><td class="value">
65<% $Dashboard->Name %>
66</td></tr>
67
68<tr><td class="label">
69<&|/l&>Queries</&>:
70</td><td class="value">
71% my @portlets = grep { defined } $Dashboard->Portlets;
72% if (!@portlets) {
73(<&|/l&>none</&>)
74% } else {
75<ol class="dashboard-queries">
76% for my $portlet (@portlets) {
77 <li class="dashboard-query">
78 <% loc($portlet->{description}, $fields{'Rows'}) %>
79 </li>
80% }
81</ol>
82% }
83</td></tr>
84
85</table>
86</&>
87
88<&| /Widgets/TitleBox, title => loc('Subscription') &>
89
90<table>
91<tr><td class="label">
92<&|/l&>Frequency</&>:
93</td><td class="value">
94
95<input type="radio" name="Frequency" value="daily" <% $fields{'Frequency'} eq 'daily' ? 'checked="checked"' : "" |n %>>
96 <&|/l&>daily</&>
97</input><br />
98
99<input type="radio" name="Frequency" value="m-f" <% $fields{'Frequency'} eq 'm-f' ? 'checked="checked"' : "" |n %>>
100 <&|/l&>Monday through Friday</&>
101</input><br />
102
103<input type="radio" name="Frequency" value="weekly"<% $fields{'Frequency'} eq 'weekly' ? 'checked="checked"' : "" |n %>>
104<&|/l&>weekly</&></input>, <&|/l&>on</&>
105<select name="Dow">
106 <option value="Monday" <% $fields{'Dow'} eq 'Monday' ? 'selected="selected"' : '' |n %>><&|/l&>Monday</&></option>
107 <option value="Tuesday" <% $fields{'Dow'} eq 'Tuesday' ? 'selected="selected"' : '' |n %>><&|/l&>Tuesday</&></option>
108 <option value="Wednesday" <% $fields{'Dow'} eq 'Wednesday' ? 'selected="selected"' : '' |n %>><&|/l&>Wednesday</&></option>
109 <option value="Thursday" <% $fields{'Dow'} eq 'Thursday' ? 'selected="selected"' : '' |n %>><&|/l&>Thursday</&></option>
110 <option value="Friday" <% $fields{'Dow'} eq 'Friday' ? 'selected="selected"' : '' |n %>><&|/l&>Friday</&></option>
111 <option value="Saturday" <% $fields{'Dow'} eq 'Saturday' ? 'selected="selected"' : '' |n %>><&|/l&>Saturday</&></option>
112 <option value="Sunday" <% $fields{'Dow'} eq 'Sunday' ? 'selected="selected"' : '' |n %>><&|/l&>Sunday</&></option>
113</select>
114<&|/l&>every</&>
115<select name="Fow">
116% for my $f ( qw/1 2 3 4/ ) {
117 <option value="<%$f%>" <% $fields{'Fow'} == $f ? 'selected="selected"' : '' |n %>><% $f %></option>
118% }
119</select>
120<&|/l&>weeks</&>
121<br />
122
123<input type="radio" name="Frequency" value="monthly"<% $fields{'Frequency'} eq 'monthly' ? 'checked="checked"' : "" |n %>>
124<&|/l&>monthly</&></input> , <&|/l&>on day</&>
125<select name="Dom">
126% for my $dom (1..31) {
127 <option value="<% $dom %>" <% $fields{'Dom'} == $dom ? 'selected="selected"' : '' |n %>><% loc($dom) %></option>
128% }
129</select>
130<br />
131
132<input type="radio" name="Frequency" value="never" <% $fields{'Frequency'} eq 'never' ? 'checked="checked"' : "" |n %>>
133 <&|/l&>never</&>
134</input>
135
136</td></tr>
137<tr><td class="label">
138<&|/l&>Hour</&>:
139</td><td class="value">
140<select name="Hour">
141% my $formatter = RT::Date->new($session{CurrentUser})->LocaleObj;
142% my $dt = DateTime->now;
143% $dt->set_minute(0);
144% $dt->set_second(0);
145
146% for my $hour (0..23) {
147% $dt->set_hour($hour);
148% my $formatted = $dt->format_cldr($formatter->time_format_short);
149
150% my $value = sprintf '%02d:00', $hour;
151% my $selected = $value eq $fields{'Hour'}
152% ? 'selected="selected"'
153% : '';
154
155 <option value="<% $value %>" <%$selected|n %>><% $formatted %></option>
156% }
157</select>
158(<%$timezone%>)
159</td></tr>
160<tr><td class="label">
161<&|/l&>Rows</&>:
162</td><td class="value">
163<select name="Rows">
164% for my $rows (1, 2, 5, 10, 15, 20, 25, 50, 75, 100, 0) {
165 <option value="<% $rows %>" <% $fields{'Rows'} eq $rows ? 'selected="selected"' : '' |n %>><% loc($rows || 'Unlimited') %></option>
166% }
167</select>
168</td></tr>
169
170<tr><td class="label">
171<&|/l&>Recipient</&>:
172</td><td class="value">
173<input name="Recipient" id="Recipient" size="30" value="<%$fields{Recipient} ? $fields{Recipient} : ''%>" />
174<div class="hints"><% loc("Leave blank to send to your current email address ([_1])", $session{'CurrentUser'}->UserObj->EmailAddress) %></div>
175</td></tr>
176</table>
177</&>
178</td>
179</tr>
180</table>
181
182% if ($SubscriptionObj) {
183 <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &>
184% } else {
185 <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &>
186% }
187</form>
188
189<%INIT>
190
191my ($title, @results);
192my $Loaded = 0;
193my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Timezone');
194
195use RT::Dashboard;
196my $Dashboard = RT::Dashboard->new($session{'CurrentUser'});
197my ($ok, $msg) = $Dashboard->LoadById($id);
198$ok || Abort(loc("Couldn't load dashboard [_1]: [_2]", $id, $msg));
199
200my $SubscriptionObj = $Dashboard->Subscription;
201
202$id = $SubscriptionObj ? $SubscriptionObj->SubValue('DashboardId') : $ARGS{'id'};
203
204my %fields = (
205 DashboardId => $id,
206 Frequency => 'daily',
207 Hour => '06:00',
208 Dow => 'Monday',
209 Dom => 1,
210 Rows => 20,
211 Recipient => '',
212 Fow => 1,
213 Counter => 0,
214);
215
216# update any fields with the values from the subscription object
217if ($SubscriptionObj) {
218 for my $field (keys %fields) {
219 $fields{$field} = $SubscriptionObj->SubValue($field);
220 }
221}
222
223# finally, update any fields with arguments passed in by the user
224for my $field (keys %fields) {
225 next if $field eq 'DashboardId'; # but this one is immutable
226 $fields{$field} = $ARGS{$field}
227 if defined($ARGS{$field});
228}
229
230
231# this'll be defined on submit
232if (defined $ARGS{Save}) {
233 my $ok = 1;
234
235 # validation
236 if ($fields{Recipient}) {
237 my @addresses = Email::Address->parse($fields{Recipient});
238 if (@addresses == 0) {
239 push @results, loc('Recipient must be an email address');
240 $ok = 0;
241 }
242 }
243
244 if ($ok) {
245 # update
246 if ($SubscriptionObj) {
247 $id = delete $fields{'DashboardId'}; # immutable
248 ($ok, $msg) = $SubscriptionObj->SetSubValues(%fields);
249 $fields{'DashboardId'} = $id;
250
251 # not so good to spew base64-encoded data at the user :)
252 if ($msg =~ /^Content changed from/) {
253 $msg = "Subscription updated.";
254 }
255
256 push @results, $msg;
257 }
258 # create
259 else {
260 Abort(loc("Unable to subscribe to dashboard [_1]: Permission denied", $id))
261 unless $Dashboard->CurrentUserCanSubscribe;
262
263 $SubscriptionObj = RT::Attribute->new($session{CurrentUser});
264 ($ok, $msg) = $SubscriptionObj->Create(
265 Name => 'Subscription',
266 Description => 'Subscription to dashboard ' . $id,
267 ContentType => 'storable',
268 Object => $session{'CurrentUser'}->UserObj,
269 Content => \%fields,
270 );
271 if ($ok) {
272 push @results, loc("Subscribed to dashboard [_1]", $Dashboard->Name);
273 push @results, loc("Warning: you have no email address set, so you will not receive this dashboard until you have it set")
274 unless $session{'CurrentUser'}->EmailAddress || $fields{Recipient};
275 }
276 else {
277 push @results, loc('Subscription could not be created: [_1]', $msg);
278 }
279 }
280 }
281}
282
283if ($SubscriptionObj) {
284 $title = loc("Modify the subscription to dashboard [_1]", $Dashboard->Name);
285}
286else {
287 $title = loc("Subscribe to dashboard [_1]", $Dashboard->Name);
288}
289
290</%INIT>
291<%ARGS>
292$id => undef
293$Frequency => undef
294$Hour => undef
295$Dow => undef
296$Dom => undef
297$Rows => undef
298$Recipient => undef
299</%ARGS>
300