summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2006-06-19 02:33:52 +0000
committerivan <ivan>2006-06-19 02:33:52 +0000
commitc0e8da2f1e89729efa1032241e4239765a296514 (patch)
tree68af748a3dc0c983e3ed255ad1bc05e9bf2eb8e7 /httemplate
parentbb65b62d3d68ac0788f230fe2e35ebe1913fc0f5 (diff)
agent virtualization, take one (stuff from "inactive" changeset snuck into cust_main.pm and the package reporting changeset in search/cust_pkg.cgi here too)
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/elements/select-agent.html2
-rw-r--r--httemplate/elements/select-table.html7
-rw-r--r--httemplate/elements/tr-select-agent.html11
-rwxr-xr-xhttemplate/search/cust_bill.html19
-rwxr-xr-xhttemplate/search/cust_main.cgi49
-rwxr-xr-xhttemplate/search/cust_pkg.cgi162
-rwxr-xr-xhttemplate/search/svc_acct.cgi24
-rwxr-xr-xhttemplate/search/svc_domain.cgi43
-rwxr-xr-xhttemplate/search/svc_forward.cgi24
9 files changed, 237 insertions, 104 deletions
diff --git a/httemplate/elements/select-agent.html b/httemplate/elements/select-agent.html
index aa480a54b..78ec25f82 100644
--- a/httemplate/elements/select-agent.html
+++ b/httemplate/elements/select-agent.html
@@ -11,6 +11,8 @@
'value' => $agentnum,
'empty_label' => 'all',
'hashref' => { 'disabled' => '' },
+ 'extra_sql' => ' AND '.
+ $FS::CurrentUser::CurrentUser->agentnums_sql,
%select_opt,
)
%>
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html
index 96f0177fb..6c8089b31 100644
--- a/httemplate/elements/select-table.html
+++ b/httemplate/elements/select-table.html
@@ -10,6 +10,7 @@
##opt
# 'empty_label' => '', #better specify it though, the default might change
# 'hashref' => {},
+ # 'extra_sql' => '',
# 'records' => \@records, #instead of hashref
# 'pre_options' => [ 'value' => 'option' ], #before normal options
@@ -25,7 +26,11 @@
if ( $opt{'records'} ) {
@records = @{ $opt{'records'} };
} else {
- @records = qsearch( $opt{'table'}, ( $opt{'hashref'} || {} ) );
+ @records = qsearch( {
+ 'table' => $opt{'table'},
+ 'hashref' => ( $opt{'hashref'} || {} ),
+ 'extra_sql' => ( $opt{'extra_sql'} || '' ),
+ });
}
my @pre_options = $opt{'pre_options'} ? @{ $opt{'pre_options'} } : ();
diff --git a/httemplate/elements/tr-select-agent.html b/httemplate/elements/tr-select-agent.html
index 2227262b6..83c8d1758 100644
--- a/httemplate/elements/tr-select-agent.html
+++ b/httemplate/elements/tr-select-agent.html
@@ -3,9 +3,16 @@
my @agents;
if ( $opt{'agents'} ) {
- @agents = @{ $opt{'agents'} };
+ #@agents = @{ $opt{'agents'} };
+ #here is the agent virtualization
+ my $agentnums_href = $FS::CurrentUser::CurrentUser->agentnums_href;
+ @agents = grep $agentnums_href->{$_->agentnum}, @{ $opt{'agents'} };
} else {
- @agents = qsearch( 'agent', { disabled=>'' } );
+ @agents = qsearch( {
+ 'table' => 'agent',
+ 'hashref' => { disabled=>'' },
+ 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+ });
}
%>
diff --git a/httemplate/search/cust_bill.html b/httemplate/search/cust_bill.html
index 2108653a8..16128d5c8 100755
--- a/httemplate/search/cust_bill.html
+++ b/httemplate/search/cust_bill.html
@@ -1,4 +1,9 @@
<%
+
+ my $join_cust_main = 'LEFT JOIN cust_main USING ( custnum )';
+ #here is the agent virtualization
+ my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my( $count_query, $sql_query );
my( $count_addl ) = ( '' );
my( $distinct ) = ( '' );
@@ -6,11 +11,15 @@
my($agentnum) = ( '' );
my($open, $days) = ( '', '' );
if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
- $count_query = "SELECT COUNT(*) FROM cust_bill WHERE invnum = $2";
+ $count_query =
+ "SELECT COUNT(*) FROM cust_bill $join_cust_main".
+ " WHERE invnum = $2 AND $agentnums_sql"; #agent virtualization
$sql_query = {
'table' => 'cust_bill',
+ 'addl_from' => $join_cust_main,
'hashref' => { 'invnum' => $2 },
#'select' => '*',
+ 'extra_sql' => " AND $agentnums_sql", #agent virtualization
};
} else {
#if ( $cgi->param('begin') || $cgi->param('end')
@@ -68,10 +77,10 @@
push @where, "cust_bill._date < ". (time-86400*$days) if $days;
}
+ #here is the agent virtualization
+ push @where, $agentnums_sql;
my $extra_sql = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
- my $addl_from = 'left join cust_main using ( custnum )';
-
if ( $cgi->param('newest_percust') ) {
$distinct = 'DISTINCT ON ( cust_bill.custnum )';
$orderby = 'ORDER BY cust_bill.custnum ASC, cust_bill._date DESC';
@@ -85,11 +94,11 @@
'$%.2f total outstanding balance',
];
}
- $count_query .= " FROM cust_bill $addl_from $extra_sql";
+ $count_query .= " FROM cust_bill $join_cust_main $extra_sql";
$sql_query = {
'table' => 'cust_bill',
- 'addl_from' => $addl_from,
+ 'addl_from' => $join_cust_main,
'hashref' => {},
'select' => "$distinct ". join(', ',
'cust_bill.*',
diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi
index 733e5dc15..5b7ccec1c 100755
--- a/httemplate/search/cust_main.cgi
+++ b/httemplate/search/cust_main.cgi
@@ -117,6 +117,10 @@ if ( $cgi->param('browse')
my $addl_qual = join(' AND ', @qual);
+ #here is the agent virtualization
+ $addl_qual .= ( $addl_qual ? ' AND ' : '' ).
+ $FS::CurrentUser::CurrentUser->agentnums_sql;
+
if ( $addl_qual ) {
$qual .= ' AND ' if $qual;
$qual .= $addl_qual;
@@ -322,32 +326,43 @@ END
print "<BR><BR>". $pager. include('/elements/table-grid.html'). <<END;
<TR>
- <TH></TH>
- <TH>(bill) name</TH>
- <TH>company</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">(bill) name</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
END
if ( defined dbdef->table('cust_main')->column('ship_last') ) {
print <<END;
- <TH>(service) name</TH>
- <TH>company</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">(service) name</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
END
}
foreach my $addl_header ( @addl_headers ) {
- print "<TH>$addl_header</TH>";
+ print '<TH CLASS="grid" BGCOLOR="#cccccc">'. "$addl_header</TH>";
}
print <<END;
- <TH>Packages</TH>
- <TH COLSPAN=2>Services</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Packages</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Services</TH>
</TR>
END
+ my $bgcolor1 = '#eeeeee';
+ my $bgcolor2 = '#ffffff';
+ my $bgcolor;
+
my(%saw,$cust_main);
foreach $cust_main (
sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
) {
+
+ if ( $bgcolor eq $bgcolor1 ) {
+ $bgcolor = $bgcolor2;
+ } else {
+ $bgcolor = $bgcolor1;
+ }
+
my($custnum,$last,$first,$company)=(
$cust_main->custnum,
$cust_main->getfield('last'),
@@ -377,9 +392,9 @@ END
%>
<TR>
- <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= $custnum %></FONT></A></TD>
- <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$last, $first" %></FONT></A></TD>
- <TD ROWSPAN=<%= $rowspan || 1 %>><%= $pcompany %></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= $custnum %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$last, $first" %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><%= $pcompany %></TD>
<%
if ( defined dbdef->table('cust_main')->column('ship_last') ) {
@@ -393,14 +408,14 @@ END
: '<FONT SIZE=-1>&nbsp;</FONT>';
%>
- <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$ship_last, $ship_first" %></FONT></A></TD>
- <TD ROWSPAN=<%= $rowspan || 1 %>><%= $pship_company %></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$ship_last, $ship_first" %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><%= $pship_company %></A></TD>
<% }
foreach my $addl_col ( @addl_cols ) { %>
- <TD ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
<% if ( $addl_col eq 'tickets' ) {
if ( @custom_priorities ) {
@@ -457,14 +472,14 @@ END
#my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
my $rowspan = scalar(@cust_svc) || 1;
- print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
+ print $n1, qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
my($n2)='';
foreach my $cust_svc ( @cust_svc ) {
my($label, $value, $svcdb) = $cust_svc->label;
my($svcnum) = $cust_svc->svcnum;
my($sview) = $p.'view';
- print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
- qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
+ print $n2,qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
+ qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
$n2="</TR><TR>";
}
#print qq!</TR><TR>\n!;
diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi
index a2fb89c12..e8b3f490d 100755
--- a/httemplate/search/cust_pkg.cgi
+++ b/httemplate/search/cust_pkg.cgi
@@ -1,19 +1,80 @@
<%
-my %part_pkg = map { $_->pkgpart => $_ } qsearch('part_pkg', {});
+# my %part_pkg = map { $_->pkgpart => $_ } qsearch('part_pkg', {});
my($query) = $cgi->keywords;
-my $orderby;
-my @where;
-my $cjoin = '';
+my @where = ();
+
+##
+# parse agent
+##
if ( $cgi->param('agentnum') =~ /^(\d+)$/ and $1 ) {
- $cjoin = "LEFT JOIN cust_main USING ( custnum )";
push @where,
"agentnum = $1";
}
+##
+# parse status
+##
+
+if ( $cgi->param('magic') eq 'active'
+ || $cgi->param('status') eq 'active' ) {
+
+ push @where, FS::cust_pkg->active_sql();
+
+} elsif ( $cgi->param('magic') eq 'suspended'
+ || $cgi->param('status') eq 'suspended' ) {
+
+ push @where, FS::cust_pkg->suspended_sql();
+
+} elsif ( $cgi->param('magic') =~ /^cancell?ed$/
+ || $cgi->param('status') =~ /^cancell?ed$/ ) {
+
+ push @where, FS::cust_pkg->cancelled_sql();
+
+} elsif ( $cgi->param('status') =~ /^(one-time charge|inactive)$/ ) {
+
+ push @where, FS::cust_pkg->inactive_sql();
+
+}
+
+###
+# parse package class
+###
+
+#false lazinessish w/graph/cust_bill_pkg.cgi
+my $classnum = 0;
+my @pkg_class = ();
+if ( $cgi->param('classnum') =~ /^(\d*)$/ ) {
+ $classnum = $1;
+ if ( $classnum ) { #a specific class
+ push @where, "classnum = $classnum";
+
+ #@pkg_class = ( qsearchs('pkg_class', { 'classnum' => $classnum } ) );
+ #die "classnum $classnum not found!" unless $pkg_class[0];
+ #$title .= $pkg_class[0]->classname.' ';
+
+ } elsif ( $classnum eq '' ) { #the empty class
+
+ push @where, "classnum IS NULL";
+ #$title .= 'Empty class ';
+ #@pkg_class = ( '(empty class)' );
+ } elsif ( $classnum eq '0' ) {
+ #@pkg_class = qsearch('pkg_class', {} ); # { 'disabled' => '' } );
+ #push @pkg_class, '(empty class)';
+ } else {
+ die "illegal classnum";
+ }
+}
+#eslaf
+
+###
+# parse magic, legacy, etc.
+###
+
+my $orderby;
if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
$orderby = 'ORDER BY bill';
@@ -23,7 +84,8 @@ if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
#"bill <= $ending",
"CASE WHEN bill IS NULL THEN 0 ELSE bill END >= $beginning ",
"CASE WHEN bill IS NULL THEN 0 ELSE bill END <= $ending",
- '( cancel IS NULL OR cancel = 0 )';
+ #'( cancel IS NULL OR cancel = 0 )'
+ ;
} else {
@@ -33,30 +95,6 @@ if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
$orderby = 'ORDER BY pkgnum';
- if ( $cgi->param('magic') eq 'active' ) {
-
- #push @where,
- # '( susp IS NULL OR susp = 0 )',
- # '( cancel IS NULL OR cancel = 0)';
- push @where, FS::cust_pkg->active_sql();
-
- } elsif ( $cgi->param('magic') eq 'suspended' ) {
-
- push @where,
- 'susp IS NOT NULL',
- 'susp != 0',
- '( cancel IS NULL OR cancel = 0)';
-
- } elsif ( $cgi->param('magic') =~ /^cancell?ed$/ ) {
-
- push @where,
- 'cancel IS NOT NULL',
- 'cancel != 0';
-
- } else {
- die "guru meditation #420";
- }
-
if ( $cgi->param('pkgpart') =~ /^(\d+)$/ ) {
push @where, "pkgpart = $1";
}
@@ -84,21 +122,35 @@ if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
}
+##
+# setup queries, links, subs, etc. for the search
+##
+
+# here is the agent virtualization
+push @where, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
-my $count_query = "SELECT COUNT(*) FROM cust_pkg $cjoin $extra_sql";
+my $addl_from = 'LEFT JOIN cust_main USING ( custnum ) '.
+ 'LEFT JOIN part_pkg USING ( pkgpart ) '.
+ 'LEFT JOIN pkg_class USING ( classnum ) ';
+
+my $count_query = "SELECT COUNT(*) FROM cust_pkg $addl_from $extra_sql";
my $sql_query = {
'table' => 'cust_pkg',
'hashref' => {},
'select' => join(', ',
'cust_pkg.*',
+ ( map "part_pkg.$_", qw( pkg freq ) ),
+ 'pkg_class.classname',
'cust_main.custnum as cust_main_custnum',
- FS::UI::Web::cust_sql_fields(),
+ FS::UI::Web::cust_sql_fields(
+ $cgi->param('cust_fields')
+ ),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => ' LEFT JOIN cust_main USING ( custnum ) ',
- #' LEFT JOIN part_pkg USING ( pkgpart ) '
+ 'addl_from' => $addl_from,
};
my $link = sub {
@@ -138,6 +190,10 @@ sub time_or_blank {
};
}
+###
+# and finally, include the search template
+###
+
%><%= include( 'elements/search.html',
'title' => 'Package Search Results',
'name' => 'packages',
@@ -146,6 +202,7 @@ sub time_or_blank {
#'redirect' => $link,
'header' => [ '#',
'Package',
+ 'Class',
'Status',
'Freq.',
'Setup',
@@ -154,18 +211,25 @@ sub time_or_blank {
'Susp.',
'Expire',
'Cancel',
- FS::UI::Web::cust_header(),
+ FS::UI::Web::cust_header(
+ $cgi->param('cust_fields')
+ ),
'Services',
],
'fields' => [
'pkgnum',
- sub { my $part_pkg = $part_pkg{shift->pkgpart};
- $part_pkg->pkg; # ' - '. $part_pkg->comment;
+ sub { #my $part_pkg = $part_pkg{shift->pkgpart};
+ #$part_pkg->pkg; # ' - '. $part_pkg->comment;
+ $_[0]->pkg; # ' - '. $_[0]->comment;
},
+ 'classname',
sub { ucfirst(shift->status); },
sub { #shift->part_pkg->freq_pretty;
- my $part_pkg = $part_pkg{shift->pkgpart};
- $part_pkg->freq_pretty;
+
+ #my $part_pkg = $part_pkg{shift->pkgpart};
+ #$part_pkg->freq_pretty;
+
+ FS::part_pkg::freq_pretty(shift);
},
#sub { time2str('%b %d %Y', shift->setup); },
@@ -204,6 +268,7 @@ sub time_or_blank {
'color' => [
'',
'',
+ '',
sub { shift->statuscolor; },
'',
'',
@@ -212,12 +277,16 @@ sub time_or_blank {
'',
'',
'',
- ( map { '' } FS::UI::Web::cust_header() ),
+ ( map { '' }
+ FS::UI::Web::cust_header(
+ $cgi->param('cust_fields')
+ )
+ ),
'',
],
- 'style' => [ '', '', 'b' ],
- 'size' => [ '', '', '-1', ],
- 'align' => 'rlclrrrrrr',
+ 'style' => [ '', '', '', 'b' ],
+ 'size' => [ '', '', '', '-1', ],
+ 'align' => 'rllclrrrrrr',
'links' => [
$link,
$link,
@@ -229,7 +298,12 @@ sub time_or_blank {
'',
'',
'',
- ( map { $clink } FS::UI::Web::cust_header() ),
+ '',
+ ( map { $clink }
+ FS::UI::Web::cust_header(
+ $cgi->param('cust_fields')
+ )
+ ),
'',
],
)
diff --git a/httemplate/search/svc_acct.cgi b/httemplate/search/svc_acct.cgi
index b14591958..ef68ba05e 100755
--- a/httemplate/search/svc_acct.cgi
+++ b/httemplate/search/svc_acct.cgi
@@ -5,11 +5,9 @@ my $orderby = 'ORDER BY svcnum';
my($query)=$cgi->keywords;
$query ||= ''; #to avoid use of unitialized value errors
-my $cjoin = '';
my @extra_sql = ();
if ( $query =~ /^UN_(.*)$/ ) {
$query = $1;
- $cjoin = 'LEFT JOIN cust_svc USING ( svcnum )';
push @extra_sql, 'pkgnum IS NULL';
}
@@ -24,7 +22,6 @@ if ( $query eq 'svcnum' ) {
push @extra_sql, "popnum = $1";
$orderby = "ORDER BY LOWER(username)";
} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
- $cjoin ||= 'LEFT JOIN cust_svc USING ( svcnum )';
push @extra_sql, "svcpart = $1";
$orderby = "ORDER BY uid";
#$orderby = "ORDER BY svcnum";
@@ -72,12 +69,20 @@ if ( $query eq 'svcnum' ) {
}
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $extra_sql =
scalar(@extra_sql)
? ' WHERE '. join(' AND ', @extra_sql )
: '';
-my $count_query = "SELECT COUNT(*) FROM svc_acct $cjoin $extra_sql";
+my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
#if ( keys %svc_acct ) {
# $count_query .= ' WHERE '.
# join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
@@ -94,10 +99,7 @@ my $sql_query = {
FS::UI::Web::cust_sql_fields(),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
- ' LEFT JOIN part_svc USING ( svcpart ) '.
- ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
- ' LEFT JOIN cust_main USING ( custnum ) ',
+ 'addl_from' => $addl_from,
};
my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
@@ -117,21 +119,21 @@ my $link_cust = sub {
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
+ 'Service',
'Account',
'UID',
- 'Service',
FS::UI::Web::cust_header(),
],
'fields' => [ 'svcnum',
+ 'svc',
'email',
'uid',
- 'svc',
\&FS::UI::Web::cust_fields,
],
'links' => [ $link,
$link,
$link,
- '',
+ $link,
( map { $link_cust }
FS::UI::Web::cust_header()
),
diff --git a/httemplate/search/svc_domain.cgi b/httemplate/search/svc_domain.cgi
index b02eea8bd..1eda3733c 100755
--- a/httemplate/search/svc_domain.cgi
+++ b/httemplate/search/svc_domain.cgi
@@ -6,38 +6,50 @@ my($query)=$cgi->keywords;
$query ||= ''; #to avoid use of unitialized value errors
my $orderby = 'ORDER BY svcnum';
-my $join = '';
my %svc_domain = ();
-my $extra_sql = '';
+my @extra_sql = ();
if ( $query eq 'svcnum' ) {
#$orderby = 'ORDER BY svcnum';
} elsif ( $query eq 'domain' ) {
$orderby = 'ORDER BY domain';
-} elsif ( $query eq 'UN_svcnum' ) {
+} elsif ( $query eq 'UN_svcnum' ) { #UN searches need to be acl'ed (and need to
+ #fix $agentnums_sql
#$orderby = 'ORDER BY svcnum';
- $join = 'LEFT JOIN cust_svc USING ( svcnum )';
- $extra_sql = ' WHERE pkgnum IS NULL';
-} elsif ( $query eq 'UN_domain' ) {
+ 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';
- $join = 'LEFT JOIN cust_svc USING ( svcnum )';
- $extra_sql = ' WHERE pkgnum IS NULL';
+ push @extra_sql, 'pkgnum IS NULL';
} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
#$orderby = 'ORDER BY svcnum';
- $join = 'LEFT JOIN cust_svc USING ( svcnum )';
- $extra_sql = " WHERE svcpart = $1";
+ push @extra_sql, "svcpart = $1";
} else {
$cgi->param('domain') =~ /^([\w\-\.]+)$/;
- $join = '';
$svc_domain{'domain'} = $1;
}
-my $count_query = "SELECT COUNT(*) FROM svc_domain $join $extra_sql";
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+my $extra_sql = '';
+if ( @extra_sql ) {
+ $extra_sql = ( keys(%svc_domain) ? ' AND ' : ' WHERE ' ).
+ join(' AND ', @extra_sql );
+}
+
+my $count_query = "SELECT COUNT(*) FROM svc_domain $addl_from ";
if ( keys %svc_domain ) {
$count_query .= ' WHERE '.
join(' AND ', map "$_ = ". dbh->quote($svc_domain{$_}),
keys %svc_domain
);
}
+$count_query .= $extra_sql;
my $sql_query = {
'table' => 'svc_domain',
@@ -48,9 +60,7 @@ my $sql_query = {
FS::UI::Web::cust_sql_fields(),
),
'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 ) ',
+ 'addl_from' => $addl_from,
};
my $link = [ "${p}view/svc_domain.cgi?", 'svcnum' ];
@@ -68,15 +78,18 @@ my $link_cust = sub {
'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()
),
diff --git a/httemplate/search/svc_forward.cgi b/httemplate/search/svc_forward.cgi
index a204e345f..4961967d7 100755
--- a/httemplate/search/svc_forward.cgi
+++ b/httemplate/search/svc_forward.cgi
@@ -5,14 +5,12 @@ my $conf = new FS::Conf;
my($query)=$cgi->keywords;
$query ||= ''; #to avoid use of unitialized value errors
-
my $orderby;
-my $cjoin = '';
my @extra_sql = ();
-if ( $query =~ /^UN_(.*)$/ ) {
+if ( $query =~ /^UN_(.*)$/ ) { #UN searches need to be acl'ed (and need to
+ #fix $agentnums_sql
$query = $1;
- $cjoin = 'LEFT JOIN cust_svc USING ( svcnum )';
push @extra_sql, 'pkgnum IS NULL';
}
@@ -22,12 +20,20 @@ if ( $query eq 'svcnum' ) {
eidiot('unimplemented');
}
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $extra_sql =
scalar(@extra_sql)
? ' WHERE '. join(' AND ', @extra_sql )
: '';
-my $count_query = "SELECT COUNT(*) FROM svc_forward $cjoin $extra_sql";
+my $count_query = "SELECT COUNT(*) FROM svc_forward $addl_from $extra_sql";
my $sql_query = {
'table' => 'svc_forward',
'hashref' => {},
@@ -37,10 +43,7 @@ my $sql_query = {
FS::UI::Web::cust_sql_fields(),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
- ' LEFT JOIN part_svc USING ( svcpart ) '.
- ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
- ' LEFT JOIN cust_main USING ( custnum ) ',
+ 'addl_from' => $addl_from,
};
# <TH>Service #<BR><FONT SIZE=-1>(click to view forward)</FONT></TH>
@@ -100,16 +103,19 @@ my $link_cust = sub {
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
+ 'Service',
'Mail to',
'Forwards to',
FS::UI::Web::cust_header(),
],
'fields' => [ 'svcnum',
+ 'svc',
$format_src,
$format_dst,
\&FS::UI::Web::cust_fields,
],
'links' => [ $link,
+ $link,
$link_src,
$link_dst,
( map { $link_cust }