Revert "RT# 39340 - configured the minimal selfservice to get mac address from radius...
[freeside.git] / httemplate / search / svc_www.cgi
1 <& elements/svc_Common.html,
2                  'title'       => 'Virtual Host Search Results',
3                  'name'        => 'virtual hosts',
4                  'query'       => $sql_query,
5                  'count_query' => $count_query,
6                  'redirect'    => $link,
7                  'header'      => [ '#',
8                                     'Service',
9                                     'Zone',
10                                     'User',
11                                     emt('Pkg. Status'),
12                                     FS::UI::Web::cust_header(),
13                                   ],
14                  'fields'      => [ 'svcnum',
15                                     'svc',
16                                     sub { $_[0]->domain_record->zone },
17                                     sub {
18                                           my $svc_www = shift;
19                                           my $svc_acct = $svc_www->svc_acct;
20                                           $svc_acct
21                                             ? $svc_acct->email
22                                             : '';
23                                         },
24                                     sub {
25                                       $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
26                                       return '' unless $cust_pkg_cache{$_[0]->svcnum};
27                                       $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
28                                     },
29                                     \&FS::UI::Web::cust_fields,
30                                   ],
31                  'links'       => [ $link,
32                                     $link,
33                                     '',
34                                     $ulink,
35                                     '', # pkg status
36                                     ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
37                                           FS::UI::Web::cust_header()
38                                     ),
39                                   ],
40                  'align' => 'rlllr'. FS::UI::Web::cust_aligns(),
41                  'color' => [ 
42                               '',
43                               '',
44                               '',
45                               '',
46                               sub {
47                                 $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
48                                 return '' unless $cust_pkg_cache{$_[0]->svcnum};
49                                 my $c = FS::cust_pkg::statuscolors;
50                                 $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
51                               }, # pkg status
52                               FS::UI::Web::cust_colors(),
53                             ],
54                  'style' => [ 
55                               '',
56                               '',
57                               '',
58                               '',
59                               'b',
60                               FS::UI::Web::cust_styles(),
61                             ],
62              
63 &>
64 <%init>
65
66 die "access denied"
67   unless $FS::CurrentUser::CurrentUser->access_right('List services');
68
69 my %cust_pkg_cache;
70
71 #my $conf = new FS::Conf;
72
73 my $orderby = 'ORDER BY svcnum';
74 my @extra_sql = ();
75 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
76
77   push @extra_sql, 'pkgnum IS NULL'
78     if $cgi->param('magic') eq 'unlinked';
79
80   if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
81     my $sortby = $1;
82     $orderby = "ORDER BY $sortby";
83   }
84
85 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
86   push @extra_sql, "svcpart = $1";
87   if (defined($cgi->param('cancelled'))) {
88     if ($cgi->param('cancelled')) {
89       push @extra_sql, "cust_pkg.cancel IS NOT NULL";
90     } else {
91       push @extra_sql, "cust_pkg.cancel IS NULL";
92     }
93   }
94 }
95
96 my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
97                 ' LEFT JOIN part_svc  USING ( svcpart ) '.
98                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
99                 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
100
101 #here is the agent virtualization
102 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
103                    'null_right' => 'View/link unlinked services'
104                  );
105
106 my $extra_sql = 
107   scalar(@extra_sql)
108     ? ' WHERE '. join(' AND ', @extra_sql )
109     : '';
110
111
112 my $count_query = "SELECT COUNT(*) FROM svc_www $addl_from $extra_sql";
113 my $sql_query = {
114   'table'     => 'svc_www',
115   'hashref'   => {},
116   'select'    => join(', ',
117                    'svc_www.*',
118                    'part_svc.svc',
119                    'cust_main.custnum',
120                    FS::UI::Web::cust_sql_fields(),
121                  ),
122   'extra_sql' => $extra_sql,
123   'order_by'  => $orderby,
124   'addl_from' => $addl_from,
125 };
126
127 my $link  = [ "${p}view/svc_www.cgi?", 'svcnum', ];
128 #my $dlink = [ "${p}view/svc_www.cgi?", 'svcnum', ];
129 my $ulink = [ "${p}view/svc_acct.cgi?", 'usersvc', ];
130
131 #smaller false laziness w/svc_*.cgi here
132 my $link_cust = sub {
133   my $svc_x = shift;
134   $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';
135 };
136
137 </%init>