default to a session cookie instead of setting an explicit timeout, weird timezone...
[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     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="font-size: smaller;">Required</TH>
65
66   </TR>
67 % foreach my $part_svc ( @part_svc ) {
68 %     my $svcdb = $part_svc->svcdb;
69 %     my $svc_x = "FS::$svcdb"->new( { svcpart => $part_svc->svcpart } );
70 %     my @dfields = $svc_x->fields;
71 %     push @dfields, 'usergroup' if $svcdb eq 'svc_acct' #double kludge
72 %                                or ($svcdb eq 'svc_broadband' 
73 %                                    and $conf->exists('svc_broadband-radius'));
74 %     my @fields =
75 %       grep { my $col = $part_svc->part_svc_column($_);
76 %              my $def = FS::part_svc->svc_table_fields($svcdb)->{$_};
77 %              $svc_x->pvf($_)
78 %              or $_ ne 'svcnum' && (
79 %                $col->columnflag || ( $col->columnlabel !~ /^\S*$/
80 %                                      && $col->columnlabel ne $def->{'label'}
81 %                                    )
82 %                                 || ( $col->required
83 %                                      && !$def->{'required'}
84 %                                    )
85 %              )
86 %            }
87 %            @dfields ;
88 %     my $rowspan = scalar(@fields) || 1;
89 %     $rowspan++ if $part_svc->restrict_edit_password;
90 %     my $url = "${p}edit/part_svc.cgi?". $part_svc->svcpart;
91 %
92 %     if ( $bgcolor eq $bgcolor1 ) {
93 %       $bgcolor = $bgcolor2;
94 %     } else {
95 %       $bgcolor = $bgcolor1;
96 %     }
97
98
99   <TR>
100
101     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
102       <A HREF="<% $url %>"><% $part_svc->svcpart %></A>
103     </TD>
104
105 % if ( $cgi->param('showdisabled') ) { 
106     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
107       <% $part_svc->disabled
108             ? '<FONT COLOR="#FF0000"><B>Disabled</B></FONT>'
109             : '<FONT COLOR="#00CC00"><B>Enabled</B></FONT>'
110       %>
111     </TD>
112 % } 
113
114     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
115       <A HREF="<% $url %>">
116         <% $part_svc->svc %>
117       </A>
118 %   # any alternate names of the service
119 %   my %msgcat = map { $_->locale => $_ } $part_svc->part_svc_msgcat;
120 %   my %labels = map { $_ => FS::Locales->description($_) } keys %msgcat;
121 %   my @locales = sort { $labels{$a} cmp $labels{$b} } keys %msgcat;
122 %   if ( @locales ) {
123       <BR>
124       <FONT SIZE="-1">
125 %     foreach my $locale (@locales) {
126         <% $labels{$locale} %>: <% $msgcat{$locale}->get('svc') %>
127         <BR>
128 %     }
129       </FONT>
130 %   }
131     </TD>
132
133     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
134       <% $svcdb %></TD>
135
136     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
137 % my $svcurl_active = svc_url( 'ahref' => 1, 'm' => $m, 'action' => 'search', 'part_svc' => $part_svc, 'query' => "svcpart=". $part_svc->svcpart . "&cancelled=0");
138 % my $svcurl_cancel = svc_url( 'ahref' => 1, 'm' => $m, 'action' => 'search', 'part_svc' => $part_svc, 'query' => "svcpart=". $part_svc->svcpart . "&cancelled=1");
139       <FONT COLOR="#00CC00"><B><% $num_cust_svc_active{$part_svc->svcpart} %></B></FONT>&nbsp;<% $num_cust_svc_active{$part_svc->svcpart} || $disable_counts ? $svcurl_active : '' %>active<% $num_cust_svc_active{$part_svc->svcpart} || $disable_counts ? '</A>' : '' %>
140 % if ( $num_cust_svc_cancelled{$part_svc->svcpart} || $disable_counts ) {
141         <BR><FONT COLOR="#FF0000"><B><% $num_cust_svc_cancelled{$part_svc->svcpart} %></B></FONT>&nbsp;<% $svcurl_cancel %>cancelled</A>
142 % }
143 % if ( $num_cust_svc{$part_svc->svcpart} || $disable_counts ) {
144         <BR><FONT SIZE="-1"><nobr>[ <A HREF="<%$p%>edit/bulk-cust_svc.html?svcpart=<% $part_svc->svcpart %>">change</A> ]</nobr></FONT>
145 % } 
146
147     </TD>
148
149 % tie my %selfservice_access, 'Tie::IxHash', #false laziness w/edit/part_svc.cgi
150 %   ''         => 'Yes',
151 %   'hidden'   => 'Hidden',
152 %   'readonly' => 'Read-only',
153 % ;
154     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
155       <% $selfservice_access{$part_svc->selfservice_access} %></TD>
156
157     <TD ROWSPAN=<% $rowspan %> CLASS="inv" BGCOLOR="<% $bgcolor %>">
158       <TABLE CLASS="inv">
159 %
160 %#  my @part_export =
161 %map { qsearchs('part_export', { exportnum => $_->exportnum } ) } qsearch('export_svc', { svcpart => $part_svc->svcpart } ) ;
162 %  foreach my $part_export (
163 %    map { qsearchs('part_export', { exportnum => $_->exportnum } ) } 
164 %      qsearch('export_svc', { svcpart => $part_svc->svcpart } )
165 %  ) {
166 %
167
168         <TR>
169           <TD><A HREF="<% $p %>edit/part_export.cgi?<% $part_export->exportnum %>"><% $part_export->label_html %></A></TD>
170         </TR>
171 %  } 
172
173       </TABLE>
174     </TD>
175
176 %     unless ( @fields ) {
177 %       for ( 1..5 ) {  
178           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"</TD>
179 %       }
180 %     }
181 %   
182 %     my($n1)='';
183 %     foreach my $field ( sort @fields ) {
184 %
185 %       #a few lines of false laziness w/edit/part_svc.cgi
186 %       my $def = FS::part_svc->svc_table_fields($svcdb)->{$field};
187 %       my $formatter = $def->{format} || sub { shift };
188 %
189 %       my $part_svc_column = $part_svc->part_svc_column($field);
190 %       my $label = $part_svc_column->columnlabel || $def->{'label'};
191 %       my $flag = $part_svc_column->columnflag;
192
193      <% $n1 %>
194      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $field %></TD>
195      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $label %></TD>
196      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $flag{$flag} %></TD>
197      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
198 % my $value = &$formatter($part_svc->part_svc_column($field)->columnvalue);
199 % if ( $flag =~ /^[MAH]$/ ) { 
200 %   my $select_table = ($flag eq 'H') ? 'hardware_class' : 'inventory_class';
201 %   foreach my $classnum ( split(',', $value) ) {
202 %     $select_class{$classnum} =
203 %       qsearchs($select_table, { 'classnum' => $classnum } );
204
205       <% $select_class{$classnum}
206             ? $select_class{$classnum}->classname
207             : "WARNING: $select_table.classnum $classnum not found" %><BR>
208 %   }
209 % } else { 
210
211             <% $value %>
212 % }
213
214      </TD>
215      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
216 % if ($part_svc_column->required) {
217        Yes
218 % }
219      </TD>
220 %     $n1="</TR><TR>";
221 %     } #foreach $field
222 %   if ( $part_svc->restrict_edit_password ) {
223    <TR>
224      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" COLSPAN=4 ALIGN="left">
225       <B><% emt('Password editing restricted.') %></B>
226      </TD>
227    </TR>
228 %   }
229
230   </TR>
231 % }  #foreach $part_svc
232
233 </TABLE>
234 </BODY>
235 </HTML>
236 <%init>
237  
238 die "access denied"
239   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
240
241 my $conf = FS::Conf->new;
242 my $disable_counts = $conf->exists('config-disable_counts') ? 1 : 0;
243
244 #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
245 my %flag = (
246   ''  => '',
247   'D' => 'Default',
248   'F' => 'Fixed (unchangeable)',
249   'S' => 'Selectable choice',
250   #'M' => 'Manual selection from inventory',
251   'M' => 'Manual selected from inventory',
252   #'A' => 'Automatically fill in from inventory',
253   'A' => 'Automatically filled in from inventory',
254   'H' => 'Selected from hardware class',
255   'X' => 'Excluded',
256   'P' => 'From package 477 information',
257 );
258
259 my %search;
260 if ( $cgi->param('showdisabled') ) {
261   %search = ();
262 } else {
263   %search = ( 'disabled' => '' );
264 }
265
266 my @part_svc =
267   sort { $a->getfield('svcpart') <=> $b->getfield('svcpart') }
268     qsearch('part_svc', \%search );
269 my $total = scalar(@part_svc);
270
271 ## The Active/Cancelled distinction is a bit awkward,
272 ## active currently includes unattached and suspended services,
273 ## but we've previously referred to EVERY existing cust_svc as "Active",
274 ## and we don't really want to know numbers by individual package status,
275 ## so for now the UI will distinguish these as "Active" and "Cancelled",
276 ## but please let's not go so far as to introduce the idea of "Service Status"
277
278 my %num_cust_svc_active;
279 my %num_cust_svc_cancelled;
280 my %num_cust_svc;
281
282 unless ( $disable_counts ) {
283   foreach my $part_svc (@part_svc) {
284     $num_cust_svc{$part_svc->svcpart} = $part_svc->num_cust_svc;
285     $num_cust_svc_cancelled{$part_svc->svcpart} = $part_svc->num_cust_svc_cancelled;
286     $num_cust_svc_active{$part_svc->svcpart} = $num_cust_svc{$part_svc->svcpart} - $num_cust_svc_cancelled{$part_svc->svcpart};
287   }
288 }
289
290 if ( $cgi->param('orderby') eq 'active' ) {
291   @part_svc = sort { $num_cust_svc{$b->svcpart} <=>
292                      $num_cust_svc{$a->svcpart}     } @part_svc;
293 } elsif ( $cgi->param('orderby') eq 'svc' ) { 
294   @part_svc = sort { lc($a->svc) cmp lc($b->svc) } @part_svc;
295 }
296
297 my %select_class = ();
298
299 </%init>