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