+if ( $cgi->param('top_dst') =~ /^(\d+)$/ && $cgi->param('top_dst') > 0 ) {
+ $topmode = $1;
+ @fields = ('dst');
+ @header = ('Destination');
+}
+elsif ( $cgi->param('top_src') =~ /^(\d+)$/ && $cgi->param('top_src') > 0 ) {
+ $topmode = $1;
+ @fields = ('src');
+ @header = ('Source');
+}
+
+if ( $topmode ) {
+ my $whichfield = $fields[0];
+ $query = { 'select' => "$whichfield, count(1) as cnt",
+ 'table' => 'cdr',
+ 'hashref' => {},
+ 'extra_sql' => "$search
+ group by $whichfield
+ order by cnt desc",
+ };
+ $count_query = "SELECT $topmode";
+
+ # this is weird, maybe we should change search.html
+ $cgi->param('maxrecords',$topmode);
+
+ # kind of hacked
+ my $link = "${p}search/cdr.html?".$cgi->query_string;
+ $link =~ s/;top_(dst|src)=(\d+|)//g;
+ $link =~ s/;maxrecords=(\d+|)//;
+ $link =~ s/;(src|dst)=(\d+|)//g;
+ $link = [ "$link;$whichfield=", sub { shift->$whichfield } ];
+ @links = ($link);
+
+ push @fields, 'cnt';
+ push @header, '# Calls';
+
+ $nototalminutes = 1;
+}
+
+my $html_foot = include('/search/elements/checkbox-foot.html',
+ actions => [
+ { submit => "reprocess selected",
+ name => "action",
+ confirm => "Are you sure you want to reprocess the selected CDRs?" },
+ { submit => "delete selected",
+ name => "action",
+ confirm => "Are you sure you want to delete the selected CDRs?" },
+ ]
+);