1 <% include( 'elements/search.html',
3 'name' => 'call detail records',
5 'query' => { 'table' => 'cdr',
7 'extra_sql' => $qsearch,
8 'order_by' => 'ORDER BY calldate',
10 'count_query' => $count_query,
17 return '' unless $edit_data;
20 my $acctid = $cdr->acctid;
21 qq!<INPUT NAME="acctid$acctid" TYPE="checkbox" VALUE="1">!;
23 @fields, #XXX fill in some pretty-print
28 'html_form' => qq!<FORM NAME="cdrForm" ACTION="$p/misc/cdr.cgi" METHOD="POST">!,
29 #false laziness w/queue.html
32 '<BR><INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">'.
33 '<INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">'.
34 qq!<BR><INPUT TYPE="submit" NAME="action" VALUE="reprocess selected" onClick="return confirm('Are you sure you want to reprocess the selected CDRs?')">!.
35 qq!<INPUT TYPE="submit" NAME="action" VALUE="delete selected" onClick="return confirm('Are you sure you want to delete the selected CDRs?')"><BR>!.
36 '<SCRIPT TYPE="text/javascript">'.
37 ' function setAll(setTo) { '.
38 ' theForm = document.cdrForm;'.
39 ' for (i=0,n=theForm.elements.length;i<n;i++)'.
40 ' if (theForm.elements[i].name.indexOf("acctid") != -1)'.
41 ' theForm.elements[i].checked = setTo;'.
54 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
56 my $edit_data = $FS::CurrentUser::CurrentUser->access_right('Edit rating data');
60 my $title = 'Call Detail Records';
63 #process params for CDR search, populate $hashref...
64 # and fixup $count_query
72 my $str2time_sql = str2time_sql;
74 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
75 push @search, "$str2time_sql calldate) >= $beginning ",
76 "$str2time_sql calldate) <= $ending";
82 push @search, FS::UI::Web::parse_lt_gt($cgi, 'duration');
83 push @search, FS::UI::Web::parse_lt_gt($cgi, 'billsec');
85 #above here things just push @search
86 #below here things also have to define $hashref->{} or push @qsearch
87 my @qsearch = @search;
93 if ( $cgi->param('freesidestatus') eq 'NULL' ) {
95 $title = "Unprocessed $title";
96 $hashref->{'freesidestatus'} = ''; # Record.pm will take care of it
97 push @search, "( freesidestatus IS NULL OR freesidestatus = '' )";
99 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
101 $title = "Processed $title";
102 $hashref->{'freesidestatus'} = $1;
103 push @search, "freesidestatus = '$1'";
111 foreach my $param ( grep /^termpart\d+status$/, $cgi->param ) {
113 my $status = $cgi->param($param);
115 $param =~ /^termpart(\d+)status$/ or die 'guru meditation 54something';
119 if ( $status eq 'NULL' ) {
121 #false lazienss w/cdr_termination.pm (i should be a part_termination method)
123 "( cdr.acctid = cdr_termination.acctid AND termpart = $termpart ) ";
124 #my $join_term = "LEFT JOIN cdr_termination ON ( $where_term )";
126 "NOT EXISTS ( SELECT 1 FROM cdr_termination WHERE $where_term )";
128 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
130 #false lazienss w/cdr_termination.pm (i should be a part_termination method)
132 "( cdr.acctid = cdr_termination.acctid AND termpart = $termpart AND status = '$1' ) ";
133 #my $join_term = "LEFT JOIN cdr_termination ON ( $where_term )";
135 "EXISTS ( SELECT 1 FROM cdr_termination WHERE $where_term )";
140 push @search, $search;
141 push @qsearch, $search;
147 # src/dest/charged_party
150 if ( $cgi->param('src') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
151 ( my $src = $1 ) =~ s/\D//g;
152 $hashref->{'src'} = $src;
153 push @search, "src = '$src'";
156 if ( $cgi->param('dst') =~ /^\s*([\d\-\+ ]+)\s*$/ ) {
157 ( my $dst = $1 ) =~ s/\D//g;
158 $hashref->{'dst'} = $dst;
159 push @search, "dst = '$dst'";
162 if ( $cgi->param('dcontext') =~ /^\s*(.+)\s*$/ ) {
164 $hashref->{'dcontext'} = $dcontext;
165 push @search, "dcontext = '$dcontext'";
168 if ( $cgi->param('charged_party') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
169 ( my $charged_party = $1 ) =~ s/\D//g;
170 #$hashref->{'charged_party'} = $charged_party;
171 #push @search, "charged_party = '$charged_party'";
174 my $search = " ( charged_party = '$charged_party'
175 OR charged_party = '1$charged_party' ) ";
177 push @search, $search;
178 push @qsearch, $search;
182 # cdrbatchnum (or legacy cdrbatch)
185 if ( $cgi->param('cdrbatch') ) {
188 qsearchs('cdr_batch', { 'cdrbatch' => scalar($cgi->param('cdrbatch')) } );
190 push @search, 'cdrbatchnum = '. $cdr_batch->cdrbatchnum;
192 die "unknown cdrbatch ". $cgi->param('cdrbatch');
195 } elsif ( $cgi->param('cdrbatchnum') ne '__ALL__' ) {
197 if ( $cgi->param('cdrbatchnum') eq '' ) {
198 my $search = "( cdrbatchnum IS NULL )";
199 push @qsearch, $search;
200 push @search, $search;
201 } elsif ( $cgi->param('cdrbatchnum') =~ /^(\d+)$/ ) {
202 $hashref->{cdrbatchnum} = $1;
203 push @search, "cdrbatchnum = $1";
212 if ( $cgi->param('acctid') =~ /\d/ ) {
213 my $acctid = $cgi->param('acctid');
214 $acctid =~ s/\r\n/\n/g; #browsers?
215 my @acctid = map { /^\s*(\d+)\s*$/ or die "guru meditation #4"; $1; }
216 grep { /^\s*(\d+)\s*$/ }
217 split(/\n/, $acctid);
219 my $search = 'acctid IN ( '. join(',', @acctid). ' )';
220 push @qsearch, $search;
221 push @search, $search;
229 my $search = join(' AND ', @search);
230 $search = "WHERE $search" if $search;
232 my $count_query = "SELECT COUNT(*) FROM cdr $search";
234 my $qsearch = join(' AND ', @qsearch);
235 $qsearch = ( scalar(keys %$hashref) ? ' AND ' : ' WHERE ' ) . $qsearch
242 my %header = %{ FS::cdr->table_info->{'fields'} };
244 my @first = qw( acctid calldate clid charged_party src dst dcontext );
245 my %first = map { $_=>1 } @first;
247 my @fields = ( @first, grep !$first{$_}, fields('cdr') );
249 if ( $cgi->param('show') ) {
250 @fields = grep $cgi->param("show_$_"), @fields;
254 if ( exists($header{$_}) ) {
258 $header =~ s/\_/ /g; #//wtf
263 my $date_sub_factory = sub {
267 my $date = shift->$column();
268 $date ? time2str( '%Y-%m-%d %T', $date ) : ''; #config time2str format?
273 #any other formatters?
274 map { $_ => &{ $date_sub_factory }($_) } qw( startdate answerdate enddate )
279 sub { $_[0]->svcnum ? [ $p.'view/svc_phone.cgi?', 'svcnum' ] : ''; },
282 @fields = map { exists($fields{$_}) ? $fields{$_} : $_ } @fields;
285 my @links = ( '', map { exists($links{$_}) ? $links{$_} : '' } @fields );