quick n' dirty CDR deletion from web interface, RT#4766 / RT#4731
authorivan <ivan>
Tue, 10 Feb 2009 10:35:13 +0000 (10:35 +0000)
committerivan <ivan>
Tue, 10 Feb 2009 10:35:13 +0000 (10:35 +0000)
FS/FS/AccessRight.pm
httemplate/misc/cdr.cgi [new file with mode: 0644]
httemplate/search/cdr.html

index bf076f6..fe10572 100644 (file)
@@ -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 (file)
index 0000000..d2ee773
--- /dev/null
@@ -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;
+    }
+  }
+}
+
+</%init>
index 0fa64c0..bef4921 100644 (file)
@@ -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!<INPUT NAME="acctid$acctid" TYPE="checkbox" VALUE="1">!;
+                             },
+                             fields('cdr'), #XXX fill in some pretty-print
+                                            #processing, etc.
+                           ],
+
+               'html_form'   => qq!<FORM NAME="cdrForm" ACTION="$p/misc/cdr.cgi" METHOD="POST">!,
+               #false laziness w/queue.html
+               'html_foot' => sub {
+                                if ( $areboxes ) {
+                                  '<BR><INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">'.
+                                  '<INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">'.
+                                  qq!<BR><INPUT TYPE="submit" NAME="action" VALUE="reprocess selected" onClick="return confirm('Are you sure you want to reprocess the selected CDRs?')">!.
+                                  qq!<INPUT TYPE="submit" NAME="action" VALUE="delete selected" onClick="return confirm('Are you sure you want to delete the selected CDRs?')"><BR>!.
+                                  '<SCRIPT TYPE="text/javascript">'.
+                                  '  function setAll(setTo) { '.
+                                  '    theForm = document.cdrForm;'.
+                                  '    for (i=0,n=theForm.elements.length;i<n;i++)'.
+                                  '      if (theForm.elements[i].name.indexOf("jobnum") != -1)'.
+                                  '        theForm.elements[i].checked = setTo;'.
+                                  '  }'.
+                                  '</SCRIPT>';
+                                } else {
+                                  '';
+                                }
+                              },
+
              )
 %>
 <%init>
 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 = {};