fix select and unselect all buttons on CDR bulk actions, RT#4766
[freeside.git] / httemplate / search / cdr.html
1 <% include( 'elements/search.html',
2                'title' => $title,
3                'name'  => 'call detail records',
4
5                'query' => { 'table'     => 'cdr',
6                             'hashref'   => $hashref,
7                             'extra_sql' => $qsearch,
8                             'order_by'  => 'ORDER BY calldate',
9                           },
10                'count_query' => $count_query,
11                'header' => [
12                              '', # checkbox column
13                              fields('cdr'), #XXX fill in some nice names
14                            ],
15                'fields' => [
16                              sub {
17                                return '' unless $edit_data;
18                                $areboxes = 1;
19                                my $cdr = shift;
20                                my $acctid = $cdr->acctid;
21                                qq!<INPUT NAME="acctid$acctid" TYPE="checkbox" VALUE="1">!;
22                              },
23                              fields('cdr'), #XXX fill in some pretty-print
24                                             #processing, etc.
25                            ],
26
27                'html_form'   => qq!<FORM NAME="cdrForm" ACTION="$p/misc/cdr.cgi" METHOD="POST">!,
28                #false laziness w/queue.html
29                'html_foot' => sub {
30                                 if ( $areboxes ) {
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;'.
41                                   '  }'.
42                                   '</SCRIPT>';
43                                 } else {
44                                   '';
45                                 }
46                               },
47
48              )
49 %>
50 <%init>
51
52 die "access denied"
53   unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
54
55 my $edit_data = $FS::CurrentUser::CurrentUser->access_right('Edit rating data');
56
57 my $areboxes = 0;
58
59 my $title = 'Call Detail Records';
60 my $hashref = {};
61
62 #process params for CDR search, populate $hashref...
63 # and fixup $count_query
64
65 my @search = ();
66
67 ###
68 # freesidestatus
69 ###
70
71 if ( $cgi->param('freesidestatus') eq 'NULL' ) {
72
73   my $title = "Unprocessed $title";
74   $hashref->{'freesidestatus'} = ''; # Record.pm will take care of it
75   push @search, "( freesidestatus IS NULL OR freesidestatus = '' )";
76
77 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
78
79   my $title = "Processed $title";
80   $hashref->{'freesidestatus'} = $1;
81   push @search, "freesidestatus = '$1'";
82
83 }
84
85 ###
86 # dates
87 ###
88
89 my $str2time_sql = str2time_sql;
90
91 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
92 push @search, "$str2time_sql calldate) >= $beginning ",
93               "$str2time_sql calldate) <= $ending";
94
95 ###
96 # duration / billsec
97 ###
98
99 push @search, FS::UI::Web::parse_lt_gt($cgi, 'duration');
100 push @search, FS::UI::Web::parse_lt_gt($cgi, 'billsec');
101
102 ###
103 # src/dest/charged_party
104 ###
105
106 my @qsearch = @search;
107
108 if ( $cgi->param('src') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
109   ( my $src = $1 ) =~ s/\D//g;
110   $hashref->{'src'} = $src;
111   push @search, "src = '$src'";
112 }
113
114 if ( $cgi->param('dst') =~ /^\s*([\d\-\+ ]+)\s*$/ ) {
115   ( my $dst = $1 ) =~ s/\D//g;
116   $hashref->{'dst'} = $dst;
117   push @search, "dst = '$dst'";
118 }
119
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'";
124   #XXX countrycode
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' ) ";
129 }
130
131 ###
132 # cdrbatch
133 ###
134
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;
140   } else {
141     $hashref->{cdrbatch} = $cgi->param('cdrbatch');
142     push @search, 'cdrbatch = '. dbh->quote($cgi->param('cdrbatch'));
143   }
144 }
145
146 ###
147 # finish it up
148 ###
149
150 my $search = join(' AND ', @search);
151 $search = "WHERE $search" if $search;
152
153 my $count_query = "SELECT COUNT(*) FROM cdr $search";
154
155 my $qsearch = join(' AND ', @qsearch);
156 $qsearch = ( scalar(keys %$hashref) ? ' AND ' : ' WHERE ' ) . $qsearch
157   if $qsearch;
158
159 </%init>