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');
67 my $conf = new FS::Conf;
74 if($cgi->param('show_deleted')) {
75 if ($curuser->access_right('View deleted attachments')) {
77 if ($curuser->access_right('Purge attachment') or
78 $curuser->access_right('Undelete attachment')) {
87 if ($curuser->access_right('Delete attachment')) {
92 my $hashref = $disabled ?
93 { disabled => { op => '>', value => 0 } } :
96 my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ?
97 'disabled > 0' : 'disabled IS NULL');
99 my $orderby = $cgi->param('orderby') || 'custnum';
102 my $c = qsearchs('cust_main', { custnum => shift->custnum } );
103 return $c ? $c->name : '<FONT COLOR="red"><B>(not found)</B></FONT>';
107 time2str("%b %o, %Y", shift->_date);
111 my $size = shift->size;
112 return $size if $size < 1024;
113 return int($size/1024).'K' if $size < 1048576;
114 return int($size/1048576).'M';
117 my $sub_checkbox = sub {
118 return '' if $noactions;
120 my $attachnum = $attach->attachnum;
122 return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
125 my $sub_edit_link = sub {
127 my $attachnum = $attach->attachnum;
128 my $custnum = $attach->custnum;
129 return include('/elements/popup_link_onclick.html',
130 action => popurl(2).'edit/cust_main_attach.cgi?'.
131 "custnum=$custnum;attachnum=$attachnum",
132 actionlabel => 'Edit attachment properties',
142 my $param = $cgi->Vars;
143 my %old_param = %$param;
144 @{$param}{keys(%new_param)} = values(%new_param);
145 my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
146 %$param = %old_param;
152 my $onclick = "return(confirm('$action all selected files?'))";
153 return qq!onclick="$onclick"!;
157 return '' if ($noactions or !$areboxes);
159 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
160 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
162 if ($curuser->access_right('Undelete attachment')) {
163 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
165 if ($curuser->access_right('Purge attachment')) {
166 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
170 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
173 '<SCRIPT TYPE="text/javascript">
174 function setAll(setTo) {
175 theForm = document.attachForm;
176 for (i=0,n=theForm.elements.length;i<n;i++)
177 if (theForm.elements[i].name.indexOf("attachnum") != -1)
178 theForm.elements[i].checked = setTo;