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,
13 fields('cdr'), #XXX fill in some nice names
17 return '' unless $edit_data;
20 my $acctid = $cdr->acctid;
21 qq!<INPUT NAME="acctid$acctid" TYPE="checkbox" VALUE="1">!;
23 fields('cdr'), #XXX fill in some pretty-print
27 'html_form' => qq!<FORM NAME="cdrForm" ACTION="$p/misc/cdr.cgi" METHOD="POST">!,
28 #false laziness w/queue.html
31 '<BR><INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">'.
32 '<INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">'.
33 qq!<BR><INPUT TYPE="submit" NAME="action" VALUE="reprocess selected" onClick="return confirm('Are you sure you want to reprocess the selected CDRs?')">!.
34 qq!<INPUT TYPE="submit" NAME="action" VALUE="delete selected" onClick="return confirm('Are you sure you want to delete the selected CDRs?')"><BR>!.
35 '<SCRIPT TYPE="text/javascript">'.
36 ' function setAll(setTo) { '.
37 ' theForm = document.cdrForm;'.
38 ' for (i=0,n=theForm.elements.length;i<n;i++)'.
39 ' if (theForm.elements[i].name.indexOf("acctid") != -1)'.
40 ' theForm.elements[i].checked = setTo;'.
53 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
55 my $edit_data = $FS::CurrentUser::CurrentUser->access_right('Edit rating data');
59 my $title = 'Call Detail Records';
62 #process params for CDR search, populate $hashref...
63 # and fixup $count_query
71 if ( $cgi->param('freesidestatus') eq 'NULL' ) {
73 my $title = "Unprocessed $title";
74 $hashref->{'freesidestatus'} = ''; # Record.pm will take care of it
75 push @search, "( freesidestatus IS NULL OR freesidestatus = '' )";
77 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
79 my $title = "Processed $title";
80 $hashref->{'freesidestatus'} = $1;
81 push @search, "freesidestatus = '$1'";
89 my $str2time_sql = str2time_sql;
91 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
92 push @search, "$str2time_sql calldate) >= $beginning ",
93 "$str2time_sql calldate) <= $ending";
99 push @search, FS::UI::Web::parse_lt_gt($cgi, 'duration');
100 push @search, FS::UI::Web::parse_lt_gt($cgi, 'billsec');
103 # src/dest/charged_party
106 my @qsearch = @search;
108 if ( $cgi->param('src') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
109 ( my $src = $1 ) =~ s/\D//g;
110 $hashref->{'src'} = $src;
111 push @search, "src = '$src'";
114 if ( $cgi->param('dst') =~ /^\s*([\d\-\+ ]+)\s*$/ ) {
115 ( my $dst = $1 ) =~ s/\D//g;
116 $hashref->{'dst'} = $dst;
117 push @search, "dst = '$dst'";
120 if ( $cgi->param('charged_party') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
121 ( my $charged_party = $1 ) =~ s/\D//g;
122 #$hashref->{'charged_party'} = $charged_party;
123 #push @search, "charged_party = '$charged_party'";
125 push @search, " ( charged_party = '$charged_party'
126 OR charged_party = '1$charged_party' ) ";
127 push @qsearch, " ( charged_party = '$charged_party'
128 OR charged_party = '1$charged_party' ) ";
135 if ( $cgi->param('cdrbatch') ne '__ALL__' ) {
136 if ( $cgi->param('cdrbatch') eq '' ) {
137 my $search = "( cdrbatch IS NULL OR cdrbatch = '' )";
138 push @qsearch, $search;
139 push @search, $search;
141 $hashref->{cdrbatch} = $cgi->param('cdrbatch');
142 push @search, 'cdrbatch = '. dbh->quote($cgi->param('cdrbatch'));
150 my $search = join(' AND ', @search);
151 $search = "WHERE $search" if $search;
153 my $count_query = "SELECT COUNT(*) FROM cdr $search";
155 my $qsearch = join(' AND ', @qsearch);
156 $qsearch = ( scalar(keys %$hashref) ? ' AND ' : ' WHERE ' ) . $qsearch