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
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 my $str2time_sql = str2time_sql;
73 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
74 push @search, "$str2time_sql calldate) >= $beginning ",
75 "$str2time_sql calldate) <= $ending";
81 push @search, FS::UI::Web::parse_lt_gt($cgi, 'duration');
82 push @search, FS::UI::Web::parse_lt_gt($cgi, 'billsec');
84 #above here things just push @search
85 #below here things also have to define $hashref->{} or push @qsearch
86 my @qsearch = @search;
92 if ( $cgi->param('freesidestatus') eq 'NULL' ) {
94 $title = "Unprocessed $title";
95 $hashref->{'freesidestatus'} = ''; # Record.pm will take care of it
96 push @search, "( freesidestatus IS NULL OR freesidestatus = '' )";
98 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
100 $title = "Processed $title";
101 $hashref->{'freesidestatus'} = $1;
102 push @search, "freesidestatus = '$1'";
110 foreach my $param ( grep /^termpart\d+status$/, $cgi->param ) {
112 my $status = $cgi->param($param);
114 $param =~ /^termpart(\d+)status$/ or die 'guru meditation 54something';
118 if ( $status eq 'NULL' ) {
120 #false lazienss w/cdr_termination.pm (i should be a part_termination method)
122 "( cdr.acctid = cdr_termination.acctid AND termpart = $termpart ) ";
123 #my $join_term = "LEFT JOIN cdr_termination ON ( $where_term )";
125 "NOT EXISTS ( SELECT 1 FROM cdr_termination WHERE $where_term )";
127 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
129 #false lazienss w/cdr_termination.pm (i should be a part_termination method)
131 "( cdr.acctid = cdr_termination.acctid AND termpart = $termpart AND status = '$1' ) ";
132 #my $join_term = "LEFT JOIN cdr_termination ON ( $where_term )";
134 "EXISTS ( SELECT 1 FROM cdr_termination WHERE $where_term )";
139 push @search, $search;
140 push @qsearch, $search;
146 # src/dest/charged_party
149 if ( $cgi->param('src') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
150 ( my $src = $1 ) =~ s/\D//g;
151 $hashref->{'src'} = $src;
152 push @search, "src = '$src'";
155 if ( $cgi->param('dst') =~ /^\s*([\d\-\+ ]+)\s*$/ ) {
156 ( my $dst = $1 ) =~ s/\D//g;
157 $hashref->{'dst'} = $dst;
158 push @search, "dst = '$dst'";
161 if ( $cgi->param('dcontext') =~ /^\s*(.+)\s*$/ ) {
163 $hashref->{'dcontext'} = $dcontext;
164 push @search, "dcontext = '$dcontext'";
167 if ( $cgi->param('charged_party') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
168 ( my $charged_party = $1 ) =~ s/\D//g;
169 #$hashref->{'charged_party'} = $charged_party;
170 #push @search, "charged_party = '$charged_party'";
173 my $search = " ( charged_party = '$charged_party'
174 OR charged_party = '1$charged_party' ) ";
176 push @search, $search;
177 push @qsearch, $search;
184 if ( $cgi->param('cdrbatch') ne '__ALL__' ) {
185 if ( $cgi->param('cdrbatch') eq '' ) {
186 my $search = "( cdrbatch IS NULL OR cdrbatch = '' )";
187 push @qsearch, $search;
188 push @search, $search;
190 $hashref->{cdrbatch} = $cgi->param('cdrbatch');
191 push @search, 'cdrbatch = '. dbh->quote($cgi->param('cdrbatch'));
199 my $search = join(' AND ', @search);
200 $search = "WHERE $search" if $search;
202 my $count_query = "SELECT COUNT(*) FROM cdr $search";
204 my $qsearch = join(' AND ', @qsearch);
205 $qsearch = ( scalar(keys %$hashref) ? ' AND ' : ' WHERE ' ) . $qsearch
212 my %header = %{ FS::cdr->table_info->{'fields'} };
214 my @first = qw( acctid calldate clid charged_party src dst dcontext );
215 my %first = map { $_=>1 } @first;
217 my @fields = ( @first, grep !$first{$_}, fields('cdr') );
219 if ( $cgi->param('show') ) {
220 @fields = grep $cgi->param("show_$_"), @fields;
224 if ( exists($header{$_}) ) {