-<%
-
-my $orderby = 'ORDER BY svcnum';
+<% include( 'elements/search.html',
+ 'title' => 'Account Search Results',
+ 'name' => 'accounts',
+ 'query' => $sql_query,
+ 'count_query' => $count_query,
+ 'redirect' => $link,
+ 'header' => [ '#',
+ 'Service',
+ 'Account',
+ 'UID',
+ FS::UI::Web::cust_header(),
+ ],
+ 'fields' => [ 'svcnum',
+ 'svc',
+ 'email',
+ 'uid',
+ \&FS::UI::Web::cust_fields,
+ ],
+ 'links' => [ $link,
+ $link,
+ $link,
+ $link,
+ ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
+ FS::UI::Web::cust_header()
+ ),
+ ],
+ 'align' => 'rlll'. FS::UI::Web::cust_aligns(),
+ 'color' => [
+ '',
+ '',
+ '',
+ '',
+ FS::UI::Web::cust_colors(),
+ ],
+ 'style' => [
+ '',
+ '',
+ '',
+ '',
+ FS::UI::Web::cust_styles(),
+ ],
+ )
+%>
+<%init>
-my($query)=$cgi->keywords;
-$query ||= ''; #to avoid use of unitialized value errors
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('List services');
my @extra_sql = ();
-if ( $query =~ /^UN_(.*)$/ ) {
- $query = $1;
- push @extra_sql, 'pkgnum IS NULL';
-}
-if ( $query eq 'svcnum' ) {
- #$orderby = "ORDER BY svcnum";
-} elsif ( $query eq 'username' ) {
- $orderby = "ORDER BY LOWER(username)";
-} elsif ( $query eq 'uid' ) {
- $orderby = "ORDER BY uid";
- push @extra_sql, "uid IS NOT NULL";
+ if ( $cgi->param('domain') ) {
+ my $svc_domain =
+ qsearchs('svc_domain', { 'domain' => $cgi->param('domain') } );
+ unless ( $svc_domain ) {
+ #it would be nice if this looked more like the other "not found"
+ #errors, but this will do for now.
+ eidiot "Domain ". $cgi->param('domain'). " not found at all";
+ } else {
+ push @extra_sql, 'domsvc = '. $svc_domain->svcnum;
+ }
+ }
+
+my $orderby = 'ORDER BY svcnum';
+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;
+ $sortby = "LOWER($sortby)"
+ if $sortby eq 'username';
+ push @extra_sql, "$sortby IS NOT NULL"
+ if $sortby eq 'uid';
+ $orderby = "ORDER BY $sortby";
+ }
+
} elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) {
push @extra_sql, "popnum = $1";
$orderby = "ORDER BY LOWER(username)";
}
};
-%><%= include( 'elements/search.html',
- 'title' => 'Account Search Results',
- 'name' => 'accounts',
- 'query' => $sql_query,
- 'count_query' => $count_query,
- 'redirect' => $link,
- 'header' => [ '#',
- 'Service',
- 'Account',
- 'UID',
- FS::UI::Web::cust_header(),
- ],
- 'fields' => [ 'svcnum',
- 'svc',
- 'email',
- 'uid',
- \&FS::UI::Web::cust_fields,
- ],
- 'links' => [ $link,
- $link,
- $link,
- $link,
- ( map { $link_cust }
- FS::UI::Web::cust_header()
- ),
- ],
- )
-%>
+</%init>
+