add selfservice_access selection to part_svc, RT#15628
[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"><FONT SIZE=-1>Customer<BR>Self-service</FONT></TH>
55
56     <TH CLASS="grid" BGCOLOR="#cccccc">Export</TH>
57
58     <TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>
59
60     <TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>
61
62     <TH COLSPAN=2 CLASS="grid" BGCOLOR="#cccccc">Modifier</TH>
63
64   </TR>
65 % my $conf = FS::Conf->new;
66 % foreach my $part_svc ( @part_svc ) {
67 %     my $svcdb = $part_svc->svcdb;
68 %     my $svc_x = "FS::$svcdb"->new( { svcpart => $part_svc->svcpart } );
69 %     my @dfields = $svc_x->fields;
70 %     push @dfields, 'usergroup' if $svcdb eq 'svc_acct' #double kludge
71 %                                or ($svcdb eq 'svc_broadband' 
72 %                                    and $conf->exists('svc_broadband-radius'));
73 %     my @fields =
74 %       grep { my $col = $part_svc->part_svc_column($_);
75 %              my $def = FS::part_svc->svc_table_fields($svcdb)->{$_};
76 %              $svc_x->pvf($_)
77 %              or $_ ne 'svcnum' && (
78 %                $col->columnflag || ( $col->columnlabel !~ /^\S*$/
79 %                                      && $col->columnlabel ne $def->{'label'}
80 %                                    )
81 %              )
82 %            }
83 %            @dfields ;
84 %     my $rowspan = scalar(@fields) || 1;
85 %     my $url = "${p}edit/part_svc.cgi?". $part_svc->svcpart;
86 %
87 %     if ( $bgcolor eq $bgcolor1 ) {
88 %       $bgcolor = $bgcolor2;
89 %     } else {
90 %       $bgcolor = $bgcolor1;
91 %     }
92
93
94   <TR>
95
96     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
97       <A HREF="<% $url %>"><% $part_svc->svcpart %></A>
98     </TD>
99
100 % if ( $cgi->param('showdisabled') ) { 
101     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
102       <% $part_svc->disabled
103             ? '<FONT COLOR="#FF0000"><B>Disabled</B></FONT>'
104             : '<FONT COLOR="#00CC00"><B>Enabled</B></FONT>'
105       %>
106     </TD>
107 % } 
108
109     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<% $url %>">
110       <% $part_svc->svc %></A></TD>
111
112     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
113       <% $svcdb %></TD>
114
115     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
116       <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>
117
118 % if ( $num_active_cust_svc{$part_svc->svcpart} ) { 
119         <BR><FONT SIZE="-1">[ <A HREF="<%$p%>edit/bulk-cust_svc.html?svcpart=<% $part_svc->svcpart %>">change</A> ]</FONT>
120 % } 
121
122     </TD>
123
124 % tie my %selfservice_access, 'Tie::IxHash', #false laziness w/edit/part_svc.cgi
125 %   ''         => 'Yes',
126 %   'hidden'   => 'Hidden',
127 %   'readonly' => 'Read-only',
128 % ;
129     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
130       <% $selfservice_access{$part_svc->selfservice_access} %></TD>
131
132     <TD ROWSPAN=<% $rowspan %> CLASS="inv" BGCOLOR="<% $bgcolor %>">
133       <TABLE CLASS="inv">
134 %
135 %#  my @part_export =
136 %map { qsearchs('part_export', { exportnum => $_->exportnum } ) } qsearch('export_svc', { svcpart => $part_svc->svcpart } ) ;
137 %  foreach my $part_export (
138 %    map { qsearchs('part_export', { exportnum => $_->exportnum } ) } 
139 %      qsearch('export_svc', { svcpart => $part_svc->svcpart } )
140 %  ) {
141 %
142
143         <TR>
144           <TD><A HREF="<% $p %>edit/part_export.cgi?<% $part_export->exportnum %>">
145 <% $part_export->exportnum %>:&nbsp;
146 % if ($part_export->exportname) {
147 <B><% $part_export->exportname %></B> (
148 % }
149 <% $part_export->exporttype %>&nbsp;to&nbsp;<% $part_export->machine %>
150 % if ($part_export->exportname) {
151 )
152 % }
153 </A></TD>
154         </TR>
155 %  } 
156
157       </TABLE>
158     </TD>
159
160 %     unless ( @fields ) {
161 %       for ( 1..4 ) {  
162           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"</TD>
163 %       }
164 %     }
165 %   
166 %     my($n1)='';
167 %     foreach my $field ( @fields ) {
168 %
169 %       #a few lines of false laziness w/edit/part_svc.cgi
170 %       my $def = FS::part_svc->svc_table_fields($svcdb)->{$field};
171 %       my $formatter = $def->{format} || sub { shift };
172 %
173 %       my $part_svc_column = $part_svc->part_svc_column($field);
174 %       my $label = $part_svc_column->columnlabel || $def->{'label'};
175 %       my $flag = $part_svc_column->columnflag;
176
177      <% $n1 %>
178      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $field %></TD>
179      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $label %></TD>
180      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $flag{$flag} %></TD>
181
182      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
183 % my $value = &$formatter($part_svc->part_svc_column($field)->columnvalue);
184 % if ( $flag =~ /^[MAH]$/ ) { 
185 %   my $select_table = ($flag eq 'H') ? 'hardware_class' : 'inventory_class';
186 %   $select_class{$value} ||= 
187 %       qsearchs($select_table, { 'classnum' => $value } );
188
189             <% $select_class{$value}
190                   ? $select_class{$value}->classname
191                   : "WARNING: $select_table.classnum $value not found" %>
192 % } else { 
193
194             <% $value %>
195 % } 
196
197      </TD>
198 %     $n1="</TR><TR>";
199 %     }
200 %
201
202   </TR>
203 % } 
204
205 </TABLE>
206 </BODY>
207 </HTML>
208 <%init>
209  
210 die "access denied"
211   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
212
213 #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
214 my %flag = (
215   ''  => '',
216   'D' => 'Default',
217   'F' => 'Fixed (unchangeable)',
218   'S' => 'Selectable choice',
219   #'M' => 'Manual selection from inventory',
220   'M' => 'Manual selected from inventory',
221   #'A' => 'Automatically fill in from inventory',
222   'A' => 'Automatically filled in from inventory',
223   'H' => 'Selected from hardware class',
224   'X' => 'Excluded',
225 );
226
227 my %search;
228 if ( $cgi->param('showdisabled') ) {
229   %search = ();
230 } else {
231   %search = ( 'disabled' => '' );
232 }
233
234 my @part_svc =
235   sort { $a->getfield('svcpart') <=> $b->getfield('svcpart') }
236     qsearch('part_svc', \%search );
237 my $total = scalar(@part_svc);
238
239 my %num_active_cust_svc = map { $_->svcpart => $_->num_cust_svc } @part_svc;
240
241 if ( $cgi->param('orderby') eq 'active' ) {
242   @part_svc = sort { $num_active_cust_svc{$b->svcpart} <=>
243                      $num_active_cust_svc{$a->svcpart}     } @part_svc;
244 } elsif ( $cgi->param('orderby') eq 'svc' ) { 
245   @part_svc = sort { lc($a->svc) cmp lc($b->svc) } @part_svc;
246 }
247
248 my %select_class = ();
249
250 </%init>