sub show_heavy_hitters {
my $_view = $in{view};
if($_view && $_view eq "view_here") {
my %states = Build_Hash("statecodes","");
$in{nw} = 1; # Show in New window format so that the table won't make main table stretch
my $sth = $dbh->prepare(qq{SELECT * FROM `member_records`});
$sth->execute();
my @row = ();
push(@row,
Tr(
th("Date Registered"),
th("Username"),
th("Name"),
th("Phone"),
th("State"),
th("Referrals")
)
);
while(my $_t1 = $sth->fetchrow_hashref()) {
my $sth2 = $dbh->prepare(qq{SELECT * FROM `shipping_address_records` WHERE `id` = ? AND `default` = ?});
$sth2->execute($_t1->{id},"1");
my $_s1 = $sth2->fetchrow_hashref();
$sth2->finish();
my $_state = $_s1->{state};
$_state = $states{$_state};
if($_state && $_state =~ /Other /) {
$_state = $_s1->{o_state} if $_s1->{o_state};
}
my $_num_referred = $dbh->selectrow_array(qq{SELECT COUNT(*) FROM `member_records` WHERE `REFERRER` = ?}, undef, $_t1->{USERNAME});
push(@row,
Tr(
td({-class=>"non_label_cell"}, Format_Date_For_Viewing($_t1->{d},"mysql_timestamp_view")),
td({-class=>"non_label_cell"}, "$_t1->{USERNAME}"),
td({-class=>"non_label_cell"}, "$_t1->{FirstName} $_t1->{LastName}"),
td({-class=>"non_label_cell"}, "$_t1->{Phone}"),
td({-class=>"non_label_cell"}, "$_state"),
td({-class=>"non_label_cell"}, "$_num_referred")
)
);
}
$sth->finish();
$_page_content .= qq~
~ . table({-class=>"sortable", -id=>"toptbl", -border=>"1", -bordercolor=>"$vars{_table_border_color}"}, @row) . br();
} elsif ($_view && $_view eq "download") {
my %states = Build_Hash("statecodes","");
my $sth = $dbh->prepare(qq{SELECT * FROM `member_records`});
$sth->execute();
my $_file2dl = qq~Date Registered,Username,Name,Phone,State,Referrals\n~;
while(my $_t1 = $sth->fetchrow_hashref()) {
my $sth2 = $dbh->prepare(qq{SELECT * FROM `shipping_address_records` WHERE `id` = ? AND `default` = ?});
$sth2->execute($_t1->{id},"1");
my $_s1 = $sth2->fetchrow_hashref();
$sth2->finish();
$_state = $_s1->{state};
$_state = $states{$_state};
if($_state && $_state =~ /Other /) {
$_state = $_s1->{o_state} if $_s1->{o_state};
}
$_num_referred = $dbh->selectrow_array(qq{SELECT COUNT(*) FROM `member_records` WHERE `REFERRER` = ?}, undef, $_t1->{USERNAME});
$_file2dl = Format_Date_For_Viewing($_t1->{d},"mysql_timestamp_view") . q~,~ . $_t1->{USERNAME} . q~,~ . "$_t1->{FirstName} $_t1->{LastName}" . q~,~ . $_t1->{Phone} . q~,~ . $_state . q~,~ . $_num_referred . "\n";
}
$sth->finish();
my $type='text';
my $_format = 'text/csv';
my $file2 = "heavy_hitters.csv";
print header(-type => $_format, -Content_disposition => qq(attachment; filename=$file2));
print $_file2dl;
} else {
$_page_content .= qq~
How do you want to view the file?
~ . a({-href=>"$_url/$in{pg}.html?load=$in{load}&view=view_here$inc_sess_id", -class=>"PageLink"}, qq~View Here in Sortable Table~) . br() x 2 .
a({-href=>"$_url/$in{pg}.html?load=$in{load}&view=download$inc_sess_id", -onclick=>"alert('This may take a few minutes, so please be patient!\\nClick OK so it can work!');", -class=>"PageLink"}, qq~Download Comma Delimited file for Excel~) . br() x 2;
}
return 1;
}