Add access right to view attachments
[freeside.git] / httemplate / view / cust_main / attachments.html
1 % if ( scalar(@attachments) ) {
2
3   <% include('/elements/init_overlib.html') %>
4
5   <% include("/elements/table-grid.html") %>
6
7   <TR>
8     <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
9 %   if ( $conf->exists('cust_main_note-display_times') ) {
10       <TH CLASS="grid" BGCOLOR="#cccccc">Time</TH>
11 %   }
12     <TH CLASS="grid" BGCOLOR="#cccccc">Person</TH>
13     <TH CLASS="grid" BGCOLOR="#cccccc">Filename</TH>
14     <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
15     <TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>
16     <TH CLASS="grid" BGCOLOR="#cccccc">Size</TH>
17     <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
18   </TR>
19
20 % my $bgcolor1 = '#eeeeee';
21 % my $bgcolor2 = '#ffffff';
22 % my $bgcolor = '';
23 % if($cgi->param('show_deleted')) {
24 %   if ($curuser->access_right('View deleted attachments')) {
25 %     @attachments = grep { $_->disabled } @attachments;
26 %   }
27 %   else {
28 %     @attachments = ();
29 %   }
30 % }
31 % else {
32 %   @attachments = grep { not $_->disabled } @attachments;
33 % }
34 %
35 % foreach my $attach (@attachments) {
36 %
37 %   if ( $bgcolor eq $bgcolor1 ) {
38 %     $bgcolor = $bgcolor2;
39 %   } else {
40 %     $bgcolor = $bgcolor1;
41 %   }
42 %
43 %   my $pop = popurl(3);
44 %   my $attachnum = $attach->attachnum;
45 %   my $edit = '';
46 %   if($attach->disabled) { # then you can undelete it or purge it.
47 %     if ($curuser->access_right('Undelete attachment')) {
48 %       my $clickjs = popup('edit/process/cust_main_attach.cgi?'.
49 %                           "custnum=$custnum;attachnum=$attachnum;".
50 %                           "undelete=1",
51 %                           'Undelete attachment');
52 %       $edit .= qq!&nbsp; <A HREF="javascript:void(0);" $clickjs>(undelete)</A>!;
53 %     }
54 %     if ($curuser->access_right('Purge attachment')) {
55 %       my $clickjs = popup('edit/process/cust_main_attach.cgi?'.
56 %                           "custnum=$custnum;attachnum=$attachnum;".
57 %                           "purge=1",
58 %                           'Purge attachment',
59 %                           'Permanently remove this file?');
60 %       $edit .= qq!&nbsp; <A HREF="javascript:void(0);" $clickjs>(purge)</A>!;
61 %     }
62 %   }
63 %   else { # you can download or edit it
64 %     if ($curuser->access_right('Edit attachment') ) {
65 %       my $clickjs = popup('edit/cust_main_attach.cgi?'.
66 %                           "custnum=$custnum;attachnum=$attachnum",
67 %                           'Edit attachment properties');
68 %       $edit .= qq!&nbsp; <A HREF="javascript:void(0);" $clickjs>(edit)</A>!;
69 %     }
70 %     if($curuser->access_right('Delete attachment') ) {
71 %       my $clickjs = popup('edit/process/cust_main_attach.cgi?'.
72 %                           "custnum=$custnum;attachnum=$attachnum;delete=1",
73 %                           'Delete attachment',
74 %                           'Delete this file?');
75 %       $edit .= qq!&nbsp; <A HREF="javascript:void(0);" $clickjs>(delete)</A>!;
76 %     }
77 %     if ($curuser->access_right('Download attachment') ) {
78 %       $edit .= qq!&nbsp; <A HREF="!.popurl(1).'attachment.html?'.$attachnum.qq!">(download)</A>!;
79 %     }
80 %   }
81
82     <TR>
83       <% note_datestr($attach,$conf,$bgcolor) %>
84       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
85         &nbsp;<% $attach->otaker%>
86       </TD>
87       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
88        &nbsp;<% $attach->filename %>
89       </TD>
90       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
91        &nbsp;<% $attach->title %>
92       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
93        &nbsp;<% $attach->mime_type %>
94       </TD>
95       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
96        &nbsp;<% size_units( $attach->size ) %>
97       </TD>
98       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
99        <% $edit %>
100       </TD>
101     </TR>
102
103 % } #end display notes
104
105 </TABLE>
106
107 % }
108 <%init>
109
110 my $conf = new FS::Conf;
111 my $curuser = $FS::CurrentUser::CurrentUser;
112 die "access denied" if !$curuser->access_right('View attachments');
113 my(%opt) = @_;
114
115 my $custnum = $opt{'custnum'};
116
117 my $cust_main = qsearchs('cust_main', {'custnum' => $custnum} );
118 die "Customer not found!" unless $cust_main;
119
120 my (@attachments) = qsearch('cust_attachment', {'custnum' => $custnum});
121
122 #subroutines
123
124 sub note_datestr {
125   my($note, $conf, $bgcolor) = @_ or return '';
126   my $td = qq{<TD CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">};
127   my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
128   $format .= "$td%l:%M%P</TD>"
129     if $conf->exists('cust_main_note-display_times');
130   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
131   $strip;
132 }
133
134 sub size_units {
135   my $bytes = shift;
136   return $bytes if $bytes < 1024;
137   return int($bytes / 1024)."K" if $bytes < 1048576;
138   return int($bytes / 1048576)."M";
139 }
140
141 sub popup {
142   my ($url, $label, $confirm) = @_;
143   my $onclick = 
144     include('/elements/popup_link_onclick.html',
145       'action'     => popurl(2).$url,
146       'actionlabel' => $label,
147       'width'       => 510,
148       'height'      => 315,
149       'frame'       => 'top',
150     );
151   $onclick = qq!if(confirm('$confirm')) { $onclick }! if $confirm;
152   return qq!onclick="$onclick"!;
153 }
154
155
156 </%init>