Merge branch 'patch-1' of https://github.com/gjones2/Freeside
[freeside.git] / rt / share / html / Elements / Tabs
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/PageLayout, show_menu => $show_menu &>
49 <a name="skipnav" id="skipnav" accesskey="8"></a>
50 <%INIT>
51
52 #my $request_path = $HTML::Mason::Commands::r->path_info;
53 my $request_path = $m->request_comp->path;
54 $request_path =~ s!/{2,}!/!g;
55
56 my $query_string = sub {
57     my %args = @_;
58     my $u    = URI->new();
59     $u->query_form(%args);
60     return $u->query;
61 };
62
63 my $build_admin_menu = sub {
64     my $top = shift;
65     my $admin = $top->child( config => title => loc('Configuration'), path => '/Admin/', sort_order => 99 );
66     if ( $session{'CurrentUser'}->HasRight( Object => RT->System, Right => 'AdminUsers' ) ) {
67         my $users = $admin->child( users =>
68             title       => loc('Users'),
69             description => loc('Manage users and passwords'),
70             path        => '/Admin/Users/',
71         );
72         $users->child( select => title => loc('Select'), path => "/Admin/Users/" );
73         $users->child( create => title => loc('Create'), path => "/Admin/Users/Modify.html?Create=1" );
74     }
75     my $groups = $admin->child( groups =>
76         title       => loc('Groups'),
77         description => loc('Manage groups and group membership'),
78         path        => '/Admin/Groups/',
79     );
80     $groups->child( select => title => loc('Select'), path => "/Admin/Groups/" );
81     $groups->child( create => title => loc('Create'), path => "/Admin/Groups/Modify.html?Create=1" );
82
83     my $queues = $admin->child( queues =>
84         title       => loc('Queues'),
85         description => loc('Manage queues and queue-specific properties'),
86         path        => '/Admin/Queues/',
87     );
88     $queues->child( select => title => loc('Select'), path => "/Admin/Queues/" );
89     $queues->child( create => title => loc('Create'), path => "/Admin/Queues/Modify.html?Create=1" );
90
91     if ( $session{'CurrentUser'}->HasRight( Object => RT->System, Right => 'AdminCustomField' ) ) {
92         my $cfs = $admin->child( 'custom-fields' =>
93             title       => loc('Custom Fields'),
94             description => loc('Manage custom fields and custom field values'),
95             path        => '/Admin/CustomFields/',
96         );
97         $cfs->child( select => title => loc('Select'), path => "/Admin/CustomFields/" );
98         $cfs->child( create => title => loc('Create'), path => "/Admin/CustomFields/Modify.html?Create=1" );
99     }
100
101     my $admin_global = $admin->child( global =>
102         title       => loc('Global'),
103         description => loc('Manage properties and configuration which apply to all queues'),
104         path        => '/Admin/Global/',
105     );
106
107     my $scrips = $admin_global->child( scrips =>
108         title       => loc('Scrips'),
109         description => loc('Modify scrips which apply to all queues'),
110         path        => '/Admin/Global/Scrips.html',
111     );
112     $scrips->child( select => title => loc('Select'), path => "/Admin/Global/Scrips.html" );
113     $scrips->child( create => title => loc('Create'), path => "/Admin/Global/Scrip.html?Create=1" );
114
115     my $templates = $admin_global->child( templates =>
116         title       => loc('Templates'),
117         description => loc('Edit system templates'),
118         path        => '/Admin/Global/Templates.html',
119     );
120     $templates->child( select => title => loc('Select'), path => "/Admin/Global/Templates.html" );
121     $templates->child( create => title => loc('Create'), path => "/Admin/Global/Template.html?Create=1" );
122
123     my $cfadmin = $admin_global->child( 'custom-fields' =>
124         title       => loc('Custom Fields'),
125         description => loc('Modify global custom fields'),
126         path        => '/Admin/Global/CustomFields/index.html',
127     );
128     $cfadmin->child( users =>
129         title       => loc('Users'),
130         description => loc('Select custom fields for all users'),
131         path        => '/Admin/Global/CustomFields/Users.html',
132     );
133     $cfadmin->child( groups =>
134         title       => loc('Groups'),
135         description => loc('Select custom fields for all user groups'),
136         path        => '/Admin/Global/CustomFields/Groups.html',
137     );
138     $cfadmin->child( queues =>
139         title       => loc('Queues'),
140         description => loc('Select custom fields for all queues'),
141         path        => '/Admin/Global/CustomFields/Queues.html',
142     );
143     $cfadmin->child( tickets =>
144         title       => loc('Tickets'),
145         description => loc('Select custom fields for tickets in all queues'),
146         path        => '/Admin/Global/CustomFields/Queue-Tickets.html',
147     );
148     $cfadmin->child( transactions =>
149         title       => loc('Ticket Transactions'),
150         description => loc('Select custom fields for transactions on tickets in all queues'),
151         path        => '/Admin/Global/CustomFields/Queue-Transactions.html',
152     );
153     $cfadmin->child( 'custom-fields' =>
154         title       => loc('Articles'),
155         description => loc('Select Custom Fields for Articles in all Classes'),
156         path        => '/Admin/Global/CustomFields/Class-Article.html',
157     );
158
159     my $article_admin = $admin->child( articles => title => loc('Articles'), path => "/Admin/Articles/index.html" );
160     my $class_admin = $article_admin->child(classes => title => loc('Classes'), path => '/Admin/Articles/Classes/' );
161     $class_admin->child( select =>
162         title       => loc('Select'),
163         description => loc('Modify and Create Classes'),
164         path        => '/Admin/Articles/Classes/',
165     );
166     $class_admin->child( create =>
167         title       => loc('Create'),
168         description => loc('Modify and Create Custom Fields for Articles'),
169         path        => '/Admin/Articles/Classes/Modify.html?Create=1',
170     );
171
172
173     my $cfs = $article_admin->child( 'custom-fields' =>
174         title => loc('Custom Fields'),
175         path  => '/Admin/CustomFields/index.html?'.$m->comp('/Elements/QueryString', type => 'RT::Class-RT::Article'),
176     );
177     $cfs->child( select =>
178         title => loc('Select'),
179         path => '/Admin/CustomFields/index.html?'.$m->comp('/Elements/QueryString', type => 'RT::Class-RT::Article'),
180     );
181     $cfs->child( create =>
182         title => loc('Create'),
183         path => '/Admin/CustomFields/Modify.html?'.$m->comp("/Elements/QueryString", Create=>1, LookupType=> "RT::Class-RT::Article" ),
184     );
185
186     $admin_global->child( 'group-rights' =>
187         title       => loc('Group Rights'),
188         description => loc('Modify global group rights'),
189         path        => '/Admin/Global/GroupRights.html',
190     );
191     $admin_global->child( 'user-rights' =>
192         title       => loc('User Rights'),
193         description => loc('Modify global user rights'),
194         path        => '/Admin/Global/UserRights.html',
195     );
196     $admin_global->child( 'my-rt' =>
197         title       => loc('RT at a glance'),
198         description => loc('Modify the default "RT at a glance" view'),
199         path        => '/Admin/Global/MyRT.html',
200     );
201     $admin_global->child( 'topics' =>
202         title       => loc('Topics'),
203         description => loc('Modify global article topics'),
204         path        => '/Admin/Global/Topics.html',
205     );
206
207     my $admin_tools = $admin->child( tools =>
208         title       => loc('Tools'),
209         description => loc('Use other RT administrative tools'),
210         path        => '/Admin/Tools/',
211     );
212     $admin_tools->child( configuration =>
213         title       => loc('System Configuration'),
214         description => loc('Detailed information about your RT setup'),
215         path        => '/Admin/Tools/Configuration.html',
216     );
217     $admin_tools->child( theme =>
218         title       => loc('Theme'),
219         description => loc('Customize the look of your RT'),
220         path        => '/Admin/Tools/Theme.html',
221     );
222     if (RT->Config->Get('StatementLog')
223         && $session{'CurrentUser'}->HasRight( Right => 'SuperUser', Object => RT->System )) {
224        $admin_tools->child( 'sql-queries' =>
225            title       => loc('SQL Queries'),
226            description => loc('Browse the SQL queries made in this process'),
227            path        => '/Admin/Tools/Queries.html',
228        );
229     }
230     $admin_tools->child( shredder =>
231         title       => loc('Shredder'),
232         description => loc('Permanently wipeout data from RT'),
233         path        => '/Admin/Tools/Shredder',
234     );
235
236     if ( $request_path =~ m{^/Admin/(Queues|Users|Groups|CustomFields)} ) {
237         my $type = $1;
238         my $tabs = PageMenu();
239
240         my %labels = (
241             Queues       => loc("Queues"),
242             Users        => loc("Users"),
243             Groups       => loc("Groups"),
244             CustomFields => loc("Custom Fields"),
245         );
246
247         my $section;
248         if ( $request_path =~ m|^/Admin/$type/?(?:index.html)?$|
249              || (    $request_path =~ m|^/Admin/$type/(?:Modify.html)$|
250                   && $DECODED_ARGS->{'Create'} )
251            )
252         {
253             $section = $tabs;
254
255         } else {
256             $section = $tabs->child( select => title => $labels{$type},
257                                      path => "/Admin/$type/" );
258         }
259
260         $section->child( select => title => loc('Select'), path => "/Admin/$type/" );
261         $section->child( create => title => loc('Create'), path => "/Admin/$type/Modify.html?Create=1" );
262     }
263
264     if ( $request_path =~ m{^/Admin/Queues} ) {
265         if ( $DECODED_ARGS->{'id'} && $DECODED_ARGS->{'id'} =~ /^\d+$/
266                 ||
267               $DECODED_ARGS->{'Queue'} && $DECODED_ARGS->{'Queue'} =~ /^\d+$/
268                 ) {
269             my $id = $DECODED_ARGS->{'Queue'} || $DECODED_ARGS->{'id'};
270             my $queue_obj = RT::Queue->new( $session{'CurrentUser'} );
271             $queue_obj->Load($id);
272
273             my $queue = PageMenu();
274             $queue->child( basics => title => loc('Basics'),   path => "/Admin/Queues/Modify.html?id=" . $id );
275             $queue->child( people => title => loc('Watchers'), path => "/Admin/Queues/People.html?id=" . $id );
276
277             my $templates = $queue->child(templates => title => loc('Templates'), path => "/Admin/Queues/Templates.html?id=" . $id);
278             $templates->child( select => title => loc('Select'), path => "/Admin/Queues/Templates.html?id=".$id);
279             $templates->child( create => title => loc('Create'), path => "/Admin/Queues/Template.html?Create=1;Queue=".$id);
280
281             my $scrips = $queue->child( scrips => title => loc('Scrips'), path => "/Admin/Queues/Scrips.html?id=" . $id);
282             $scrips->child( select => title => loc('Select'), path => "/Admin/Queues/Scrips.html?id=" . $id );
283             $scrips->child( create => title => loc('Create'), path => "/Admin/Queues/Scrip.html?Create=1;Queue=" . $id);
284
285             my $ticket_cfs = $queue->child( 'ticket-custom-fields' => title => loc('Ticket Custom Fields'),
286                 path => '/Admin/Queues/CustomFields.html?SubType=RT::Ticket&id=' . $id );
287
288             my $txn_cfs = $queue->child( 'transaction-custom-fields' => title => loc('Transaction Custom Fields'),
289                 path => '/Admin/Queues/CustomFields.html?SubType=RT::Ticket-RT::Transaction&id='.$id );
290
291             $queue->child( 'group-rights' => title => loc('Group Rights'), path => "/Admin/Queues/GroupRights.html?id=".$id );
292             $queue->child( 'user-rights' => title => loc('User Rights'), path => "/Admin/Queues/UserRights.html?id=" . $id );
293
294
295             $m->callback( CallbackName => 'PrivilegedQueue', queue_id => $id, page_menu => $queue);
296         }
297     }
298     if ( $request_path =~ m{^/Admin/Users} ) {
299         if ( $DECODED_ARGS->{'id'} && $DECODED_ARGS->{'id'} =~ /^\d+$/ ) {
300             my $id = $DECODED_ARGS->{'id'};
301             my $obj = RT::User->new( $session{'CurrentUser'} );
302             $obj->Load($id);
303
304             my $tabs = PageMenu();
305             $tabs->child( basics      => title => loc('Basics'),         path => "/Admin/Users/Modify.html?id=" . $id );
306             $tabs->child( memberships => title => loc('Memberships'),    path => "/Admin/Users/Memberships.html?id=" . $id );
307             $tabs->child( history     => title => loc('History'),        path => "/Admin/Users/History.html?id=" . $id );
308             $tabs->child( 'my-rt'     => title => loc('RT at a glance'), path => "/Admin/Users/MyRT.html?id=" . $id );
309             if ( RT->Config->Get('GnuPG')->{'Enable'} ) {
310                 $tabs->child( pgp     => title => loc('GnuPG'),          path => "/Admin/Users/GnuPG.html?id=" . $id );
311             }
312         }
313
314     }
315
316     if ( $request_path =~ m{^/Admin/Groups} ) {
317         if ( $DECODED_ARGS->{'id'} && $DECODED_ARGS->{'id'} =~ /^\d+$/ ) {
318             my $id = $DECODED_ARGS->{'id'};
319             my $obj = RT::Group->new( $session{'CurrentUser'} );
320             $obj->Load($id);
321
322             my $tabs = PageMenu();
323             $tabs->child( basics         => title => loc('Basics'),       path => "/Admin/Groups/Modify.html?id=" . $obj->id );
324             $tabs->child( members        => title => loc('Members'),      path => "/Admin/Groups/Members.html?id=" . $obj->id );
325             $tabs->child( 'group-rights' => title => loc('Group Rights'), path => "/Admin/Groups/GroupRights.html?id=" . $obj->id );
326             $tabs->child( 'user-rights'  => title => loc('User Rights'),  path => "/Admin/Groups/UserRights.html?id=" . $obj->id );
327             $tabs->child( history        => title => loc('History'),      path => "/Admin/Groups/History.html?id=" . $obj->id );
328         }
329     }
330
331     if ( $request_path =~ m{^/Admin/CustomFields/} ) {
332         if ( $DECODED_ARGS->{'id'} && $DECODED_ARGS->{'id'} =~ /^\d+$/ ) {
333             my $id = $DECODED_ARGS->{'id'};
334             my $obj = RT::CustomField->new( $session{'CurrentUser'} );
335             $obj->Load($id);
336
337             my $tabs = PageMenu();
338             $tabs->child( basics         => title => loc('Basics'),       path => "/Admin/CustomFields/Modify.html?id=".$id );
339             $tabs->child( 'group-rights' => title => loc('Group Rights'), path => "/Admin/CustomFields/GroupRights.html?id=" . $id );
340             $tabs->child( 'user-rights'  => title => loc('User Rights'),  path => "/Admin/CustomFields/UserRights.html?id=" . $id );
341             $tabs->child( 'applies-to'   => title => loc('Applies to'),   path => "/Admin/CustomFields/Objects.html?id=" . $id );
342         }
343     }
344
345     if ( $request_path =~ m{^/Admin/Global/(Scrip|Template)s?\.html} ) {
346         my $type = $1;
347         my $tabs = PageMenu();
348
349         # With only two elements, swapping between dropdown and menu is kinda dumb
350         # In the glorious future this should be cleaner.
351
352         $tabs->child( select => title => loc('Select'), path => "/Admin/Global/${type}s.html" );
353         $tabs->child( create => title => loc('Create'), path => "/Admin/Global/${type}.html?Create=1" );
354     }
355
356     if ( $request_path =~ m{^/Admin/Articles/Classes/} ) {
357         my $tabs = PageMenu();
358         if ( my $id = $DECODED_ARGS->{'id'} ) {
359             my $obj = RT::CustomField->new( $session{'CurrentUser'} );
360             $obj->Load($id);
361
362             my $section = $tabs->child( select => title => loc("Classes"), path => "/Admin/Articles/Classes/" );
363             $section->child( select => title => loc('Select'), path => "/Admin/Articles/Classes/" );
364             $section->child( create => title => loc('Create'), path => "/Admin/Articles/Classes/Modify.html?Create=1" );
365
366             $tabs->child( basics          => title => loc('Basics'),        path => "/Admin/Articles/Classes/Modify.html?id=".$id );
367             $tabs->child( topics          => title => loc('Topics'),        path => "/Admin/Articles/Classes/Topics.html?id=".$id );
368             $tabs->child( 'custom-fields' => title => loc('Custom Fields'), path => "/Admin/Articles/Classes/CustomFields.html?id=".$id );
369             $tabs->child( 'group-rights'  => title => loc('Group Rights'),  path => "/Admin/Articles/Classes/GroupRights.html?id=".$id );
370             $tabs->child( 'user-rights'   => title => loc('User Rights'),   path => "/Admin/Articles/Classes/UserRights.html?id=".$id );
371             $tabs->child( 'applies-to'    => title => loc('Applies to'),    path => "/Admin/Articles/Classes/Objects.html?id=$id" );
372         } else {
373             $tabs->child( select => title => loc('Select'), path => "/Admin/Articles/Classes/" );
374             $tabs->child( create => title => loc('Create'), path => "/Admin/Articles/Classes/Modify.html?Create=1" );
375         }
376     }
377 };
378
379
380 my $build_main_nav = sub {
381
382     my $home = Menu->child( home => title => loc('Homepage'), path => '/' );
383     # We explicitly exclude superusers; otherwise the dashboards for
384     # groups you're not in (but can see the dashboards of by dint of
385     # being a superuser) would push the useful ones from the groups
386     # you're actually in off of the stack.
387     my @dashboards = $m->comp("/Dashboards/Elements/ListOfDashboards", IncludeSuperuserGroups => 0);
388     my $limit      = 7;
389
390     my $more = 0;
391     if ( @dashboards > $limit ) {
392         $more = 1;
393         splice @dashboards, $limit;
394     }
395
396     my $dashes = Menu()->child('home');
397     if (@dashboards) {
398         for my $dash (@dashboards) {
399             $home->child( 'dashboard-' . $dash->id,
400                 title => $dash->Name,
401                 path  => '/Dashboards/' . $dash->id . '/' . $dash->Name
402             );
403         }
404
405         $dashes->child( more => title => loc('All Dashboards'), path => 'Dashboards/index.html' );
406     }
407     my $dashboard = RT::Dashboard->new( $session{CurrentUser} );
408     if ( $dashboard->CurrentUserCanCreateAny ) {
409         $dashes->child('dashboard_create' => title => loc('New Dashboard'), path => "/Dashboards/Modify.html?Create=1" );
410     }
411
412     my $tickets = Menu->child( search => title => loc('Tickets'), path => '/Search/Build.html' );
413     $tickets->child( simple => title => loc('Simple Search'), path => "/Search/Simple.html" );
414     $tickets->child( new    => title => loc('New Search'),    path => "/Search/Build.html?NewQuery=1" );
415
416
417     my $tools = Menu->child( tools => title => loc('Tools'), path => '/Tools/index.html' );
418     my $articles = $tools->child( articles => title => loc('Articles'), path => "/Articles/index.html");
419     $articles->child( articles => title => loc('Overview'), path => "/Articles/index.html" );
420     $articles->child( search   => title => loc('Search'),   path => "/Articles/Article/Search.html" );
421     $articles->child( topics   => title => loc('Topics'),   path => "/Articles/Topics.html" );
422
423     $tools->child( my_day =>
424         title       => loc('My Day'),
425         description => loc('Easy updating of your open tickets'),
426         path        => '/Tools/MyDay.html',
427     );
428
429     if ( RT->Config->Get('EnableReminders') ) {
430         $tools->child( my_reminders =>
431             title       => loc('My Reminders'),
432             description => loc('Easy viewing of your reminders'),
433             path        => '/Tools/MyReminders.html',
434         );
435     }
436
437     $tools->child( offline =>
438         title       => loc('Offline'),
439         description => loc('Create tickets offline'),
440         path        => '/Tools/Offline.html',
441     );
442
443     if ( $session{'CurrentUser'}->HasRight( Right => 'ShowApprovalsTab', Object => RT->System ) ) {
444         $tools->child( approval =>
445             title       => loc('Approval'),
446             description => loc('My Approvals'),
447             path        => '/Approvals/',
448         );
449     }
450
451     if ( $session{'CurrentUser'}->HasRight( Right => 'ShowConfigTab', Object => RT->System ) )
452     {
453         $build_admin_menu->($tools);
454     }
455
456     my $username = '<span class="current-user">'
457                  . $m->interp->apply_escapes($session{'CurrentUser'}->Name, 'h')
458                  . '</span>';
459     my $about_me = Menu->child( 'preferences' =>
460         title        => loc('Logged in as [_1]', $username),
461         escape_title => 0,
462         sort_order   => 99,
463     );
464
465
466     if ( $session{'CurrentUser'}->UserObj
467          && $session{'CurrentUser'}->HasRight( Right => 'ModifySelf', Object => RT->System )) {
468         my $settings = $about_me->child( settings => title => loc('Settings'), path => '/Prefs/Other.html' );
469         $settings->child( options        => title => loc('Options'),        path => '/Prefs/Other.html' );
470         $settings->child( about_me       => title => loc('About me'),       path => '/User/Prefs.html' );
471         $settings->child( search_options => title => loc('Search options'), path => '/Prefs/SearchOptions.html' );
472         $settings->child( myrt           => title => loc('RT at a glance'), path => '/Prefs/MyRT.html' );
473         $settings->child( quicksearch    => title => loc('Quick search'),   path => '/Prefs/Quicksearch.html' );
474
475         my $search_menu = $settings->child( 'saved-searches' => title => loc('Saved Searches') );
476         my $searches = [ $m->comp( "/Search/Elements/SearchesForObject",
477                           Object => RT::System->new( $session{'CurrentUser'} )) ];
478         my $i = 0;
479
480         for my $search (@$searches) {
481             $search_menu->child( "search-" . $i++ =>
482                 title => $search->[0],
483                 path  => "/Prefs/Search.html?"
484                        . $query_string->( name => ref( $search->[1] ) . '-' . $search->[1]->Id ),
485             );
486
487         }
488     }
489     if ( $session{'CurrentUser'}->Name
490          && (   !RT->Config->Get('WebExternalAuth')
491               || RT->Config->Get('WebFallbackToInternalAuth') )) {
492         $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' );
493     }
494     if ( $request_path =~ m{^/Dashboards/(\d+)?}) {
495         if ( my $id = ( $1 || $DECODED_ARGS->{'id'} ) ) {
496             my $obj = RT::Dashboard->new( $session{'CurrentUser'} );
497             $obj->LoadById($id);
498             if ( $obj and $obj->id ) {
499                 my $tabs = PageMenu;
500                 $tabs->child( basics       => title => loc('Basics'),       path => "/Dashboards/Modify.html?id=" . $obj->id);
501                 $tabs->child( content      => title => loc('Content'),      path => "/Dashboards/Queries.html?id=" . $obj->id);
502                 $tabs->child( subscription => title => loc('Subscription'), path => "/Dashboards/Subscription.html?id=" . $obj->id)
503                     if $obj->CurrentUserCanSubscribe;
504                 $tabs->child( show         => title => loc('Show'),         path => "/Dashboards/" . $obj->id . "/" . $obj->Name)
505             }
506         }
507     }
508
509
510     if ( $request_path =~ m{^/Ticket/} ) {
511         if ( ( $DECODED_ARGS->{'id'} || '' ) =~ /^(\d+)$/ ) {
512             my $id  = $1;
513             my $obj = RT::Ticket->new( $session{'CurrentUser'} );
514             $obj->Load($id);
515
516             my $actions = PageMenu()->child( actions => title => loc('Actions'), sort_order  => 95 );
517             my $tabs = PageMenu();
518             $tabs->child( bookmark => raw_html => $m->scomp( '/Ticket/Elements/Bookmark', id => $id ), sort_order => 99 );
519             $tabs->child( display => title => loc('Display'), path => "/Ticket/Display.html?id=" . $id );
520             $tabs->child( history => title => loc('History'), path => "/Ticket/History.html?id=" . $id );
521
522             my %can = %{ $obj->CurrentUser->PrincipalObj->HasRights( Object => $obj ) };
523             $can{'_ModifyOwner'} = $can{'OwnTicket'} || $can{'TakeTicket'} || $can{'StealTicket'};
524             my $can = sub {
525                 unless ($_[0] eq 'ExecuteCode') {
526                     return $can{$_[0]} || $can{'SuperUser'};
527                 } else {
528                     return !RT->Config->Get('DisallowExecuteCode')
529                         && ( $can{'ExecuteCode'} || $can{'SuperUser'} );
530                 }
531             };
532
533             # comment out until we can do it for an individual custom field
534             #if ( $can->('ModifyTicket') || $can->('ModifyCustomField') ) {
535             $tabs->child( basics => title => loc('Basics'), path => "/Ticket/Modify.html?id=" . $id );
536
537             #}
538
539             #ACL?
540             $tabs->child( customers => title => loc('Customers'), path => "/Ticket/ModifyCustomers.html?id=" . $id );
541
542             if ( $can->('ModifyTicket') || $can->('_ModifyOwner') || $can->('Watch') || $can->('WatchAsAdminCc') ) {
543                 $tabs->child( people => title => loc('People'), path => "/Ticket/ModifyPeople.html?id=" . $id );
544             }
545
546             if ( $can->('ModifyTicket') ) {
547                 $tabs->child( dates => title => loc('Dates'), path => "/Ticket/ModifyDates.html?id=" . $id );
548                 $tabs->child( links => title => loc('Links'), path => "/Ticket/ModifyLinks.html?id=" . $id );
549             }
550
551             #if ( $can->('ModifyTicket') || $can->('ModifyCustomField') || $can->('_ModifyOwner') ) {
552             $tabs->child( jumbo => title => loc('Jumbo'), path => "/Ticket/ModifyAll.html?id=" . $id );
553             #}
554
555             if ( RT->Config->Get('EnableReminders') ) {
556                 $tabs->child( reminders => title => loc('Reminders'), path => "/Ticket/Reminders.html?id=" . $id );
557             }
558
559             if ( $can->('ModifyTicket') or $can->('ReplyToTicket') ) {
560                 $actions->child( reply => title => loc('Reply'), path => "/Ticket/Update.html?Action=Respond;id=" . $id );
561             }
562
563             if ( $can->('ModifyTicket') or $can->('CommentOnTicket') ) {
564                 $actions->child( comment => title => loc('Comment'), path => "/Ticket/Update.html?Action=Comment;id=" . $id );
565             }
566
567             if ( $can->('ForwardMessage') ) {
568                 $actions->child( forward => title => loc('Forward'), path => "/Ticket/Forward.html?id=" . $id );
569             }
570
571             my $hide_resolve_with_deps = RT->Config->Get('HideResolveActionsWithDependencies')
572                 && $obj->HasUnresolvedDependencies;
573
574             my $current   = $obj->Status;
575             my $lifecycle = $obj->QueueObj->Lifecycle;
576             my $i         = 1;
577             foreach my $info ( $lifecycle->Actions($current) ) {
578                 my $next = $info->{'to'};
579                 next unless $lifecycle->IsTransition( $current => $next );
580
581                 my $check = $lifecycle->CheckRight( $current => $next );
582                 next unless $can->($check);
583
584                 next if $hide_resolve_with_deps
585                     && $lifecycle->IsInactive($next)
586                     && !$lifecycle->IsInactive($current);
587
588                 my $action = $info->{'update'} || '';
589                 my $url = '/Ticket/';
590                 if ($action) {
591                     $url .= "Update.html?"
592                         . $query_string->(
593                             Action        => $action,
594                             DefaultStatus => $next,
595                             id            => $id,
596                         );
597                 } else {
598                     $url .= "Display.html?"
599                         . $query_string->(
600                             Status => $next,
601                             id     => $id,
602                         );
603                 }
604                 my $key = $info->{'label'} || ucfirst($next);
605                 $actions->child( $key => title => loc( $key ), path => $url);
606             }
607
608             if ( $can->('OwnTicket') ) {
609                 if ( $obj->OwnerObj->Id == RT->Nobody->id
610                      && ( $can->('ModifyTicket') or $can->('TakeTicket') ) ) {
611                     $actions->child( take => title => loc('Take'), path => "/Ticket/Display.html?Action=Take;id=" . $id );
612                 }
613
614                 elsif (    $obj->OwnerObj->id != RT->Nobody->id
615                         && $obj->OwnerObj->id != $session{CurrentUser}->id
616                         && ( $can->('ModifyTicket') or $can->('StealTicket') ) ) {
617                     $actions->child( steal => title => loc('Steal'), path => "/Ticket/Display.html?Action=Steal;id=" . $id );
618                 }
619             }
620
621             # TODO needs a "Can extract article into a class applied to this queue" check
622             $actions->child( 'extract-article' =>
623                 title => loc('Extract Article'),
624                 path  => "/Articles/Article/ExtractIntoClass.html?Ticket=".$obj->id,
625             );
626
627             if ( defined $session{"tickets"} ) {
628                 # we have to update session data if we get new ItemMap
629                 my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
630
631                 my $item_map = $session{"tickets"}->ItemMap;
632
633                 if ($updatesession) {
634                     $session{"tickets"}->PrepForSerialization();
635                 }
636
637                 my $search = Menu()->child('search');
638                 # Don't display prev links if we're on the first ticket
639                 if ( $item_map->{$id}->{prev} ) {
640                     $search->child( first =>
641                         title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
642                     $search->child( prev =>
643                         title => '< ' . loc('Prev'),   class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
644                 }
645                 # Don't display next links if we're on the last ticket
646                 if ( $item_map->{$id}->{next} ) {
647                     $search->child( next =>
648                         title => loc('Next') . ' >',  class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
649                     $search->child( last =>
650                         title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
651                 }
652             }
653         }
654     }
655
656     if (
657         (
658                $request_path =~ m{^/(?:Ticket|Search)/}
659             && $request_path !~ m{^/Search/Simple\.html}
660         )
661         || (   $request_path =~ m{^/Search/Simple\.html}
662             && $DECODED_ARGS->{'q'} )
663       )
664     {
665         my $search = Menu()->child('search');
666         my $args      = '';
667         my $has_query = '';
668         my $current_search = $session{"CurrentSearchHash"} || {};
669         my $search_id = $DECODED_ARGS->{'SavedSearchLoad'} || $DECODED_ARGS->{'SavedSearchId'} || $current_search->{'SearchId'} || '';
670         my $chart_id = $DECODED_ARGS->{'SavedChartSearchId'} || $current_search->{SavedChartSearchId};
671
672         $has_query = 1 if ( $DECODED_ARGS->{'Query'} or $current_search->{'Query'} );
673
674         my %query_args;
675         my %fallback_query_args = (
676             SavedSearchId => ( $search_id eq 'new' ) ? undef : $search_id,
677             SavedChartSearchId => $chart_id,
678             (
679                 map {
680                     my $p = $_;
681                     $p => $DECODED_ARGS->{$p} || $current_search->{$p}
682                 } qw(Query Format OrderBy Order Page)
683             ),
684             RowsPerPage => (
685                 defined $DECODED_ARGS->{'RowsPerPage'}
686                 ? $DECODED_ARGS->{'RowsPerPage'}
687                 : $current_search->{'RowsPerPage'}
688             ),
689         );
690
691         if ($QueryString) {
692             $args = '?' . $QueryString;
693         }
694         else {
695             my %final_query_args = ();
696             # key => callback to avoid unnecessary work
697
698             for my $param (keys %fallback_query_args) {
699                 $final_query_args{$param} = defined($QueryArgs->{$param})
700                                           ? $QueryArgs->{$param}
701                                           : $fallback_query_args{$param};
702             }
703
704             for my $field (qw(Order OrderBy)) {
705                 if ( ref( $final_query_args{$field} ) eq 'ARRAY' ) {
706                     $final_query_args{$field} = join( "|", @{ $final_query_args{$field} } );
707                 } elsif (not defined $final_query_args{$field}) {
708                     delete $final_query_args{$field};
709                 }
710                 else {
711                     $final_query_args{$field} ||= '';
712                 }
713             }
714
715             $args = '?' . $query_string->(%final_query_args);
716         }
717
718         my $current_search_menu;
719         if ( $request_path =~ m{^/Ticket} ) {
720             $current_search_menu = $search->child( current_search => title => loc('Current Search') );
721             $current_search_menu->path("/Search/Results.html$args") if $has_query;
722         } else {
723             $current_search_menu = PageMenu();
724         }
725
726         $current_search_menu->child( edit_search =>
727             title => loc('Edit Search'), path => "/Search/Build.html" . ( ($has_query) ? $args : '' ) );
728         $current_search_menu->child( advanced =>
729             title => loc('Advanced'),    path => "/Search/Edit.html$args" );
730         if ($has_query) {
731             $current_search_menu->child( results => title => loc('Show Results'), path => "/Search/Results.html$args" );
732         }
733
734         if ( $has_query ) {
735             $current_search_menu->child( bulk  => title => loc('Bulk Update'), path => "/Search/Bulk.html$args" );
736             $current_search_menu->child( chart => title => loc('Chart'),       path => "/Search/Chart.html$args" );
737
738             #formerly Callbacks/RTx-Calendar/Ticket/Element/Tabs/Default
739             $current_search_menu->child( calendar => title => loc('Calendar'), path => "/Search/Calendar.html$args" );
740
741             my $more = $current_search_menu->child( more => title => loc('Feeds') );
742
743             $more->child( tsv => title => loc('TSV'), path => "/Search/Results.tsv$args" );
744             $more->child( csv => title => loc('CSV'), path => "/Search/Results.csv$args" );
745             $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Search/Results.xls$args" );
746
747             my %rss_data = map {
748                 $_ => $QueryArgs->{$_} || $fallback_query_args{$_} || '' }
749                     qw(Query Order OrderBy);
750             my $RSSQueryString = "?"
751                 . $query_string->( Query   => $rss_data{Query},
752                                    Order   => $rss_data{Order},
753                                    OrderBy => $rss_data{OrderBy}
754                                  );
755             my $RSSPath = join '/', map $m->interp->apply_escapes( $_, 'u' ),
756                 $session{'CurrentUser'}->UserObj->Name,
757                 $session{'CurrentUser'}
758                 ->UserObj->GenerateAuthString(   $rss_data{Query}
759                                                . $rss_data{Order}
760                                                . $rss_data{OrderBy} );
761
762             $more->child( rss => title => loc('RSS'), path => "/NoAuth/rss/$RSSPath/$RSSQueryString");
763             my $ical_path = join '/', map $m->interp->apply_escapes($_, 'u'),
764                 $session{'CurrentUser'}->UserObj->Name,
765                 $session{'CurrentUser'}->UserObj->GenerateAuthString( $rss_data{Query} ),
766                 $rss_data{Query};
767             $more->child( ical => title => loc('iCal'), path => '/NoAuth/iCal/'.$ical_path);
768
769             if ($request_path =~ m{^/Search/Results.html}
770                 &&                        #XXX TODO better abstraction
771                 $session{'CurrentUser'}->HasRight( Right => 'SuperUser', Object => RT->System )) {
772                 my $shred_args = $query_string->(
773                     search          => 1,
774                     plugin          => 'Tickets',
775                     'Tickets:query' => $rss_data{'Query'},
776                     'Tickets:limit' => $QueryArgs->{'Rows'},
777                 );
778
779                 $more->child( shredder => title => loc('Shredder'), path => '/Admin/Tools/Shredder/?' . $shred_args);
780             }
781
782         }
783     }
784
785     if ( $request_path =~ m{^/Article/} ) {
786         if ( $DECODED_ARGS->{'id'} && $DECODED_ARGS->{'id'} =~ /^\d+$/ ) {
787             my $id = $DECODED_ARGS->{'id'};
788             my $tabs = PageMenu();
789
790             $tabs->child( display => title => loc('Display'), path => "/Articles/Article/Display.html?id=".$id );
791             $tabs->child( history => title => loc('History'), path => "/Articles/Article/History.html?id=".$id );
792             $tabs->child( modify  => title => loc('Modify'),  path => "/Articles/Article/Edit.html?id=".$id );
793             $tabs->child( delete  => title => loc('Delete'),  path => "/Articles/Article/Delete.html?id=".$id );
794         }
795     }
796
797     if ( $request_path =~ m{^/Articles/} ) {
798         my $tabs = PageMenu();
799         $tabs->child( search => title => loc("Search"),       path => "/Articles/Article/Search.html" );
800         $tabs->child( create => title => loc("New Article" ), path => "/Articles/Article/PreCreate.html" );
801         if ( $request_path =~ m{^/Articles/Article/} and ( $DECODED_ARGS->{'id'} || '' ) =~ /^(\d+)$/ ) {
802             my $id  = $1;
803             my $obj = RT::Article->new( $session{'CurrentUser'} );
804             $obj->Load($id);
805
806             $tabs->child( display => title => loc("Display"), path => "/Articles/Article/Display.html?id=" . $id );
807             $tabs->child( history => title => loc('History'), path => '/Articles/Article/History.html?id=' . $id );
808
809             if ( $obj->CurrentUserHasRight('ModifyArticle') ) {
810                 $tabs->child(modify => title => loc('Modify'), path => '/Articles/Article/Edit.html?id=' . $id );
811             }
812             if ( $obj->CurrentUserHasRight('DeleteArticle') ) {
813                 $tabs->child(delete => title => loc('Delete'), path => '/Articles/Article/Delete.html?id=' . $id );
814             }
815         }
816
817     }
818
819     if ( $request_path =~ /^\/(?:index.html|$)/ ) {
820         PageMenu()->child( edit => title => loc('Edit'), path => '/Prefs/MyRT.html' );
821     }
822
823     PageWidgets()->child( simple_search => raw_html => $m->scomp('SimpleSearch') );
824     PageWidgets()->child( create_ticket => raw_html => $m->scomp('CreateTicket') );
825
826     $m->callback( CallbackName => 'Privileged' );
827 };
828
829 my $build_selfservice_nav = sub {
830     my $queues = RT::Queues->new( $session{'CurrentUser'} );
831     $queues->UnLimit;
832
833     my $queue_count = 0;
834     my $queue_id;
835
836     while ( my $queue = $queues->Next ) {
837         next unless $queue->CurrentUserHasRight('CreateTicket');
838         $queue_id = $queue->id;
839         $queue_count++;
840         last if ( $queue_count > 1 );
841     }
842
843
844     if ( $queue_count > 1 ) {
845         Menu->child( new => title => loc('New ticket'), path => '/SelfService/CreateTicketInQueue.html' );
846     } elsif ( $queue_id ) {
847         Menu->child( new => title => loc('New ticket'), path => '/SelfService/Create.html?Queue=' . $queue_id );
848     }
849     my $tickets = Menu->child( tickets => title => loc('Tickets'), path => '/SelfService/' );
850     $tickets->child( open   => title => loc('Open tickets'),   path => '/SelfService/' );
851     $tickets->child( closed => title => loc('Closed tickets'), path => '/SelfService/Closed.html' );
852
853
854     my $username = '<span class="current-user">'
855                  . $m->interp->apply_escapes($session{'CurrentUser'}->Name, 'h')
856                  . '</span>';
857     my $about_me = Menu->child( preferences =>
858         title        => loc('Logged in as [_1]', $username),
859         escape_title => 0,
860         sort_order   => 99,
861     );
862
863     if ( $session{'CurrentUser'}->HasRight( Right => 'ModifySelf', Object => RT->System ) ) {
864         $about_me->child( prefs => title => loc('Preferences'), path => '/SelfService/Prefs.html' );
865     }
866
867     if ( $session{'CurrentUser'}->Name
868          && (   !RT->Config->Get('WebExternalAuth')
869               || RT->Config->Get('WebFallbackToInternalAuth') )) {
870         $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' );
871     }
872
873     if ($session{'CurrentUser'}->HasRight( Right => 'ShowArticle', Object => RT->System )) {
874         PageWidgets->child( 'goto-article' => raw_html => $m->scomp('/SelfService/Elements/SearchArticle') );
875     }
876
877     PageWidgets->child( goto => raw_html => $m->scomp('/SelfService/Elements/GotoTicket') );
878
879     $m->callback( CallbackName => 'SelfService' );
880 };
881
882
883
884 if ( $request_path !~ m{^/SelfService/} ) {
885     $build_main_nav->();
886 } else {
887     $build_selfservice_nav->();
888 }
889
890
891
892
893 </%INIT>
894 <%ARGS>
895 $show_menu => 1
896 $QueryString => ''
897 $QueryArgs => {}
898 </%ARGS>