Wholesale CDR cost re-billing, RT#27555
[freeside.git] / httemplate / view / cust_main / attachments.html
1 % if ( scalar(@attachments) ) {
2
3   <& /elements/init_overlib.html &>
4
5   <& /elements/table-grid.html &>
6
7   <TR>
8     <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
9 %   if ( $conf->exists('cust_main_note-display_times') ) {
10       <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Time') |h %></TH>
11 %   }
12     <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Person') |h %></TH>
13     <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Filename') |h %></TH>
14     <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Description') |h %></TH>
15     <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Type') |h %></TH>
16     <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Size') |h %></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 %                           emt('Undelete attachment'));
52 %       $edit .= linkstr($clickjs, emt('undelete'));
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 %                           emt('Purge attachment'),
59 %                           emt('Permanently remove this file?') );
60 %       $edit .= linkstr($clickjs,emt('purge'));
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 %                           emt('Edit attachment properties'));
68 %       $edit .= linkstr($clickjs,emt('edit'));
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 .= linkstr($clickjs,emt('delete'));
76 %     }
77 %     if ($curuser->access_right('Download attachment') ) {
78 %       $edit .= qq!&nbsp; <A HREF="!.popurl(1).'attachment.html?'.$attachnum.qq!">(!
79 %                               . emt('download') .')</A>';
80 %     }
81 %   }
82
83     <TR>
84       <% note_datestr($attach,$conf,$bgcolor) %>
85       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
86         &nbsp;<% $attach->usernum ? $attach->access_user->name : $attach->otaker %>
87       </TD>
88       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
89        &nbsp;<% $attach->filename |h %>
90       </TD>
91       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
92        &nbsp;<% $attach->title |h %>
93       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
94        &nbsp;<% $attach->mime_type |h %>
95       </TD>
96       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
97        &nbsp;<% size_units( $attach->size ) %>
98       </TD>
99       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
100        <% $edit %>
101       </TD>
102     </TR>
103
104 % } #end display notes
105
106 </TABLE>
107
108 % }
109 <%init>
110
111 my $conf = new FS::Conf;
112 my $curuser = $FS::CurrentUser::CurrentUser;
113 die "access denied" if !$curuser->access_right('View attachments');
114 my(%opt) = @_;
115
116 my $custnum = $opt{'custnum'};
117
118 my $cust_main = qsearchs('cust_main', {'custnum' => $custnum} );
119 die "Customer not found!" unless $cust_main;
120
121 my (@attachments) = qsearch('cust_attachment', {'custnum' => $custnum});
122
123 #subroutines
124
125 sub note_datestr {
126   my($note, $conf, $bgcolor) = @_ or return '';
127   my $td = qq{<TD CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">};
128   my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
129   $format .= "$td%l:%M%P</TD>"
130     if $conf->exists('cust_main_note-display_times');
131   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
132   $strip;
133 }
134
135 sub linkstr {
136     my ($clickjs, $label) = (shift,shift);
137     '&nbsp; <A HREF="javascript:void(0);" '. $clickjs . '>(' . emt($label) . ')</A>';
138 }
139
140 sub size_units {
141   my $bytes = shift;
142   return $bytes if $bytes < 1024;
143   return int($bytes / 1024)."K" if $bytes < 1048576;
144   return int($bytes / 1048576)."M";
145 }
146
147 sub popup {
148   my ($url, $label, $confirm) = @_;
149   my $onclick = 
150     include('/elements/popup_link_onclick.html',
151       'action'     => popurl(2).$url,
152       'actionlabel' => $label,
153       'width'       => 510,
154       'height'      => 315,
155       'frame'       => 'top',
156     );
157   $onclick = qq!if(confirm('$confirm')) { $onclick }! if $confirm;
158   return qq!onclick="$onclick"!;
159 }
160
161
162 </%init>