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' );
130 #still need to report on attachments with deleted customer? did we ever?
131 #my $sub_cust = sub {
132 # my $c = qsearchs('cust_main', { custnum => shift->custnum } );
133 # return $c ? encode_entities($c->name) : '<FONT COLOR="red"><B>(not found)</B></FONT>';
136 my $clink = [ $p.'view/cust_main.cgi?', 'custnum' ];
139 time2str("%b %o, %Y", shift->_date);
143 my $size = shift->size;
144 return $size if $size < 1024;
145 return int($size/1024).'K' if $size < 1048576;
146 return int($size/1048576).'M';
149 my $sub_checkbox = sub {
150 return '' if $noactions;
152 my $attachnum = $attach->attachnum;
154 return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
157 my $sub_edit_link = sub {
159 my $attachnum = $attach->attachnum;
160 my $custnum = $attach->custnum;
161 return include('/elements/popup_link_onclick.html',
162 action => popurl(2).'edit/cust_main_attach.cgi?'.
163 "custnum=$custnum;attachnum=$attachnum",
164 actionlabel => 'Edit attachment properties',
174 my $param = $cgi->Vars;
175 my %old_param = %$param;
176 @{$param}{keys(%new_param)} = values(%new_param);
177 my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
178 %$param = %old_param;
184 my $onclick = "return(confirm('$action all selected files?'))";
185 return qq!onclick="$onclick"!;
189 return '' if ($noactions or !$areboxes);
191 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
192 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
194 if ($curuser->access_right('Undelete attachment')) {
195 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
197 if ($curuser->access_right('Purge attachment')) {
198 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
202 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
205 '<SCRIPT TYPE="text/javascript">
206 function setAll(setTo) {
207 theForm = document.attachForm;
208 for (i=0,n=theForm.elements.length;i<n;i++)
209 if (theForm.elements[i].name.indexOf("attachnum") != -1)
210 theForm.elements[i].checked = setTo;