diff options
author | ivan <ivan> | 2005-05-02 06:32:10 +0000 |
---|---|---|
committer | ivan <ivan> | 2005-05-02 06:32:10 +0000 |
commit | 2eb5fc5cdbe002fd17a4d3ee5bde71b4f5422f8b (patch) | |
tree | 688b5ca9926f3144dc413781426adc760b737775 /httemplate | |
parent | aea197c3f695b917a0dbdef5ec056d583f6df55d (diff) |
move httemplate/search/svc_domain to the new search template along with svc_www and svc_forward
Diffstat (limited to 'httemplate')
-rwxr-xr-x | httemplate/search/svc_domain.cgi | 206 | ||||
-rwxr-xr-x | httemplate/search/svc_forward.cgi | 26 | ||||
-rwxr-xr-x | httemplate/search/svc_www.cgi | 21 |
3 files changed, 89 insertions, 164 deletions
diff --git a/httemplate/search/svc_domain.cgi b/httemplate/search/svc_domain.cgi index 948b1d9ae..8d6547ca8 100755 --- a/httemplate/search/svc_domain.cgi +++ b/httemplate/search/svc_domain.cgi @@ -4,158 +4,80 @@ my $conf = new FS::Conf; my($query)=$cgi->keywords; $query ||= ''; #to avoid use of unitialized value errors -my(@svc_domain,$sortby); + +my $orderby = 'ORDER BY svcnum'; +my $join = ''; +my %svc_domain = (); +my $extra_sql = ''; if ( $query eq 'svcnum' ) { - $sortby=\*svcnum_sort; - @svc_domain=qsearch('svc_domain',{}); + #$orderby = 'ORDER BY svcnum'; } elsif ( $query eq 'domain' ) { - $sortby=\*domain_sort; - @svc_domain=qsearch('svc_domain',{}); + $orderby = 'ORDER BY domain'; } elsif ( $query eq 'UN_svcnum' ) { - $sortby=\*svcnum_sort; - @svc_domain = grep qsearchs('cust_svc',{ - 'svcnum' => $_->svcnum, - 'pkgnum' => '', - }), qsearch('svc_domain',{}); + #$orderby = 'ORDER BY svcnum'; + $join = 'LEFT JOIN cust_svc USING ( svcnum )'; + $extra_sql = ' WHERE pkgnum IS NULL'; } elsif ( $query eq 'UN_domain' ) { - $sortby=\*domain_sort; - @svc_domain = grep qsearchs('cust_svc',{ - 'svcnum' => $_->svcnum, - 'pkgnum' => '', - }), qsearch('svc_domain',{}); + $orderby = 'ORDER BY domain'; + $join = 'LEFT JOIN cust_svc USING ( svcnum )'; + $extra_sql = ' WHERE pkgnum IS NULL'; } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) { - @svc_domain = - qsearch( 'svc_domain', {}, '', - " WHERE $1 = ( SELECT svcpart FROM cust_svc ". - " WHERE cust_svc.svcnum = svc_domain.svcnum ) " - ); - $sortby=\*svcnum_sort; + #$orderby = 'ORDER BY svcnum'; + $join = 'LEFT JOIN cust_svc USING ( svcnum )'; + $extra_sql = " WHERE svcpart = $1"; } else { $cgi->param('domain') =~ /^([\w\-\.]+)$/; - my($domain)=$1; - #push @svc_domain, qsearchs('svc_domain',{'domain'=>$domain}); - @svc_domain = qsearchs('svc_domain',{'domain'=>$domain}); + $join = ''; + $svc_domain{'domain'} = $1; } -if ( scalar(@svc_domain) == 1 ) { - print $cgi->redirect(popurl(2). "view/svc_domain.cgi?". $svc_domain[0]->svcnum); - #exit; -} elsif ( scalar(@svc_domain) == 0 ) { -%> -<!-- mason kludge --> -<% - eidiot "No matching domains found!\n"; -} else { -%> -<!-- mason kludge --> -<% - my($total)=scalar(@svc_domain); - print header("Domain Search Results",''), <<END; - - $total matching domains found - <TABLE BORDER=4 CELLSPACING=0 CELLPADDING=0> - <TR> - <TH>Service #</TH> - <TH>Domain</TH> -<!-- <TH>Mail to<BR><FONT SIZE=-1>(click to view account)</FONT></TH> - <TH>Forwards to<BR><FONT SIZE=-1>(click to view account)</FONT></TH> ---> - </TR> -END - -# my(%saw); # if we've multiple domains with the same - # svcnum, then we've a corrupt database - - foreach my $svc_domain ( -# sort $sortby grep(!$saw{$_->svcnum}++, @svc_domain) - sort $sortby (@svc_domain) - ) { - my($svcnum,$domain)=( - $svc_domain->svcnum, - $svc_domain->domain, - ); - - #don't display all accounts here - my $rowspan = 1; - - #my @svc_acct=qsearch('svc_acct',{'domsvc' => $svcnum}); - #my $rowspan = 0; - # - #my $n1 = ''; - #my($svc_acct, @rows); - #foreach $svc_acct ( - # sort {$b->getfield('username') cmp $a->getfield('username')} (@svc_acct) - #) { - # - # my (@forwards) = (); - # - # my($svcnum,$username)=( - # $svc_acct->svcnum, - # $svc_acct->username, - # ); - # - # my @svc_forward = qsearch( 'svc_forward', { 'srcsvc' => $svcnum } ); - # my $svc_forward; - # foreach $svc_forward (@svc_forward) { - # my($dstsvc,$dst) = ( - # $svc_forward->dstsvc, - # $svc_forward->dst, - # ); - # if ($dstsvc) { - # my $dst_svc_acct=qsearchs( 'svc_acct', { 'svcnum' => $dstsvc } ); - # my $destination=$dst_svc_acct->email; - # push @forwards, qq!<TD><A HREF="!, popurl(2), - # qq!view/svc_acct.cgi?$dstsvc">$destination</A>!, - # qq!</TD></TR>! - # ; - # }else{ - # push @forwards, qq!<TD>$dst</TD></TR>! - # ; - # } - # } - # - # push @rows, qq!$n1<TD ROWSPAN=!, (scalar(@svc_forward) || 1), - # qq!><A HREF="!. popurl(2). qq!view/svc_acct.cgi?$svcnum">!, - # #print '', ( ($domuser eq '*') ? "<I>(anything)</I>" : $domuser ); - # ( ($username eq '*') ? "<I>(anything)</I>" : $username ), - # qq!\@$domain</A> </TD>!, - # ; - # - # push @rows, @forwards; - # - # $rowspan += (scalar(@svc_forward) || 1); - # $n1 = "</TR><TR>"; - #} - ##end of false laziness - # - # - - print <<END; - <TR> - <TD ROWSPAN=$rowspan><A HREF="${p}view/svc_domain.cgi?$svcnum">$svcnum</A></TD> - <TD ROWSPAN=$rowspan><A HREF="${p}view/svc_domain.cgi?$svcnum">$domain</A></TD> -END - - #print @rows; - print "</TR>"; - - } - - print <<END; - </TABLE> - </BODY> -</HTML> -END +my $count_query = "SELECT COUNT(*) FROM svc_domain $join $extra_sql"; +if ( keys %svc_domain ) { + $count_query .= ' WHERE '. + join(' AND ', map "$_ = ". dbh->quote($svc_domain{$_}), + keys %svc_domain + ); } -sub svcnum_sort { - $a->getfield('svcnum') <=> $b->getfield('svcnum'); -} - -sub domain_sort { - $a->getfield('domain') cmp $b->getfield('domain'); -} - - +my $sql_query = { + 'table' => 'svc_domain', + 'hashref' => \%svc_domain, + 'select' => join(', ', + 'svc_domain.*', + map "cust_main.$_", qw(custnum last first company) + ), + 'extra_sql' => "$extra_sql $orderby", + 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum )'. + 'LEFT JOIN cust_pkg USING ( pkgnum )'. + 'LEFT JOIN cust_main USING ( custnum )', +}; + +my $link = [ "${p}view/svc_domain.cgi", 'svcnum' ]; + +#smaller false laziness w/svc_*.cgi here +my $link_cust = sub { + my $svc_x = shift; + $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' => [ '#', + 'Domain', + 'Customer', + ], + 'fields' => [ 'svcnum', + 'domain', + \&FS::svc_Common::cust_name, + ], + 'links' => [ $link, + $link, + $link_cust, + ], + ) %> diff --git a/httemplate/search/svc_forward.cgi b/httemplate/search/svc_forward.cgi index f54822572..1c1c6e4dd 100755 --- a/httemplate/search/svc_forward.cgi +++ b/httemplate/search/svc_forward.cgi @@ -4,7 +4,7 @@ my $conf = new FS::Conf; my($query)=$cgi->keywords; $query ||= ''; #to avoid use of unitialized value errors -my($orderby); +my $orderby; if ( $query eq 'svcnum' ) { $orderby = 'ORDER BY svcnum'; } else { @@ -69,26 +69,10 @@ my $link_dst = sub { } }; -my $format_cust = sub { - my $svc_forward = shift; - - if ( $svc_forward->custnum ) { - #false laziness w/FS::cust_main::name - my $name = $svc_forward->get('last'). ', '. $svc_forward->first; - $name = $svc_forward->company. " ($name)" if $svc_forward->company; - $name; - } else { - '<I>(unlinked)</I>'; - } -}; - +#smaller false laziness w/svc_*.cgi here my $link_cust = sub { - my $svc_forward = shift; - if ( $svc_forward->custnum ) { - [ "${p}view/cust_main.cgi?", 'custnum' ]; - } else { - ''; - } + my $svc_x = shift; + $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : ''; }; %><%= include ('elements/search.html', @@ -105,7 +89,7 @@ my $link_cust = sub { 'fields' => [ 'svcnum', $format_src, $format_dst, - $format_cust, + \&FS::svc_Common::cust_name, ], 'links' => [ $link, $link_src, diff --git a/httemplate/search/svc_www.cgi b/httemplate/search/svc_www.cgi index 5ae72f8b3..de1f5dd78 100755 --- a/httemplate/search/svc_www.cgi +++ b/httemplate/search/svc_www.cgi @@ -15,27 +15,46 @@ my $count_query = 'SELECT COUNT(*) FROM svc_www'; my $sql_query = { 'table' => 'svc_www', 'hashref' => {}, + 'select' => join(', ', + 'svc_www.*', + map "cust_main.$_", qw(custnum last first company) + ), 'extra_sql' => $orderby, + 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum )'. + 'LEFT JOIN cust_pkg USING ( pkgnum )'. + 'LEFT JOIN cust_main USING ( custnum )', }; my $link = [ "${p}view/svc_www.cgi?", 'svcnum', ]; #my $dlink = [ "${p}view/svc_www.cgi?", 'svcnum', ]; my $ulink = [ "${p}view/svc_acct.cgi?", 'usersvc', ]; +#smaller false laziness w/svc_*.cgi here +my $link_cust = sub { + my $svc_x = shift; + $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : ''; +}; %><%= include( 'elements/search.html', 'title' => 'Virtual Host Search Results', 'name' => 'virtual hosts', 'query' => $sql_query, 'count_query' => $count_query, - 'header' => [ '#', 'Zone', 'User', ], + 'redirect' => $link, + 'header' => [ '#', + 'Zone', + 'User', + 'Customer', + ], 'fields' => [ 'svcnum', sub { $_[0]->domain_record->zone }, sub { $_[0]->svc_acct->email }, + \&FS::svc_Common::cust_name, ], 'links' => [ $link, '', $ulink, + $link_cust, ], ) %> |