@fields, #XXX fill in some pretty-print
#processing, etc.
],
+ 'links' => \@links,
'html_form' => qq!<FORM NAME="cdrForm" ACTION="$p/misc/cdr.cgi" METHOD="POST">!,
#false laziness w/queue.html
###
my $str2time_sql = str2time_sql;
+my $closing = str2time_sql_closing;
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
-push @search, "$str2time_sql calldate) >= $beginning ",
- "$str2time_sql calldate) <= $ending";
+push @search, "$str2time_sql calldate $closing >= $beginning ",
+ "$str2time_sql calldate $closing <= $ending";
###
# duration / billsec
push @search, "dst = '$dst'";
}
+if ( $cgi->param('dcontext') =~ /^\s*(.+)\s*$/ ) {
+ my $dcontext = $1;
+ $hashref->{'dcontext'} = $dcontext;
+ push @search, "dcontext = '$dcontext'";
+}
+
if ( $cgi->param('charged_party') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
( my $charged_party = $1 ) =~ s/\D//g;
#$hashref->{'charged_party'} = $charged_party;
}
###
-# cdrbatch
+# cdrbatchnum (or legacy cdrbatch)
###
-if ( $cgi->param('cdrbatch') ne '__ALL__' ) {
- if ( $cgi->param('cdrbatch') eq '' ) {
- my $search = "( cdrbatch IS NULL OR cdrbatch = '' )";
+if ( $cgi->param('cdrbatch') ) {
+
+ my $cdr_batch =
+ qsearchs('cdr_batch', { 'cdrbatch' => scalar($cgi->param('cdrbatch')) } );
+ if ( $cdr_batch ) {
+ $hashref->{cdrbatchnum} = $cdr_batch->cdrbatchnum;
+ push @search, 'cdrbatchnum = '. $cdr_batch->cdrbatchnum;
+ } else {
+ die "unknown cdrbatch ". $cgi->param('cdrbatch');
+ }
+
+} elsif ( $cgi->param('cdrbatchnum') ne '__ALL__' ) {
+
+ if ( $cgi->param('cdrbatchnum') eq '' ) {
+ my $search = "( cdrbatchnum IS NULL )";
+ push @qsearch, $search;
+ push @search, $search;
+ } elsif ( $cgi->param('cdrbatchnum') =~ /^(\d+)$/ ) {
+ $hashref->{cdrbatchnum} = $1;
+ push @search, "cdrbatchnum = $1";
+ }
+
+}
+
+###
+# acctid
+###
+
+if ( $cgi->param('acctid') =~ /\d/ ) {
+ my $acctid = $cgi->param('acctid');
+ $acctid =~ s/\r\n/\n/g; #browsers?
+ my @acctid = map { /^\s*(\d+)\s*$/ or die "guru meditation #4"; $1; }
+ grep { /^\s*(\d+)\s*$/ }
+ split(/\n/, $acctid);
+ if ( @acctid ) {
+ my $search = 'acctid IN ( '. join(',', @acctid). ' )';
push @qsearch, $search;
push @search, $search;
- } else {
- $hashref->{cdrbatch} = $cgi->param('cdrbatch');
- push @search, 'cdrbatch = '. dbh->quote($cgi->param('cdrbatch'));
}
}
# display fields
###
-#XXX fill in some (more) nice names
-my %header = (
- 'calldate' => 'Call Date',
- 'clid' => 'Caller ID',
- 'charged_party' => 'Charged party',
- 'src' => 'Source',
- 'dst' => 'Destination',
- 'dcontext' => 'Destination Context',
- 'channel' => 'Channel',
- 'dstchannel' => 'Destination Channel',
- 'freesidestatus' => 'Freeside status',
-);
+my %header = %{ FS::cdr->table_info->{'fields'} };
my @first = qw( acctid calldate clid charged_party src dst dcontext );
my %first = map { $_=>1 } @first;
my @fields = ( @first, grep !$first{$_}, fields('cdr') );
+if ( $cgi->param('show') ) {
+ @fields = grep $cgi->param("show_$_"), @fields;
+}
+
my @header = map {
if ( exists($header{$_}) ) {
$header{$_};
} else {
my $header = $_;
- $header =~ s/\_/ /g;
+ $header =~ s/\_/ /g; #//wtf
ucfirst($header);
}
} @fields;
+my $date_sub_factory = sub {
+ my $column = shift;
+ sub {
+ #my $cdr = shift;
+ my $date = shift->$column();
+ $date ? time2str( '%Y-%m-%d %T', $date ) : ''; #config time2str format?
+ };
+};
+
+my %fields = (
+ #any other formatters?
+ map { $_ => &{ $date_sub_factory }($_) } qw( startdate answerdate enddate )
+);
+
+my %links = (
+ 'svcnum' =>
+ sub { $_[0]->svcnum ? [ $p.'view/svc_phone.cgi?', 'svcnum' ] : ''; },
+);
+
+@fields = map { exists($fields{$_}) ? $fields{$_} : $_ } @fields;
+
+ #checkbox column
+my @links = ( '', map { exists($links{$_}) ? $links{$_} : '' } @fields );
+
</%init>