1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<& elements/search.html,
'title' => $part_svc->svc.' services in package #'.$pkgnum,
'name' => 'services',
'html_form' => $html_form,
'query' => $sql_query,
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
'Service',
'', #checkboxes
],
'fields' => [ 'svcnum',
sub {
($_[0]->label)[1]
},
sub {
$areboxes = 1;
'<INPUT TYPE="checkbox" NAME="svcnum" VALUE='.$_[0]->svcnum.'>'
},
],
'links' => [ $link,
$link,
'',
],
'align' => 'rrlc',
'color' => [
('')x4,
],
'style' => [
('')x4,
],
'html_foot' => sub { $areboxes ? $html_foot : '' }
&>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('List services');
my $pkgnum = $cgi->param('pkgnum');
$pkgnum =~ /^(\d+)$/ or die "invalid pkgnum: $pkgnum";
my @extra_sql = ( "cust_svc.pkgnum = $pkgnum" );
my $svcpart = $cgi->param('svcpart');
$svcpart =~ /^(\d+)$/ or die "invalid svcpart: $svcpart";
push @extra_sql, "cust_svc.svcpart = $svcpart";
my $part_svc = qsearchs('part_svc', {svcpart => $svcpart});
my $svcdb = $part_svc->svcdb;
my $orderby = 'ORDER BY svcnum'; #others?
my $addl_from = " LEFT JOIN part_svc USING (svcpart)
LEFT JOIN cust_pkg USING (pkgnum)
LEFT JOIN cust_main USING (custnum)
INNER JOIN $svcdb USING (svcnum)";
my $search_string;
if ( length( $cgi->param('search_svc') ) ) {
$search_string = $cgi->param('search_svc');
$search_string =~ s/(^\s+|\s+$)//;
push @extra_sql, "FS::$svcdb"->search_sql($search_string);
}
#here is the agent virtualization
push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
'null_right' => 'View/link unlinked services'
);
my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
my $sql_query = {
'select' => join(', ',
'cust_svc.*',
'part_svc.svc',
),
'table' => 'cust_svc',
'addl_from' => $addl_from,
'hashref' => {},
'extra_sql' => $extra_sql,
'order_by' => $orderby,
};
#warn Dumper($sql_query)."\n";
my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql";
my $link = sub {
my $cust_svc = shift;
my $url = svc_url(
'm' => $m,
'action' => 'view',
'svcdb' => $svcdb,
'query' => '',
);
[ $url, 'svcnum' ];
};
my $html_form = qq!
<SCRIPT TYPE="text/javascript">
function areyousure(obj) {
return confirm('Permanently delete the selected services?');
}
</SCRIPT>
<FORM METHOD="POST" ACTION="${p}misc/unprovision.cgi" onsubmit="return areyousure()">!;
my $areboxes = 0;
my $html_foot = qq!
<BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Unprovision selected">
<INPUT TYPE="hidden" NAME="pkgnum" VALUE=$pkgnum>
<INPUT TYPE="hidden" NAME="svcpart" VALUE=$svcpart>
</FORM>!;
</%init>
|