Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / browse / msg_template.html
1 <% include( 'elements/browse.html',
2               'title'         => 'Message templates',
3               'name_singular' => 'template',
4               'menubar'       => \@menubar,
5               'query'         => { 'table' => 'msg_template', },
6               'count_query'   => 'SELECT COUNT(*) FROM msg_template',
7               'disableable'   => 1,
8               'disabled_statuspos' => (scalar(@locales) + 3),
9               'agent_virt'         => 1,
10               'agent_null_right'   => ['View global templates','Edit global templates'],
11               'agent_pos'          => 1,
12               'header'      => [ 'Name', '', map ('', @locales), '' ],
13               'fields'      => [ 'msgname', @locales, $disable_link_label ],
14               'links'       => [ $link, @locale_links, '' ],
15               'link_onclicks' => [ '', map('', @locale_links), $disable_link ],
16               'cell_style'    => [ '', '', map ($locale_style, @locales), $locale_style ],
17           )
18 %>
19 <%init>
20
21 my $curuser = $FS::CurrentUser::CurrentUser;
22
23 die "access denied"
24   unless $curuser->access_right([ 'View templates', 'View global templates',
25                                   'Edit templates', 'Edit global templates', ]);
26
27 my @menubar = ();
28 if ( $curuser->access_right(['Edit templates', 'Edit global templates']) ) {
29   push @menubar, 'Add a new template' => $p.'edit/msg_template.html';
30 }
31 push @menubar, 'View template images' => $p.'browse/template_image.html';
32
33 my $link = [ "${p}edit/msg_template.html?msgnum=", 'msgnum' ];
34
35 my $locale_style = 'font-size:0.8em; padding:3px';
36
37 my (@locales, @locale_links);
38 foreach my $l ( FS::Locales->locales ) {
39   push @locales, sub {
40     exists ( $_[0]->content_locales->{$l} )
41     ? +{ FS::Locales->locale_info($l) }->{'label'} 
42     : '';
43   };
44   push @locale_links, sub {
45     my $content = $_[0]->content_locales->{$l} or return '';
46     [ "${p}edit/msg_template.html?locale=$l;msgnum=", 'msgnum' ];
47   };
48 }
49
50 my $disable_link = sub {
51   my $template = shift;
52   include('/elements/popup_link_onclick.html',
53     action      => $p.'misc/disable-msg_template.cgi?msgnum=' .
54                      $template->msgnum .
55                      ($template->disabled ? ';enable=1' : ''),
56     actionlabel => 'Disable template',
57   );
58 };
59
60 my $disable_link_label = sub {
61   my $template = shift;
62   $template->disabled ? '(enable)' : '(disable)' ;
63 };
64
65 </%init>