1 <% include( 'elements/browse.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">!
14 'query' => { 'table' => 'cust_attachment',
15 'hashref' => $hashref,
16 'extra_sql' => 'ORDER BY '.$orderby,
18 'count_query' => $count_query,
19 'header' => [ selflink('#',orderby => 'attachnum'),
20 selflink('Customer',orderby => 'custnum'),
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'),
39 [ $p.'view/cust_main.cgi?', 'custnum' ],
56 'html_foot' => $sub_foot,
64 my $curuser = $FS::CurrentUser::CurrentUser;
65 die "access denied" if !$curuser->access_right('View attachments')
66 or !$curuser->access_right('Browse attachments');
68 my $conf = new FS::Conf;
75 if($cgi->param('show_deleted')) {
76 if ($curuser->access_right('View deleted attachments')) {
78 if ($curuser->access_right('Purge attachment') or
79 $curuser->access_right('Undelete attachment')) {
88 if ($curuser->access_right('Delete attachment')) {
93 my $hashref = $disabled ?
94 { disabled => { op => '>', value => 0 } } :
97 my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ?
98 'disabled > 0' : 'disabled IS NULL');
100 my $orderby = $cgi->param('orderby') || 'custnum';
103 my $c = qsearchs('cust_main', { custnum => shift->custnum } );
104 return $c ? $c->name : '<FONT COLOR="red"><B>(not found)</B></FONT>';
108 time2str("%b %o, %Y", shift->_date);
112 my $size = shift->size;
113 return $size if $size < 1024;
114 return int($size/1024).'K' if $size < 1048576;
115 return int($size/1048576).'M';
118 my $sub_checkbox = sub {
119 return '' if $noactions;
121 my $attachnum = $attach->attachnum;
123 return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
126 my $sub_edit_link = sub {
128 my $attachnum = $attach->attachnum;
129 my $custnum = $attach->custnum;
130 return include('/elements/popup_link_onclick.html',
131 action => popurl(2).'edit/cust_main_attach.cgi?'.
132 "custnum=$custnum;attachnum=$attachnum",
133 actionlabel => 'Edit attachment properties',
143 my $param = $cgi->Vars;
144 my %old_param = %$param;
145 @{$param}{keys(%new_param)} = values(%new_param);
146 my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
147 %$param = %old_param;
153 my $onclick = "return(confirm('$action all selected files?'))";
154 return qq!onclick="$onclick"!;
158 return '' if ($noactions or !$areboxes);
160 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
161 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
163 if ($curuser->access_right('Undelete attachment')) {
164 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
166 if ($curuser->access_right('Purge attachment')) {
167 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
171 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
174 '<SCRIPT TYPE="text/javascript">
175 function setAll(setTo) {
176 theForm = document.attachForm;
177 for (i=0,n=theForm.elements.length;i<n;i++)
178 if (theForm.elements[i].name.indexOf("attachnum") != -1)
179 theForm.elements[i].checked = setTo;