From ab85518b116ffe93751adbd05ae1412b8a8b2a2e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 10 Feb 2009 10:35:13 +0000 Subject: [PATCH] quick n' dirty CDR deletion from web interface, RT#4766 / RT#4731 --- FS/FS/AccessRight.pm | 1 + httemplate/misc/cdr.cgi | 48 ++++++++++++++++++++++++++++++++++++++++++++++ httemplate/search/cdr.html | 45 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 httemplate/misc/cdr.cgi diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index bf076f649..fe10572ca 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -221,6 +221,7 @@ tie my %rights, 'Tie::IxHash', { rightname=>'Reprocess batches', global=>1 }, { rightname=>'Import', global=>1 }, #some of these are ag-virt'ed now? give em their own ACLs { rightname=>'Export', global=>1 }, + { rightname=> 'Edit rating data', desc=>'Delete CDRs', global=>1 }, #], # ### diff --git a/httemplate/misc/cdr.cgi b/httemplate/misc/cdr.cgi new file mode 100644 index 000000000..d2ee77364 --- /dev/null +++ b/httemplate/misc/cdr.cgi @@ -0,0 +1,48 @@ +%# <% $cgi->redirect(popurl(2). "search/cdr.html") %> +%# i should be a popup and reload my parent... until then, this will do +<% include('/elements/header.html','CDR update successful') %> +<% include('/elements/footer.html') %> +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Edit rating data'); + +$cgi->param('action') =~ /^(new|del|(reprocess|delete) selected)$/ + or die "Illegal action"; +my $action = $1; + +my $cdr; +if ( $action eq 'new' || $action eq 'del' ) { + $cgi->param('acctid') =~ /^(\d+)$/ or die "Illegal acctid"; + my $acctid = $1; + $cdr = qsearchs('cdr', { 'acctid' => $1 }) + or die "unknown acctid $acctid"; +} + +if ( $action eq 'new' ) { + my %hash = $cdr->hash; + $hash{'freesidestatus'} = ''; + my $new = new FS::cdr \%hash; + my $error = $new->replace($cdr); + die $error if $error; +} elsif ( $action eq 'del' ) { + my $error = $cdr->delete; + die $error if $error; +} elsif ( $action =~ /^(reprocess|delete) selected$/ ) { + foreach my $acctid ( + map { /^acctid(\d+)$/; $1; } grep /^acctid\d+$/, $cgi->param + ) { + my $cdr = qsearchs('cdr', { 'acctid' => $acctid }); + if ( $action eq 'reprocess selected' && $cdr ) { #new + my %hash = $cdr->hash; + $hash{'freesidestatus'} = ''; + my $new = new FS::cdr \%hash; + my $error = $new->replace($cdr); + die $error if $error; + } elsif ( $action eq 'delete selected' && $cdr ) { #del + my $error = $cdr->delete; + die $error if $error; + } + } +} + + diff --git a/httemplate/search/cdr.html b/httemplate/search/cdr.html index 0fa64c00c..bef49219f 100644 --- a/httemplate/search/cdr.html +++ b/httemplate/search/cdr.html @@ -1,15 +1,50 @@ <% include( 'elements/search.html', 'title' => $title, 'name' => 'call detail records', + 'query' => { 'table' => 'cdr', 'hashref' => $hashref, 'extra_sql' => $qsearch, 'order_by' => 'ORDER BY calldate', }, 'count_query' => $count_query, - 'header' => [ fields('cdr') ], #XXX fill in some nice names - 'fields' => [ fields('cdr') ], #XXX fill in some pretty-print - # processing, etc. + 'header' => [ + '', # checkbox column + fields('cdr'), #XXX fill in some nice names + ], + 'fields' => [ + sub { + return '' unless $edit_data; + $areboxes = 1; + my $cdr = shift; + my $acctid = $cdr->acctid; + qq!!; + }, + fields('cdr'), #XXX fill in some pretty-print + #processing, etc. + ], + + 'html_form' => qq!
!, + #false laziness w/queue.html + 'html_foot' => sub { + if ( $areboxes ) { + '
'. + ''. + qq!
!. + qq!
!. + ''; + } else { + ''; + } + }, + ) %> <%init> @@ -17,6 +52,10 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('List rating data'); +my $edit_data = $FS::CurrentUser::CurrentUser->access_right('Edit rating data'); + +my $areboxes = 0; + my $title = 'Call Detail Records'; my $hashref = {}; -- 2.11.0