commiting rt 3.8.9 to HEAD
[freeside.git] / rt / share / html / Ticket / Elements / Tabs
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 % $m->callback( Ticket => $Ticket, actions=> $actions, tabs => $tabs, %ARGS );
49 <& /Elements/Tabs, 
50     tabs => $tabs, 
51     actions => $actions, 
52     current_tab => $current_tab, 
53     current_toptab => $current_toptab,
54     Title => $Title &> 
55 <%INIT>
56 my $tabs = {};
57 my $current_toptab = "Search/Build.html", my $searchtabs = {};
58 my $actions;
59
60 if ($Ticket) {
61
62     my $id = $Ticket->id();
63
64     if ( defined $session{'tickets'} ) {
65
66         # we have to update session data if we get new ItemMap
67         my $updatesession = 1 unless ( $session{'tickets'}->{'item_map'} );
68
69         my $item_map = $session{'tickets'}->ItemMap;
70
71         if ($updatesession) {
72             $session{'i'}++;
73             $session{'tickets'}->PrepForSerialization();
74         }
75
76         # Don't display prev links if we're on the first ticket
77         if ( $item_map->{ $Ticket->Id }->{prev} ) {
78             if ( $item_map->{first} ) {
79                 $searchtabs->{'_a'} = {
80                     class => "nav",
81                     path  => "Ticket/Display.html?id=" . $item_map->{first},
82                     title => '<< ' . loc('First')
83                 };
84             }
85             $searchtabs->{"_b"} = {
86                 class => "nav",
87                 path  => "Ticket/Display.html?id="
88                     . $item_map->{ $Ticket->Id }->{prev},
89                 title => '< ' . loc('Prev')
90             };
91         }
92
93         # Don't display next links if we're on the last ticket
94         if ( $item_map->{ $Ticket->Id }->{next} ) {
95             $searchtabs->{'d'} = {
96                 class => "nav",
97                 path  => "Ticket/Display.html?id="
98                     . $item_map->{ $Ticket->Id }->{next},
99                 title => loc('Next') . ' >'
100             };
101             if ( $item_map->{last} ) {
102                 $searchtabs->{'e'} = {
103                     class => "nav",
104                     path  => "Ticket/Display.html?id=" . $item_map->{last},
105                     title => loc('Last') . ' >>'
106                 };
107             }
108         }
109     }
110
111     $tabs->{"this"} = {
112         class          => "currentnav",
113         path           => "Ticket/Display.html?id=" . $Ticket->id,
114         title          => "#" . $id,
115         current_subtab => $current_subtab
116     };
117
118     my $ticket_page_tabs = {
119         _A => {
120             title => loc('Display'),
121             path  => "Ticket/Display.html?id=" . $id,
122         },
123
124         _Ab => {
125             title => loc('History'),
126             path  => "Ticket/History.html?id=" . $id,
127         },
128         _B => {
129             title => loc('Basics'),
130             path  => "Ticket/Modify.html?id=" . $id,
131         },
132
133         _C => {
134             title => loc('Dates'),
135             path  => "Ticket/ModifyDates.html?id=" . $id,
136         },
137         _D => {
138             title => loc('People'),
139             path  => "Ticket/ModifyPeople.html?id=" . $id,
140         },
141         _E => {
142             title => loc('Links'),
143             path  => "Ticket/ModifyLinks.html?id=" . $id,
144         },
145         _Ea => {
146             title => loc('Checklist'),
147             path  => "Ticket/Checklist.html?id=" . $id,
148         },
149         _Eb=> {
150             title => loc('Customers'),
151             path  => "Ticket/ModifyCustomers.html?id=" . $id,
152         },
153         _X => {
154             title => loc('Jumbo'),
155             path  => "Ticket/ModifyAll.html?id=" . $id,
156         },
157
158     };
159
160     if ( RT->Config->Get('EnableReminders') ) {
161         $ticket_page_tabs->{_F} = {
162             title     => loc('Reminders'),
163             path      => "Ticket/Reminders.html?id=" . $id,
164             separator => 1,
165         };
166     }
167
168     foreach my $tab ( sort keys %{$ticket_page_tabs} ) {
169         if ( $ticket_page_tabs->{$tab}->{'path'} eq $current_tab ) {
170             $ticket_page_tabs->{$tab}->{"subtabs"} = $subtabs;
171             $tabs->{'this'}->{"current_subtab"}
172                 = $ticket_page_tabs->{$tab}->{"path"};
173         }
174     }
175     $tabs->{'this'}->{"subtabs"} = $ticket_page_tabs;
176     $current_tab = "Ticket/Display.html?id=" . $id;
177
178     my %can = ( ModifyTicket => $Ticket->CurrentUserHasRight('ModifyTicket'), );
179
180     if ( $can{'ModifyTicket'} or $Ticket->CurrentUserHasRight('ReplyToTicket') )
181     {
182         $actions->{'F'} = {
183             title => loc('Reply'),
184             path  => "Ticket/Update.html?Action=Respond&id=" . $id,
185         };
186     }
187
188     if ( $Ticket->CurrentUserHasRight('ForwardMessage') )
189     {
190         $actions->{'FA'} = {
191             title => loc('Forward'),
192             path  => "Ticket/Forward.html?id=" . $id,
193         };
194     }
195
196     if ( $can{'ModifyTicket'} ) {
197         if ( $Ticket->Status ne 'resolved' ) {
198             $actions->{'G'} = {
199                 path =>
200                     "Ticket/Update.html?Action="
201                     . RT->Config->Get('ResolveDefaultUpdateType', $session{'CurrentUser'})
202                     . "&DefaultStatus=resolved&id="
203                     . $id,
204                 title => loc('Resolve')
205             };
206         }
207         if ( $Ticket->Status ne 'open' ) {
208             $actions->{'A'} = {
209                 path  => "Ticket/Display.html?Status=open&id=" . $id,
210                 title => loc('Open it')
211             };
212         }
213     }
214
215     if ( $Ticket->CurrentUserHasRight('OwnTicket') ) {
216         if ( $Ticket->OwnerObj->Id == $RT::Nobody->id ) {
217             $actions->{'B'} = {
218                 path  => "Ticket/Display.html?Action=Take&id=" . $id,
219                 title => loc('Take'),
220                 }
221                 if $can{'ModifyTicket'}
222                     or $Ticket->CurrentUserHasRight('TakeTicket');
223         } elsif ( $Ticket->OwnerObj->id != $session{CurrentUser}->id ) {
224             $actions->{'C'} = {
225                 path  => "Ticket/Display.html?Action=Steal&id=" . $id,
226                 title => loc('Steal'),
227                 }
228                 if $can{'ModifyTicket'}
229                     or $Ticket->CurrentUserHasRight('StealTicket');
230         }
231     }
232
233     if (   $can{'ModifyTicket'}
234         or $Ticket->CurrentUserHasRight('CommentOnTicket') )
235     {
236         $actions->{'E'} = {
237             title => loc('Comment'),
238             path  => "Ticket/Update.html?Action=Comment&id=" . $id,
239         };
240     }
241
242     $actions->{'_ZZ'}
243         = { html => $m->scomp( '/Ticket/Elements/Bookmark', id => $Ticket->id ),
244         };
245
246 }
247
248 if ( ( defined $actions->{A} || defined $actions->{B} || defined $actions->{C} )
249     && (   defined $actions->{E}
250         || defined $actions->{F}
251         || defined $actions->{G} ) )
252 {
253
254     if    ( defined $actions->{C} ) { $actions->{C}->{separator} = 1 }
255     elsif ( defined $actions->{B} ) { $actions->{B}->{separator} = 1 }
256     elsif ( defined $actions->{A} ) { $actions->{A}->{separator} = 1 }
257 }
258
259 my $args = '';
260 my $has_query = '';
261 my %query_args;
262 my $search_id = $ARGS{'SavedSearchId'}
263             || $session{'CurrentSearchHash'}->{'SearchId'} || '';
264 my $chart_search_id = $ARGS{'SavedChartSearchId'} || '';
265
266 $has_query = 1 if ( $ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'} );
267   
268 %query_args = (
269         SavedSearchId => ($search_id eq 'new') ? undef : $search_id,
270         SavedChartSearchId => $chart_search_id,
271         Query  => $ARGS{'Query'}  || $session{'CurrentSearchHash'}->{'Query'},
272         Format => $ARGS{'Format'} || $session{'CurrentSearchHash'}->{'Format'},
273         OrderBy => $ARGS{'OrderBy'}
274             || $session{'CurrentSearchHash'}->{'OrderBy'},
275         Order => $ARGS{'Order'} || $session{'CurrentSearchHash'}->{'Order'},
276         Page  => $ARGS{'Page'}  || $session{'CurrentSearchHash'}->{'Page'},
277         RowsPerPage  => $ARGS{'RowsPerPage'}  || $session{'CurrentSearchHash'}->{'RowsPerPage'},
278     );
279
280     $args = "?" . $m->comp( '/Elements/QueryString', %query_args );
281
282 $tabs->{"f"} = {
283     path  => "Search/Build.html?NewQuery=1",
284     title => loc('New Search')
285 };
286 $tabs->{"g"} = {
287     path  => "Search/Build.html" . (($has_query) ? $args : ''),
288     title => loc('Edit Search')
289 };
290 $tabs->{"h"} = {
291     path      => "Search/Edit.html$args",
292     title     => loc('Advanced'),
293     separator => 1
294 };
295 if ($has_query) {
296
297     if ( $current_tab =~ m{Search/Results.html} ) {
298         $current_tab = "Search/Results.html$args";
299
300         if ( $session{'CurrentUser'}
301             ->HasRight( Right => 'SuperUser', Object => $RT::System ) )
302         {
303             my $shred_args = $m->comp(
304                 '/Elements/QueryString',
305                 Search          => 1,
306                 Plugin          => 'Tickets',
307                 'Tickets:query' => $query_args{'Query'},
308                 'Tickets:limit' => $query_args{'Rows'}
309             );
310
311             $tabs->{"shredder"} = {
312                 path  => 'Admin/Tools/Shredder/?' . $shred_args,
313                 title => loc('Shredder')
314             };
315
316         }
317     }
318     if ( $current_tab =~ m{Search/(Bulk|Build|Edit)\.html} ) {
319         $current_tab = "Search/$1.html$args";
320     }
321
322     $tabs->{"i"} = {
323         path  => "Search/Results.html$args",
324         title => loc('Show Results'),
325     };
326
327     $tabs->{"j"} = {
328         path  => "Search/Bulk.html$args",
329         title => loc('Bulk Update'),
330     };
331
332     $tabs->{"k"} = {
333         path  => "Search/Chart.html$args",
334         title => loc('Graph'),
335     };
336
337     $tabs->{"l"} = {
338         path  => "Prefs/SavedSearches.html",
339         title => 'Saved Searches',
340     };
341
342 }
343
344 foreach my $searchtab ( keys %{$searchtabs} ) {
345     ( $searchtab =~ /^_/ )
346         ? $tabs->{ "s" . $searchtab } = $searchtabs->{$searchtab}
347         : $tabs->{ "z_" . $searchtab } = $searchtabs->{$searchtab};
348 }
349
350 </%INIT>
351
352   
353 <%ARGS>
354 $Ticket => undef
355 $subtabs => undef
356 $current_tab => ''
357 $current_subtab => ''
358 $Title => undef
359 $RowsPerPage => undef
360 </%ARGS>