1 <% include( 'elements/search.html',
2 'title' => 'Attachments',
4 'name' => ($disabled ? 'deleted' : '') .' attachments',
5 'html_init' => include('/elements/init_overlib.html') .
6 ($curuser->access_right('View deleted attachments') ? (
7 selflink('Show '.($disabled ? 'active' : 'deleted'),
8 show_deleted => (1-$disabled))) : ''),
10 qq!<FORM NAME="attachForm" ACTION="$p/misc/cust_attachment.cgi" METHOD="POST">
11 <INPUT TYPE="hidden" NAME="orderby" VALUE="$orderby">
12 <INPUT TYPE="hidden" NAME="show_deleted" VALUE="$disabled">!
15 'count_query' => $count_query,
16 'header' => [ selflink('#',orderby => 'attachnum'),
17 #selflink('Customer',orderby => 'custnum'),
18 FS::UI::Web::cust_header(
19 $cgi->param('cust_fields')
21 selflink('Date',orderby => '_date'),
22 selflink('Filename',orderby => 'filename'),
23 selflink('Size',orderby => 'length(body)'),
24 selflink('Uploaded by',orderby => 'otaker'),
25 selflink('Description',orderby => 'title'),
31 \&FS::UI::Web::cust_fields,
40 ( map { $_ ne 'Cust. Status' ? $clink : '' }
41 FS::UI::Web::cust_header(
42 $cgi->param('cust_fields')
48 ( map '', FS::UI::Web::cust_header(
49 $cgi->param('cust_fields')
57 FS::UI::Web::cust_colors(),
61 FS::UI::Web::cust_styles(),
63 'align' => 'r'. FS::UI::Web::cust_aligns(),
73 'html_foot' => $sub_foot,
81 my $curuser = $FS::CurrentUser::CurrentUser;
82 die "access denied" if !$curuser->access_right('View attachments')
83 or !$curuser->access_right('Browse attachments');
85 my $conf = new FS::Conf;
92 if($cgi->param('show_deleted')) {
93 if ($curuser->access_right('View deleted attachments')) {
95 if ($curuser->access_right('Purge attachment') or
96 $curuser->access_right('Undelete attachment')) {
105 if ($curuser->access_right('Delete attachment')) {
110 my $orderby = $cgi->param('orderby') || 'custnum';
113 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
114 $extra_sql = " AND agentnum = $1 ";
118 table => 'cust_attachment',
119 hashref => { disabled => $disabled ? { op => '>', value => 0 } : '', },
120 order_by => "ORDER BY $orderby",
121 addl_from => 'JOIN cust_main USING (custnum)',
122 extra_sql => "$extra_sql AND ". $curuser->agentnums_sql,
125 my $count_query = 'SELECT COUNT(*) FROM cust_attachment'
126 . ' JOIN cust_main USING (custnum)'
127 . ' WHERE ' . $curuser->agentnums_sql
128 . ' AND disabled ' . ( $disabled ? '> 0' : 'IS NULL' );
131 #still need to report on attachments with deleted customer? did we ever?
132 #my $sub_cust = sub {
133 # my $c = qsearchs('cust_main', { custnum => shift->custnum } );
134 # return $c ? encode_entities($c->name) : '<FONT COLOR="red"><B>(not found)</B></FONT>';
137 my $clink = [ $p.'view/cust_main.cgi?', 'custnum' ];
140 time2str("%b %o, %Y", shift->_date);
144 my $size = shift->size;
145 return $size if $size < 1024;
146 return int($size/1024).'K' if $size < 1048576;
147 return int($size/1048576).'M';
150 my $sub_checkbox = sub {
151 return '' if $noactions;
153 my $attachnum = $attach->attachnum;
155 return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
158 my $sub_edit_link = sub {
160 my $attachnum = $attach->attachnum;
161 my $custnum = $attach->custnum;
162 return include('/elements/popup_link_onclick.html',
163 action => popurl(2).'edit/cust_main_attach.cgi?'.
164 "custnum=$custnum;attachnum=$attachnum",
165 actionlabel => 'Edit attachment properties',
175 my $param = $cgi->Vars;
176 my %old_param = %$param;
177 @{$param}{keys(%new_param)} = values(%new_param);
178 my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
179 %$param = %old_param;
185 my $onclick = "return(confirm('$action all selected files?'))";
186 return qq!onclick="$onclick"!;
190 return '' if ($noactions or !$areboxes);
192 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
193 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
195 if ($curuser->access_right('Undelete attachment')) {
196 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
198 if ($curuser->access_right('Purge attachment')) {
199 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
203 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
206 '<SCRIPT TYPE="text/javascript">
207 function setAll(setTo) {
208 theForm = document.attachForm;
209 for (i=0,n=theForm.elements.length;i<n;i++)
210 if (theForm.elements[i].name.indexOf("attachnum") != -1)
211 theForm.elements[i].checked = setTo;