-<%
-#
-# $Id: svc_acct.cgi,v 1.1 2001-07-30 07:36:04 ivan Exp $
-#
-# Usage: post form to:
-# http://server.name/path/svc_acct.cgi
-#
-# Note: Should be run setuid freeside as user nobody.
-#
-# loosely (sp?) based on search/cust_main.cgi
-#
-# ivan@voicenet.com 96-jan-3 -> 96-jan-4
-#
-# rewrite (now does browsing too) ivan@sisd.com 98-mar-9
-#
-# Changes to allow page to work at a relative position in server
-# bmccane@maxbaud.net 98-apr-3
-#
-# show unlinked accounts ivan@sisd.com 98-jun-22
-#
-# use FS::CGI, show total ivan@sisd.com 98-jul-17
-#
-# give service and customer info too ivan@sisd.com 98-aug-16
-#
-# $Log: svc_acct.cgi,v $
-# Revision 1.1 2001-07-30 07:36:04 ivan
-# templates!!!
-#
-# Revision 1.11 1999/04/14 11:25:33 ivan
-# *** empty log message ***
-#
-# Revision 1.10 1999/04/14 11:20:21 ivan
-# visual fix
-#
-# Revision 1.9 1999/04/10 01:53:18 ivan
-# oops, search usernames limited to 8 chars
-#
-# Revision 1.8 1999/04/09 23:43:29 ivan
-# just in case
-#
-# Revision 1.7 1999/02/07 09:59:38 ivan
-# more mod_perl fixes, and bugfixes Peter Wemm sent via email
-#
-# Revision 1.6 1999/01/19 05:14:14 ivan
-# for mod_perl: no more top-level my() variables; use vars instead
-# also the last s/create/new/;
-#
-# Revision 1.5 1999/01/18 09:41:39 ivan
-# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
-# (good idea anyway)
-#
-# Revision 1.4 1999/01/18 09:22:34 ivan
-# changes to track email addresses for email invoicing
-#
-# Revision 1.3 1998/12/23 03:06:28 ivan
-# $cgi->keywords instead of $cgi->query_string
-#
-# Revision 1.2 1998/12/17 09:41:10 ivan
-# s/CGI::(Base|Request)/CGI.pm/;
-#
-
-use strict;
-use vars qw( $cgi @svc_acct $sortby $query );
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::UID qw(cgisuidsetup);
-use FS::Record qw(qsearch qsearchs);
-use FS::CGI qw(header eidiot popurl table);
-use FS::svc_acct;
-use FS::cust_main;
-
-$cgi = new CGI;
-&cgisuidsetup($cgi);
-
-($query)=$cgi->keywords;
-$query ||= ''; #to avoid use of unitialized value errors
-#this tree is a little bit redundant
-if ( $query eq 'svcnum' ) {
- $sortby=\*svcnum_sort;
- @svc_acct=qsearch('svc_acct',{});
-} elsif ( $query eq 'username' ) {
- $sortby=\*username_sort;
- @svc_acct=qsearch('svc_acct',{});
-} elsif ( $query eq 'uid' ) {
- $sortby=\*uid_sort;
- @svc_acct=grep $_->uid ne '', qsearch('svc_acct',{});
-} elsif ( $query eq 'UN_svcnum' ) {
- $sortby=\*svcnum_sort;
- @svc_acct = grep qsearchs('cust_svc',{
- 'svcnum' => $_->svcnum,
- 'pkgnum' => '',
- }), qsearch('svc_acct',{});
-} elsif ( $query eq 'UN_username' ) {
- $sortby=\*username_sort;
- @svc_acct = grep qsearchs('cust_svc',{
- 'svcnum' => $_->svcnum,
- 'pkgnum' => '',
- }), qsearch('svc_acct',{});
-} elsif ( $query eq 'UN_uid' ) {
- $sortby=\*uid_sort;
- @svc_acct = grep qsearchs('cust_svc',{
- 'svcnum' => $_->svcnum,
- 'pkgnum' => '',
- }), qsearch('svc_acct',{});
-} else {
- $sortby=\*uid_sort;
- &usernamesearch;
-}
+<% 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>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('List services');
+
+my @extra_sql = ();
+
+ 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' || $sortby eq 'seconds';
+ $orderby = "ORDER BY $sortby";
+ }