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