combine ticket notification scrips, #15353
[freeside.git] / httemplate / search / 477partVI_census.html
index 9134bac..534d872 100755 (executable)
@@ -1,13 +1,6 @@
 <% include( 'elements/search.html',
                   'html_init'     => $html_init,
-                  'html_foot'     => sub { if (scalar(keys %state_hash) > 1) {
-                                             '<BR><B>'.
-                                               'WARNING: multiple states found'.
-                                             '</B><BR>';
-                                           } else { 
-                                             '';
-                                           }
-                                         },
+                  'html_foot'     => $html_foot,
                   'name'          => 'regions',
                   'query'         => [ @sql_query ],
                   'count_query'   =>  $count_query,
                                      ],
                   'fields'        => [
                     sub { my $row = shift; 
-                          $state_hash{substr($row->censustract, 0, 2)} = 1;
-                          substr($row->censustract, 2, 3)
+                          my $state = substr($row->censustract, 0, 2);
+                          $state_hash{$state}++;
+                          substr($row->censustract, 2, 3) || 'None';
+                        },
+                    sub { my $row = shift;
+                          substr($row->censustract, 5) || 'None';
                         },
-                    sub { my $row = shift; substr($row->censustract, 5) },
                     'upload',
                     'download',
                     'technology_code',
-                    sub { $cgi->param('_type') eq 'xml' ? '0' : '' },  # doesn't really work
-                    'quantity',
+                    sub { $cgi->param('_type') eq 'xml' ? '0' : '' },#broken
+                    sub { my $row = shift;
+                          my $state = substr($row->censustract, 0, 2);
+                          $state_pkgcount{$state} += $row->quantity;
+                          $row->quantity;
+                        },
                     sub { my $row = shift; sprintf "%.2f", $row->residential },
                   ],
                   'links'        => [
@@ -76,11 +76,13 @@ my $html_init = '<H2>Part VI</H2>';
 my %search_hash = ();
 my @sql_query = ();
 my %state_hash = ();
+my %state_pkgcount = ();
   
 for ( qw(agentnum magic) ) {
   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
 }
-$search_hash{'classnum'} = [ $cgi->param('classnum') ];
+$search_hash{'classnum'} = [ $cgi->param('classnum') ]
+  if grep { $_ eq 'classnum' } $cgi->param;
 
 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
   if $cgi->param('part1_column_option');
@@ -130,14 +132,59 @@ my $count_query = 'SELECT count(*) FROM ( ('.
           @sql_query
        ). ') ) AS foo';
 
-my $link = 'cust_pkg.cgi?'.
-           join(';', map{ "$_=". $search_hash{$_} } keys %search_hash). ';';
+my $link = 'cust_pkg.cgi?'. join(';',
+                                      map { my $key = $_;
+                                            my @values = ref($search_hash{$_}) 
+                                              ? @{ $search_hash{$_} }
+                                              : $search_hash{$_};
+                                            map { "$key=$_" } @values;
+                                          }
+                                          keys %search_hash        
+                                ). ';';
+
 my $link_suffix = sub { my $row = shift;
                         my $result = 'censustract='. $row->censustract. ';';
-                        $result .= 'report_option='. @row_option[$row->upload - 1]
-                          if @row_option[$row->upload - 1];
-                        $result .= 'report_option='. @column_option[$row->download - 1]
-                          if @column_option[$row->download - 1];
+                        my @ro = grep $_,
+                          @row_option[$row->upload - 1],
+                          @column_option[$row->download - 2],
+                          @technology_option[$row->technology_code - 1],
+                        ;
+                        $result .= 'report_option='. join(',',@ro) if @ro;
                         $result;
                       };
+
+my $html_foot = sub {
+  if (scalar(keys %state_hash) > 1) {
+
+    my $roa_r = join(',', grep $_, @row_option);
+    $roa_r = ";report_option_any_r=$roa_r" if $roa_r;
+
+    my $roa_c = join(',', grep $_, @column_option);
+    $roa_c = ";report_option_any_c=$roa_c" if $roa_c;
+
+    my $roa_t = join(',', grep $_, @technology_option);
+    $roa_t = ";report_option_any_t=$roa_t" if $roa_t;
+    
+    '<BR><B>WARNING: multiple states found</B><BR>'.
+    '<TABLE BORDER=0>'. #nicer formatting someday
+    join('', map { '<TR>'.
+                     '<TD>'.
+                       ( &FS::Report::FCC_477::statenum2state($_) || 'None' ).
+                     '</TD>'.
+                     '<TD>'.
+                       qq(<A HREF="${link}censustract2=$_$roa_r$roa_c$roa_t">).
+                       $state_pkgcount{$_}.
+                      ' packages</A> in '.
+                       $state_hash{$_}. ' census tracts'.
+                     '</TD>'.
+                   '</TR>';
+                 }
+                 keys %state_hash
+        ).
+    '</TABLE>';
+  } else { 
+    '';
+  }
+};
+
 </%init>