Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / search / svc_broadband.cgi
index 605b829..ff2538c 100755 (executable)
@@ -1,4 +1,4 @@
-<% include( 'elements/search.html',
+<& elements/svc_Common.html,
               'title'       => 'Broadband Search Results',
               'name'        => 'broadband services',
               'html_init'   => $html_init,
                                  'Router',
                                  @tower_header,
                                  'IP Address',
+                                 emt('Pkg. Status'),
                                  FS::UI::Web::cust_header($cgi->param('cust_fields')),
                                ],
               'fields'      => [ 'svcnum',
                                  'svc',
                                  sub {
-                                   my $blocknum = shift->blocknum or return '';
-                                   $routerbyblock{$blocknum}->routername;
+                                   my $router = shift->router; 
+                                   $router ? $router->routername : '';
                                  },
                                  @tower_fields,
                                  'ip_addr',
+                                 sub {
+                                   $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
+                                   $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
+                                 },
                                  \&FS::UI::Web::cust_fields,
                                ],
               'links'       => [ $link,
                                  '', #$link_router,
                                  (map '', @tower_fields),
                                  $link,
+                                 '', # pkg status
                                  ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                                        FS::UI::Web::cust_header($cgi->param('cust_fields'))
                                  ),
                                ],
-              'align'       => 'rll'.('r' x @tower_fields).'r'.
+              'align'       => 'rll'.('r' x @tower_fields).'rr'.
                                 FS::UI::Web::cust_aligns(),
               'color'       => [ 
                                  '',
                                  '',
                                  (map '', @tower_fields),
                                  '',
+                                 sub {
+                                   my $c = FS::cust_pkg::statuscolors;
+                                   $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
+                                 }, # pkg status
                                  FS::UI::Web::cust_colors(),
                                ],
               'style'       => [ 
                                  '',
                                  (map '', @tower_fields),
                                  '',
+                                 'b',
                                  FS::UI::Web::cust_styles(),
                                ],
-          )
-%>
+          
+&>
 <%init>
 
 die "access denied" unless
   $FS::CurrentUser::CurrentUser->access_right('List services');
 
+my %cust_pkg_cache;
+
 my $conf = new FS::Conf;
 
 my %search_hash;
 if ( $cgi->param('magic') eq 'unlinked' ) {
   %search_hash = ( 'unlinked' => 1 );
-}
-else {
-  foreach (qw(custnum agentnum svcpart)) {
+} else {
+  foreach (qw( custnum agentnum svcpart cust_fields )) {
     $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
   }
   foreach (qw(pkgpart routernum towernum sectornum)) {
     $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
   }
+  if ( defined($cgi->param('cancelled')) ) {
+    $search_hash{'cancelled'} = $cgi->param('cancelled') ? 1 : 0;
+  }
 }
 
 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
-  $search_hash{'order_by'} = $1;
+  $search_hash{'order_by'} = "ORDER BY $1";
 }
 
 my $sql_query = FS::svc_broadband->search(\%search_hash);
@@ -106,5 +121,9 @@ my $html_init = include('/elements/email-link.html',
                   'search_hash' => \%search_hash,
                   'table' => 'svc_broadband' 
                 );
+$html_init .= ' | ' .
+  '<a href="' .
+  $fsurl . 'search/svc_broadband-map.html?' . $cgi->query_string .
+  '">' . emt('View a map of these services') . '</a>';
 
 </%init>