event refactor, landing on HEAD!
[freeside.git] / httemplate / search / svc_domain.cgi
index 1eda373..08ffdba 100755 (executable)
@@ -1,27 +1,62 @@
-<%
+<% include( 'elements/search.html',
+                 'title'             => "Domain Search Results",
+                 'name'              => 'domains',
+                 'query'             => $sql_query,
+                 'count_query'       => $count_query,
+                 'redirect'          => $link,
+                 'header'            => [ '#',
+                                          'Service',
+                                          'Domain',
+                                          FS::UI::Web::cust_header(),
+                                        ],
+                 'fields'            => [ 'svcnum',
+                                          'svc',
+                                          'domain',
+                                          \&FS::UI::Web::cust_fields,
+                                        ],
+                 'links'             => [ $link,
+                                          $link,
+                                          $link,
+                                          ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
+                                                FS::UI::Web::cust_header()
+                                          ),
+                                        ],
+                 'align' => 'rll'. FS::UI::Web::cust_aligns(),
+                 'color' => [ 
+                              '',
+                              '',
+                              '',
+                              FS::UI::Web::cust_colors(),
+                            ],
+                 'style' => [ 
+                              '',
+                              '',
+                              '',
+                              FS::UI::Web::cust_styles(),
+                            ],
+              )
+%>
+<%init>
 
-my $conf = new FS::Conf;
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('List services');
 
-my($query)=$cgi->keywords;
-$query ||= ''; #to avoid use of unitialized value errors
+my $conf = new FS::Conf;
 
 my $orderby = 'ORDER BY svcnum';
 my %svc_domain = ();
 my @extra_sql = ();
-if ( $query eq 'svcnum' ) {
-  #$orderby = 'ORDER BY svcnum';
-} elsif ( $query eq 'domain' ) {
-  $orderby = 'ORDER BY domain';
-} elsif ( $query eq 'UN_svcnum' ) { #UN searches need to be acl'ed (and need to
-                                    #fix $agentnums_sql
-  #$orderby = 'ORDER BY svcnum';
-  push @extra_sql, 'pkgnum IS NULL';
-} elsif ( $query eq 'UN_domain' ) { #UN searches need to be acl'ed (and need to
-                                    #fix $agentnums_sql
-  $orderby = 'ORDER BY domain';
-  push @extra_sql, 'pkgnum IS NULL';
+if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
+
+  push @extra_sql, 'pkgnum IS NULL'
+    if $cgi->param('magic') eq 'unlinked';
+
+  if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
+    my $sortby = $1;
+    $orderby = "ORDER BY $sortby";
+  }
+
 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
-  #$orderby = 'ORDER BY svcnum';
   push @extra_sql, "svcpart = $1";
 } else {
   $cgi->param('domain') =~ /^([\w\-\.]+)$/; 
@@ -34,7 +69,9 @@ my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
                 ' LEFT JOIN cust_main USING ( custnum ) ';
 
 #here is the agent virtualization
-push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( 
+                   'null_right' => 'View/link unlinked services'
+                 );
 
 my $extra_sql = '';
 if ( @extra_sql ) {
@@ -56,8 +93,9 @@ my $sql_query = {
   'hashref'   => \%svc_domain,
   'select'    => join(', ',
                    'svc_domain.*',
-                    'cust_main.custnum',
-                    FS::UI::Web::cust_sql_fields(),
+                   'part_svc.svc',
+                   'cust_main.custnum',
+                   FS::UI::Web::cust_sql_fields(),
                  ),
   'extra_sql' => "$extra_sql $orderby",
   'addl_from' => $addl_from,
@@ -71,28 +109,4 @@ my $link_cust = sub {
   $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';
 };
 
-%><%= include( 'elements/search.html',
-                 'title'             => "Domain Search Results",
-                 'name'              => 'domains',
-                 'query'             => $sql_query,
-                 'count_query'       => $count_query,
-                 'redirect'          => $link,
-                 'header'            => [ '#',
-                                          'Service',
-                                          'Domain',
-                                          FS::UI::Web::cust_header(),
-                                        ],
-                 'fields'            => [ 'svcnum',
-                                          'svc',
-                                          'domain',
-                                          \&FS::UI::Web::cust_fields,
-                                        ],
-                 'links'             => [ $link,
-                                          $link,
-                                          $link,
-                                          ( map { $link_cust }
-                                                FS::UI::Web::cust_header()
-                                          ),
-                                        ],
-              )
-%>
+</%init>