RADIUS groups for svc_broadband, #14695
[freeside.git] / httemplate / browse / part_svc.cgi
1 <% include('/elements/header.html', 'Service Definition Listing') %>
2
3 <SCRIPT>
4 function part_export_areyousure(href) {
5   if (confirm("Are you sure you want to delete this export?") == true)
6     window.location.href = href;
7 }
8 </SCRIPT>
9
10     Service definitions are the templates for items you offer to your customers.<BR><BR>
11
12 <FORM METHOD="POST" ACTION="<% $p %>edit/part_svc.cgi">
13 <A HREF="<% $p %>edit/part_svc.cgi"><I>Add a new service definition</I></A>
14 % if ( @part_svc ) { 
15 &nbsp;or&nbsp;<SELECT NAME="clone"><OPTION></OPTION>
16 % foreach my $part_svc ( @part_svc ) { 
17
18   <OPTION VALUE="<% $part_svc->svcpart %>"><% $part_svc->svc %></OPTION>
19 % } 
20
21 </SELECT><INPUT TYPE="submit" VALUE="Clone existing service">
22 % } 
23
24 </FORM><BR>
25
26 <% $total %> service definitions
27 <% $cgi->param('showdisabled')
28       ? do { $cgi->param('showdisabled', 0);
29              '( <a href="'. $cgi->self_url. '">hide disabled services</a> )'; }
30       : do { $cgi->param('showdisabled', 1);
31              '( <a href="'. $cgi->self_url. '">show disabled services</a> )'; }
32 %>
33 % $cgi->param('showdisabled', ( 1 ^ $cgi->param('showdisabled') ) ); 
34
35 <% include('/elements/table-grid.html') %>
36 %   my $bgcolor1 = '#eeeeee';
37 %   my $bgcolor2 = '#ffffff';
38 %   my $bgcolor = '';
39
40   <TR>
41
42     <TH CLASS="grid" BGCOLOR="#cccccc"><A HREF="<% do { $cgi->param('orderby', 'svcpart'); $cgi->self_url } %>">#</A></TH>
43
44 % if ( $cgi->param('showdisabled') ) { 
45       <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
46 % } 
47
48     <TH CLASS="grid" BGCOLOR="#cccccc"><A HREF="<% do { $cgi->param('orderby', 'svc'); $cgi->self_url; } %>">Service</A></TH>
49
50     <TH CLASS="grid" BGCOLOR="#cccccc">Table</TH>
51
52     <TH CLASS="grid" BGCOLOR="#cccccc"><A HREF="<% do { $cgi->param('orderby', 'active'); $cgi->self_url; } %>"><FONT SIZE=-1>Customer<BR>Services</FONT></A></TH>
53
54     <TH CLASS="grid" BGCOLOR="#cccccc">Export</TH>
55
56     <TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>
57
58     <TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>
59
60     <TH COLSPAN=2 CLASS="grid" BGCOLOR="#cccccc">Modifier</TH>
61
62   </TR>
63 % my $conf = FS::Conf->new;
64 % foreach my $part_svc ( @part_svc ) {
65 %     my $svcdb = $part_svc->svcdb;
66 %     my $svc_x = "FS::$svcdb"->new( { svcpart => $part_svc->svcpart } );
67 %     my @dfields = $svc_x->fields;
68 %     push @dfields, 'usergroup' if $svcdb eq 'svc_acct' #double kludge
69 %                                or ($svcdb eq 'svc_broadband' 
70 %                                    and $conf->exists('svc_broadband-radius'));
71 %     my @fields =
72 %       grep { my $col = $part_svc->part_svc_column($_);
73 %              my $def = FS::part_svc->svc_table_fields($svcdb)->{$_};
74 %              $svc_x->pvf($_)
75 %              or $_ ne 'svcnum' && (
76 %                $col->columnflag || ( $col->columnlabel !~ /^\S*$/
77 %                                      && $col->columnlabel ne $def->{'label'}
78 %                                    )
79 %              )
80 %            }
81 %            @dfields ;
82 %     my $rowspan = scalar(@fields) || 1;
83 %     my $url = "${p}edit/part_svc.cgi?". $part_svc->svcpart;
84 %
85 %     if ( $bgcolor eq $bgcolor1 ) {
86 %       $bgcolor = $bgcolor2;
87 %     } else {
88 %       $bgcolor = $bgcolor1;
89 %     }
90
91
92   <TR>
93
94     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
95       <A HREF="<% $url %>"><% $part_svc->svcpart %></A>
96     </TD>
97
98 % if ( $cgi->param('showdisabled') ) { 
99     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
100       <% $part_svc->disabled
101             ? '<FONT COLOR="#FF0000"><B>Disabled</B></FONT>'
102             : '<FONT COLOR="#00CC00"><B>Enabled</B></FONT>'
103       %>
104     </TD>
105 % } 
106
107     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<% $url %>">
108       <% $part_svc->svc %></A></TD>
109
110     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
111       <% $svcdb %></TD>
112
113     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
114       <FONT COLOR="#00CC00"><B><% $num_active_cust_svc{$part_svc->svcpart} %></B></FONT>&nbsp;<% $num_active_cust_svc{$part_svc->svcpart} ? svc_url( 'ahref' => 1, 'm' => $m, 'action' => 'search', 'part_svc' => $part_svc, 'query' => "svcpart=". $part_svc->svcpart ) : '<A NAME="zero">' %>active</A>
115
116 % if ( $num_active_cust_svc{$part_svc->svcpart} ) { 
117         <BR><FONT SIZE="-1">[ <A HREF="<%$p%>edit/bulk-cust_svc.html?svcpart=<% $part_svc->svcpart %>">change</A> ]</FONT>
118 % } 
119
120     </TD>
121
122     <TD ROWSPAN=<% $rowspan %> CLASS="inv" BGCOLOR="<% $bgcolor %>">
123       <TABLE CLASS="inv">
124 %
125 %#  my @part_export =
126 %map { qsearchs('part_export', { exportnum => $_->exportnum } ) } qsearch('export_svc', { svcpart => $part_svc->svcpart } ) ;
127 %  foreach my $part_export (
128 %    map { qsearchs('part_export', { exportnum => $_->exportnum } ) } 
129 %      qsearch('export_svc', { svcpart => $part_svc->svcpart } )
130 %  ) {
131 %
132
133         <TR>
134           <TD><A HREF="<% $p %>edit/part_export.cgi?<% $part_export->exportnum %>">
135 <% $part_export->exportnum %>:&nbsp;
136 % if ($part_export->exportname) {
137 <B><% $part_export->exportname %></B> (
138 % }
139 <% $part_export->exporttype %>&nbsp;to&nbsp;<% $part_export->machine %>
140 % if ($part_export->exportname) {
141 )
142 % }
143 </A></TD>
144         </TR>
145 %  } 
146
147       </TABLE>
148     </TD>
149
150 %     unless ( @fields ) {
151 %       for ( 1..4 ) {  
152           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"</TD>
153 %       }
154 %     }
155 %   
156 %     my($n1)='';
157 %     foreach my $field ( @fields ) {
158 %
159 %       #a few lines of false laziness w/edit/part_svc.cgi
160 %       my $def = FS::part_svc->svc_table_fields($svcdb)->{$field};
161 %       my $formatter = $def->{format} || sub { shift };
162 %
163 %       my $part_svc_column = $part_svc->part_svc_column($field);
164 %       my $label = $part_svc_column->columnlabel || $def->{'label'};
165 %       my $flag = $part_svc_column->columnflag;
166
167      <% $n1 %>
168      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $field %></TD>
169      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $label %></TD>
170      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $flag{$flag} %></TD>
171
172      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
173 % my $value = &$formatter($part_svc->part_svc_column($field)->columnvalue);
174 % if ( $flag =~ /^[MAH]$/ ) { 
175 %   my $select_table = ($flag eq 'H') ? 'hardware_class' : 'inventory_class';
176 %   $select_class{$value} ||= 
177 %       qsearchs($select_table, { 'classnum' => $value } );
178
179             <% $select_class{$value}
180                   ? $select_class{$value}->classname
181                   : "WARNING: $select_table.classnum $value not found" %>
182 % } else { 
183
184             <% $value %>
185 % } 
186
187      </TD>
188 %     $n1="</TR><TR>";
189 %     }
190 %
191
192   </TR>
193 % } 
194
195 </TABLE>
196 </BODY>
197 </HTML>
198 <%init>
199  
200 die "access denied"
201   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
202
203 #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
204 my %flag = (
205   ''  => '',
206   'D' => 'Default',
207   'F' => 'Fixed (unchangeable)',
208   'S' => 'Selectable choice',
209   #'M' => 'Manual selection from inventory',
210   'M' => 'Manual selected from inventory',
211   #'A' => 'Automatically fill in from inventory',
212   'A' => 'Automatically filled in from inventory',
213   'H' => 'Selected from hardware class',
214   'X' => 'Excluded',
215 );
216
217 my %search;
218 if ( $cgi->param('showdisabled') ) {
219   %search = ();
220 } else {
221   %search = ( 'disabled' => '' );
222 }
223
224 my @part_svc =
225   sort { $a->getfield('svcpart') <=> $b->getfield('svcpart') }
226     qsearch('part_svc', \%search );
227 my $total = scalar(@part_svc);
228
229 my %num_active_cust_svc = map { $_->svcpart => $_->num_cust_svc } @part_svc;
230
231 if ( $cgi->param('orderby') eq 'active' ) {
232   @part_svc = sort { $num_active_cust_svc{$b->svcpart} <=>
233                      $num_active_cust_svc{$a->svcpart}     } @part_svc;
234 } elsif ( $cgi->param('orderby') eq 'svc' ) { 
235   @part_svc = sort { lc($a->svc) cmp lc($b->svc) } @part_svc;
236 }
237
238 my %select_class = ();
239
240 </%init>