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">!
15 'count_query' => $count_query,
16 'header' => [ selflink('#',orderby => 'attachnum'),
17 selflink('Customer',orderby => 'custnum'),
18 selflink('Date',orderby => '_date'),
19 selflink('Filename',orderby => 'filename'),
20 selflink('Size',orderby => 'length(body)'),
21 selflink('Uploaded by',orderby => 'otaker'),
22 selflink('Description',orderby => 'title'),
36 [ $p.'view/cust_main.cgi?', 'custnum' ],
53 'html_foot' => $sub_foot,
61 my $curuser = $FS::CurrentUser::CurrentUser;
62 die "access denied" if !$curuser->access_right('View attachments')
63 or !$curuser->access_right('Browse attachments');
65 my $conf = new FS::Conf;
72 if($cgi->param('show_deleted')) {
73 if ($curuser->access_right('View deleted attachments')) {
75 if ($curuser->access_right('Purge attachment') or
76 $curuser->access_right('Undelete attachment')) {
85 if ($curuser->access_right('Delete attachment')) {
90 my $orderby = $cgi->param('orderby') || 'custnum';
92 my ( $query, $count_query, ) = do {
93 my @agentnums = $curuser->agentnums;
95 table => 'cust_attachment',
97 => { disabled => $disabled ? { op => '>', value => 0 } : undef, },
98 order_by => "ORDER BY $orderby",
99 addl_from => 'JOIN cust_main USING (custnum)',
101 => 'AND agentnum IN (' . join( ',', @agentnums, 'NULL', ) . ')',
103 'SELECT COUNT(*) FROM cust_attachment'
104 . ' JOIN cust_main USING (custnum)'
105 . ' WHERE agentnum in (' . join( ',', @agentnums, 'NULL', ) . ')'
106 . ( $disabled ? 'and disabled > 0' : '' );
110 my $c = qsearchs('cust_main', { custnum => shift->custnum } );
111 return $c ? encode_entities($c->name) : '<FONT COLOR="red"><B>(not found)</B></FONT>';
115 time2str("%b %o, %Y", shift->_date);
119 my $size = shift->size;
120 return $size if $size < 1024;
121 return int($size/1024).'K' if $size < 1048576;
122 return int($size/1048576).'M';
125 my $sub_checkbox = sub {
126 return '' if $noactions;
128 my $attachnum = $attach->attachnum;
130 return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
133 my $sub_edit_link = sub {
135 my $attachnum = $attach->attachnum;
136 my $custnum = $attach->custnum;
137 return include('/elements/popup_link_onclick.html',
138 action => popurl(2).'edit/cust_main_attach.cgi?'.
139 "custnum=$custnum;attachnum=$attachnum",
140 actionlabel => 'Edit attachment properties',
150 my $param = $cgi->Vars;
151 my %old_param = %$param;
152 @{$param}{keys(%new_param)} = values(%new_param);
153 my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
154 %$param = %old_param;
160 my $onclick = "return(confirm('$action all selected files?'))";
161 return qq!onclick="$onclick"!;
165 return '' if ($noactions or !$areboxes);
167 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
168 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
170 if ($curuser->access_right('Undelete attachment')) {
171 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
173 if ($curuser->access_right('Purge attachment')) {
174 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
178 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
181 '<SCRIPT TYPE="text/javascript">
182 function setAll(setTo) {
183 theForm = document.attachForm;
184 for (i=0,n=theForm.elements.length;i<n;i++)
185 if (theForm.elements[i].name.indexOf("attachnum") != -1)
186 theForm.elements[i].checked = setTo;