+ print $txt_fh "\n" if $txt_fh;
+ if ($htm_fh) {
+ print $htm_fh "</table>\n";
+ print $htm_fh "</td><td>\n";
+ if ($HAVE_GD_Graph_pie && $charts && ($#chartdatavals > 0))
+ {
+ # calculate the graph
+ my @data = (
+ \@chartdatanames,
+ \@chartdatavals
+ );
+ my $graph = GD::Graph::pie->new(300, 300);
+ $graph->set(
+ x_label => 'Name',
+ y_label => 'Amount',
+ title => 'By count',
+ );
+ my $gd = $graph->plot(\@data) or warn($graph->error);
+ if ($gd) {
+ my $temp = $text;
+ $temp =~ s/ /_/g;
+ open(IMG, ">$chartdir/${temp}_count.png") or die "Could not write $chartdir/${temp}_count.png: $!\n";
+ binmode IMG;
+ print IMG $gd->png;
+ close IMG;
+ print $htm_fh "<img src=\"$chartrel/${temp}_count.png\">";
+ }
+ }
+ print $htm_fh "</td><td>\n";
+ print $htm_fh "</td></tr></table>\n\n";
+ }
+ ++${$row_sref} if $xls_fh;
+
+
+ if (defined $m_data) {
+ # write header
+
+ $title = "Top $name by volume";
+
+ printf $txt_fh ("%s\n%s\n%s", $title, "-" x length($title),$txt_col_headers) if $txt_fh;
+
+ if ($htm_fh) {
+ print $htm_fh <<EoText;
+<hr><a name="$text volume"></a><h2>$title</h2>
+<table border=0 width="100%">
+<tr><td>
+<table border=1>
+EoText
+ print $htm_col_headers;
+ }
+ if ($xls_fh) {
+ $spreadsheet->write(${$row_sref}++, 0, $title, $f_header2);
+ $spreadsheet->write(${$row_sref}++, 0, [@headers, $text], $f_headertab);
+ }
+
+ @chartdatanames = ();
+ @chartdatavals = ();
+ $chartotherval = 0;
+ my $use_gig = 0;
+ foreach my $key (top_n_sort($topcount,$m_data_gigs,$m_data,$m_count)) {
+ # The largest volume will be the first (top of the list).
+ # If it has at least 1 gig, then just use gigabytes to avoid
+ # risking an integer overflow when generating the pie charts.
+ if ($$m_data_gigs{$key}) {
+ $use_gig = 1;
+ }
+
+ my $messages = $$m_count{$key};
+ my @content = ($messages);
+ push(@content, $$a_count{$key}) if defined $a_count;
+ my $rounded_volume = volume_rounded($$m_data{$key},$$m_data_gigs{$key});
+ my($data ,$gigs) = (0,0);
+ un_round($rounded_volume,\$data,\$gigs);
+ my $rounded_average = volume_rounded($data/$messages,$gigs/$messages);
+ push(@content, $rounded_volume, $rounded_average );
+
+ # write content
+ printf $txt_fh ($txt_format, @content, $key) if $txt_fh;
+ if ($htm_fh) {
+ my $htmlkey = $key;
+ $htmlkey =~ s/>/\>\;/g;
+ $htmlkey =~ s/</\<\;/g;
+ printf $htm_fh ($htm_format, @content, $htmlkey);
+ }
+ $spreadsheet->write(${$row_sref}++, 0, [@content, $key], $f_default) if $xls_fh;
+
+
+ if (scalar @chartdatanames < $ntopchart) {
+ if ($use_gig) {
+ if ($$m_data_gigs{$key}) {
+ push(@chartdatanames, $key);
+ push(@chartdatavals, $$m_data_gigs{$key});
+ }
+ }
+ else {
+ push(@chartdatanames, $key);
+ push(@chartdatavals, $$m_data{$key});
+ }
+ }
+ else {
+ $chartotherval += ($use_gig) ? $$m_data_gigs{$key} : $$m_data{$key};
+ }
+ }
+ push(@chartdatanames, "Other");
+ push(@chartdatavals, $chartotherval);
+
+ print $txt_fh "\n" if $txt_fh;
+ if ($htm_fh) {
+ print $htm_fh "</table>\n";
+ print $htm_fh "</td><td>\n";
+ if ($HAVE_GD_Graph_pie && $charts && ($#chartdatavals > 0)) {
+ # calculate the graph
+ my @data = (
+ \@chartdatanames,
+ \@chartdatavals
+ );
+ my $graph = GD::Graph::pie->new(300, 300);
+ $graph->set(
+ x_label => 'Name',
+ y_label => 'Volume' ,
+ title => 'By Volume',
+ );
+ my $gd = $graph->plot(\@data) or warn($graph->error);
+ if ($gd) {
+ my $temp = $text;
+ $temp =~ s/ /_/g;
+ open(IMG, ">$chartdir/${temp}_volume.png") or die "Could not write $chartdir/${temp}_volume.png: $!\n";
+ binmode IMG;
+ print IMG $gd->png;
+ close IMG;
+ print $htm_fh "<img src=\"$chartrel/${temp}_volume.png\">";
+ }
+ }
+ print $htm_fh "</td><td>\n";
+ print $htm_fh "</td></tr></table>\n\n";
+ }
+
+ ++${$row_sref} if $xls_fh;
+ }
+}
+
+
+#######################################################################