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';
93 table => 'cust_attachment',
94 hashref => { disabled => $disabled ? { op => '>', value => 0 } : '', },
95 order_by => "ORDER BY $orderby",
96 addl_from => 'JOIN cust_main USING (custnum)',
97 extra_sql => ' AND ' . $curuser->agentnums_sql,
100 my $count_query = 'SELECT COUNT(*) FROM cust_attachment'
101 . ' JOIN cust_main USING (custnum)'
102 . ' WHERE ' . $curuser->agentnums_sql
103 . ' AND disabled ' . ( $disabled ? '> 0' : 'IS NULL' );
106 my $c = qsearchs('cust_main', { custnum => shift->custnum } );
107 return $c ? encode_entities($c->name) : '<FONT COLOR="red"><B>(not found)</B></FONT>';
111 time2str("%b %o, %Y", shift->_date);
115 my $size = shift->size;
116 return $size if $size < 1024;
117 return int($size/1024).'K' if $size < 1048576;
118 return int($size/1048576).'M';
121 my $sub_checkbox = sub {
122 return '' if $noactions;
124 my $attachnum = $attach->attachnum;
126 return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
129 my $sub_edit_link = sub {
131 my $attachnum = $attach->attachnum;
132 my $custnum = $attach->custnum;
133 return include('/elements/popup_link_onclick.html',
134 action => popurl(2).'edit/cust_main_attach.cgi?'.
135 "custnum=$custnum;attachnum=$attachnum",
136 actionlabel => 'Edit attachment properties',
146 my $param = $cgi->Vars;
147 my %old_param = %$param;
148 @{$param}{keys(%new_param)} = values(%new_param);
149 my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
150 %$param = %old_param;
156 my $onclick = "return(confirm('$action all selected files?'))";
157 return qq!onclick="$onclick"!;
161 return '' if ($noactions or !$areboxes);
163 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
164 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
166 if ($curuser->access_right('Undelete attachment')) {
167 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
169 if ($curuser->access_right('Purge attachment')) {
170 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
174 $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
177 '<SCRIPT TYPE="text/javascript">
178 function setAll(setTo) {
179 theForm = document.attachForm;
180 for (i=0,n=theForm.elements.length;i<n;i++)
181 if (theForm.elements[i].name.indexOf("attachnum") != -1)
182 theForm.elements[i].checked = setTo;