Reverted menu-left-example.png back to original and cleaned up menu-top-example to...
[freeside.git] / httemplate / browse / template_image.html
1 <% include('/elements/init_overlib.html') %>
2
3 <% include( 'elements/browse.html',
4               'title'         => 'Template images',
5               'name_singular' => 'image',
6               'menubar'       => \@menubar,
7               'query'         => { 'table' => 'template_image', },
8               'count_query'   => 'SELECT COUNT(*) FROM template_image',
9               'agent_virt'         => 1,
10               'agent_null_right'   => ['View global templates','Edit global templates'],
11               'agent_pos'          => 1,
12               'header'      => [ 'Name', '', '' ],
13               'fields'      => [ 'name', $tag, $delete_text ],
14               'links'       => [ '', '', '' ],
15               'cell_style'    => [ '', '', '' ],
16           )
17 %>
18
19 <% include('/elements/template_image-dialog.html',
20      'url' => $p.'browse/template_image.html'
21    ) %>
22
23 <%init>
24 use FS::template_image;
25
26 my $curuser = $FS::CurrentUser::CurrentUser;
27
28 die "access denied"
29   unless $curuser->access_right([ 'View templates', 'View global templates',
30                                   'Edit templates', 'Edit global templates', ]);
31
32 my $canedit = $curuser->access_right(['Edit templates', 'Edit global templates']);
33
34 my @menubar = ();
35 if ($canedit) {
36   push @menubar, 'Upload a new image' => 'javascript:insertImageDialog(\'upload\')';
37 }
38 push @menubar, ( 'View message templates' => $p.'browse/msg_template.html' );
39
40 my $tag = sub { qq!<A HREF="javascript:insertImageDialog(! . $_[0]->imgnum . qq!)">view</A>! };
41
42 my $delete_text = $canedit ? sub {
43   my $image = shift;
44   my $imgnum = $image->imgnum;
45   unless ($image->agentnum) {
46     unless ($FS::CurrentUser::CurrentUser->access_right('Edit global templates')) {
47       return '';
48     }
49   }
50   my $out = <<EOF;
51 <FORM name="delete_template_image_$imgnum">
52 <INPUT TYPE="hidden" name="imgnum" value="$imgnum">
53 </FORM>
54 EOF
55   $out .= include('/elements/progress-init.html',
56             "delete_template_image_$imgnum",
57             [ 'imgnum' ],
58             $p.'misc/process/template_image-delete.cgi',
59             $p.'browse/template_image.html',
60             "imgnum$imgnum",
61           );
62   my $onclick = 'if ( confirm(\'';
63   $onclick .= emt('Are you sure you want to delete template image ') . $imgnum;
64   $onclick .= '\') ) { imgnum' . $imgnum . 'process() }';
65   return $out . '<A HREF="javascript:void(0)" ONCLICK="' . $onclick . '">delete</A>';
66 } : '';
67
68 </%init>