From: mark Date: Wed, 18 Nov 2009 09:09:34 +0000 (+0000) Subject: cust_attachment improvement, RT#4964 and #6225 X-Git-Tag: root_of_svc_elec_features~675 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=fc195fd7a0a2ca670cfdd62ef646436b58795c21;p=freeside.git cust_attachment improvement, RT#4964 and #6225 --- diff --git a/httemplate/browse/cust_attachment.html b/httemplate/browse/cust_attachment.html new file mode 100755 index 000000000..0fdc745a2 --- /dev/null +++ b/httemplate/browse/cust_attachment.html @@ -0,0 +1,183 @@ +<% include( 'elements/browse.html', + 'title' => 'Attachments', + 'menubar' => '', + 'name' => ($disabled ? 'deleted' : '') .' attachments', + 'html_init' => include('/elements/init_overlib.html') . + ($curuser->access_right('View deleted attachments') ? ( + selflink('Show '.($disabled ? 'active' : 'deleted'), + show_deleted => (1-$disabled))) : ''), + 'html_form' => + qq!
+ + ! + , + 'query' => { 'table' => 'cust_attachment', + 'hashref' => $hashref, + 'extra_sql' => 'ORDER BY '.$orderby, + }, + 'count_query' => $count_query, + 'header' => [ selflink('#',orderby => 'attachnum'), + selflink('Customer',orderby => 'custnum'), + selflink('Date',orderby => '_date'), + selflink('Filename',orderby => 'filename'), + selflink('Size',orderby => 'length(body)'), + selflink('Uploaded by',orderby => 'otaker'), + selflink('Description',orderby => 'title'), + '', # checkbox column + ], + 'fields' => [ + 'attachnum', + $sub_cust, + $sub_date, + 'filename', + $sub_size, + 'otaker', + 'title', + $sub_checkbox, + ], + 'links' => [ '', + [ $p.'view/cust_main.cgi?', 'custnum' ], + ], + 'link_onclicks' => [ + '', + '', + '', + $sub_edit_link, + ], + + #'links' => [ + # '', + # '', + # '', + # '', + # '', + # '', #$acct_link, + # '', + 'html_foot' => $sub_foot, + ) + +%> + + +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +my $conf = new FS::Conf; + +my $noactions = 1; +my $areboxes = 0; + +my $disabled = 0; + +if($cgi->param('show_deleted')) { + if ($curuser->access_right('View deleted attachments')) { + $disabled = 1; + if ($curuser->access_right('Purge attachment') or + $curuser->access_right('Undelete attachment')) { + $noactions = 0; + } + } + else { + die "access denied"; + } +} +else { + if ($curuser->access_right('Delete attachment')) { + $noactions = 0; + } +} + +my $hashref = $disabled ? + { disabled => { op => '>', value => 0 } } : + { disabled => '' }; + +my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ? + 'disabled > 0' : 'disabled IS NULL'); + +my $orderby = $cgi->param('orderby') || 'custnum'; + +my $sub_cust = sub { + my $c = qsearchs('cust_main', { custnum => shift->custnum } ); + return $c ? $c->name : '(not found)'; +}; + +my $sub_date = sub { + time2str("%b %o, %Y", shift->_date); +}; + +my $sub_size = sub { + my $size = shift->size; + return $size if $size < 1024; + return int($size/1024).'K' if $size < 1048576; + return int($size/1048576).'M'; +}; + +my $sub_checkbox = sub { + return '' if $noactions; + my $attach = shift; + my $attachnum = $attach->attachnum; + $areboxes = 1; + return qq!!; +}; + +my $sub_edit_link = sub { + my $attach = shift; + my $attachnum = $attach->attachnum; + my $custnum = $attach->custnum; + return include('/elements/popup_link_onclick.html', + action => popurl(2).'edit/cust_main_attach.cgi?'. + "custnum=$custnum;attachnum=$attachnum", + actionlabel => 'Edit attachment properties', + width => 510, + height => 315, + frame => 'top', + ); +}; + +sub selflink { + my $label = shift; + my %new_param = @_; + my $param = $cgi->Vars; + my %old_param = %$param; + @{$param}{keys(%new_param)} = values(%new_param); + my $link = ''.$label.''; + %$param = %old_param; + return $link; +} + +sub confirm { + my $action = shift; + my $onclick = "return(confirm('$action all selected files?'))"; + return qq!onclick="$onclick"!; +} + +my $sub_foot = sub { + return '' if ($noactions or !$areboxes); + my $foot = +'
+'; + if ($disabled) { + if ($curuser->access_right('Undelete attachment')) { + $foot .= '
'; + } + if ($curuser->access_right('Purge attachment')) { + $foot .= '
'; + } + } + else { + $foot .= '
'; + } + $foot .= +''; + return $foot; +}; + + diff --git a/httemplate/misc/cust_attachment.cgi b/httemplate/misc/cust_attachment.cgi new file mode 100644 index 000000000..d1ec777d8 --- /dev/null +++ b/httemplate/misc/cust_attachment.cgi @@ -0,0 +1,34 @@ +<% '',$cgi->redirect(popurl(2). "browse/cust_attachment.html?$browse_opts") %> +<%init> + +$cgi->param('action') =~ /^(Delete|Undelete|Purge) selected$/ + or die "Illegal action"; +my $action = $1; + +my $browse_opts = join(';', map { $_.'='.$cgi->param($_) } + qw( orderby show_deleted ) + ); + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right("$action attachment"); + +foreach my $attachnum ( + map { /^attachnum(\d+)$/; $1; } grep /^attachnum\d+$/, $cgi->param + ) { + my $attach = qsearchs('cust_attachment', { 'attachnum' => $attachnum }); + my $error; + if ( $action eq 'Delete' and !$attach->disabled ) { + $attach->disabled(time); + $error = $attach->replace; + } + elsif ( $action eq 'Undelete' and $attach->disabled ) { + $attach->disabled(''); + $error = $attach->replace; + } + elsif ( $action eq 'Purge' and $attach->disabled ) { + $error = $attach->delete; + } + die $error if $error; +} + +