template forward search using the standard search template: forwards are now paged
[freeside.git] / httemplate / search / svc_forward.cgi
1 <%
2
3 my $conf = new FS::Conf;
4
5 my($query)=$cgi->keywords;
6 $query ||= ''; #to avoid use of unitialized value errors
7 my($orderby);
8 if ( $query eq 'svcnum' ) {
9   $orderby = 'ORDER BY svcnum';
10 } else {
11   eidiot('unimplemented');
12 }
13
14 my $count_query = 'SELECT COUNT(*) FROM svc_forward';
15 my $sql_query = {
16   'table'     => 'svc_forward',
17   'hashref'   => {},
18   'extra_sql' => $orderby,
19 };
20
21 #        <TH>Service #<BR><FONT SIZE=-1>(click to view forward)</FONT></TH>
22 #        <TH>Mail to<BR><FONT SIZE=-1>(click to view account)</FONT></TH>
23 #        <TH>Forwards to<BR><FONT SIZE=-1>(click to view account)</FONT></TH>
24
25 my $link = [ "${p}/view/svc_forward.cgi?", 'svcnum' ];
26
27 my $format_src = sub {
28   my $svc_forward = shift;
29   if ( $svc_forward->srcsvc_acct ) {
30     $svc_forward->srcsvc_acct->email;
31   } else {
32     my $src = $svc_forward->src;
33     $src = "<I>(anything)</I>$src" if $src =~ /^@/;
34     $src;
35   }
36 };
37
38 my $link_src = sub {
39   my $svc_forward = shift;
40   if ( $svc_forward->srcsvc_acct ) {
41     [ "${p}view/svc_acct.cgi?", 'srcsvc' ];
42   } else {
43     '';
44   }
45 };
46
47 my $format_dst = sub {
48   my $svc_forward = shift;
49   if ( $svc_forward->dstsvc_acct ) {
50     $svc_forward->dstsvc_acct->email;
51   } else {
52     $svc_forward->dst;
53   }
54 };
55
56 my $link_dst = sub {
57   my $svc_forward = shift;
58   if ( $svc_forward->dstsvc_acct ) {
59     [ "${p}view/svc_acct.cgi?", 'dstsvc' ];
60   } else {
61     '';
62   }
63 };
64
65 #this would quite a bit more efficient as a left join as part of the main query
66 my $format_cust = sub {
67   my $svc_forward = shift;
68   my $cust_pkg = $svc_forward->cust_svc->cust_pkg;
69   if ( $cust_pkg ) {
70     $cust_pkg->cust_main->name;
71   } else {
72     '';
73   }
74 };
75
76 my $link_cust = sub {
77   my $svc_forward = shift;
78   my $cust_pkg = $svc_forward->cust_svc->cust_pkg;
79   if ( $cust_pkg ) {
80     [ "${p}view/cust_main.cgi?", sub { shift->cust_svc->cust_pkg->custnum } ];
81   } else {
82     '';
83   }
84 };
85
86 %><%= include ('elements/search.html',
87                  'title'             => "Mail forward Search Results",
88                  'name'              => 'mail forwards',
89                  'query'             => $sql_query,
90                  'count_query'       => $count_query,
91                  'redirect'          => $link,
92                  'header'            => [ '#',
93                                           'Mail to',
94                                           'Forwards to',
95                                           'Customer',
96                                         ],
97                  'fields'            => [ 'svcnum',
98                                           $format_src,
99                                           $format_dst,
100                                           $format_cust,
101                                         ],
102                  'links'             => [ $link,
103                                           $link_src,
104                                           $link_dst,
105                                           $link_cust,
106                                         ],
107               )
108 %>