Will things ever be the same again?
[freeside.git] / httemplate / view / svc_acct.cgi
1 %
2 %
3 %my $conf = new FS::Conf;
4 %
5 %my($query) = $cgi->keywords;
6 %$query =~ /^(\d+)$/;
7 %my $svcnum = $1;
8 %my $svc_acct = qsearchs('svc_acct',{'svcnum'=>$svcnum});
9 %die "Unknown svcnum" unless $svc_acct;
10 %
11 %#false laziness w/all svc_*.cgi
12 %my $cust_svc = qsearchs( 'cust_svc' , { 'svcnum' => $svcnum } );
13 %my $pkgnum = $cust_svc->getfield('pkgnum');
14 %my($cust_pkg, $custnum);
15 %if ($pkgnum) {
16 %  $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } );
17 %  $custnum = $cust_pkg->custnum;
18 %} else {
19 %  $cust_pkg = '';
20 %  $custnum = '';
21 %}
22 %#eofalse
23 %
24 %my $part_svc = qsearchs('part_svc',{'svcpart'=> $cust_svc->svcpart } );
25 %die "Unknown svcpart" unless $part_svc;
26 %my $svc = $part_svc->svc;
27 %
28 %die 'Empty domsvc for svc_acct.svcnum '. $svc_acct->svcnum
29 %  unless $svc_acct->domsvc;
30 %my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $svc_acct->domsvc } );
31 %die 'Unknown domain (domsvc '. $svc_acct->domsvc.
32 %    ' for svc_acct.svcnum '. $svc_acct->svcnum. ')'
33 %  unless $svc_domain;
34 %my $domain = $svc_domain->domain;
35 %
36 %
37 % if ( $custnum ) { 
38
39
40   <% include("/elements/header.html","View $svc account", menubar(
41     "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
42     "Main menu" => $p,
43   )) %>
44
45   <% include( '/elements/small_custview.html', $custnum, '', 1 ) %>
46   <BR>
47 % } else { 
48
49
50   <SCRIPT>
51   function areyousure(href) {
52       if (confirm("Permanently delete this account?") == true)
53           window.location.href = href;
54   }
55   </SCRIPT>
56   
57   <% include("/elements/header.html",'Account View', menubar(
58     "Cancel this (unaudited) account" =>
59             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')",
60     "Main menu" => $p,
61   )) %>
62 % } 
63 % if ( $part_svc->part_export_usage ) {
64 %
65 %  my $last_bill;
66 %  my %plandata;
67 %  if ( $cust_pkg ) {
68 %    #false laziness w/httemplate/edit/part_pkg... this stuff doesn't really
69 %    #belong in plan data
70 %    %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
71 %                    split("\n", $cust_pkg->part_pkg->plandata );
72 %
73 %    $last_bill = $cust_pkg->last_bill;
74 %  } else {
75 %    $last_bill = 0;
76 %    %plandata = ();
77 %  }
78 %
79 %  my $seconds = $svc_acct->seconds_since_sqlradacct( $last_bill, time );
80 %  my $hour = int($seconds/3600);
81 %  my $min = int( ($seconds%3600) / 60 );
82 %  my $sec = $seconds%60;
83 %
84 %  my $input = $svc_acct->attribute_since_sqlradacct(
85 %    $last_bill, time, 'AcctInputOctets'
86 %  ) / 1048576;
87 %  my $output = $svc_acct->attribute_since_sqlradacct(
88 %    $last_bill, time, 'AcctOutputOctets'
89 %  ) / 1048576;
90 %
91 %
92
93
94   RADIUS session information<BR>
95   <% ntable('#cccccc',2) %>
96   <TR><TD BGCOLOR="#ffffff">
97 % if ( $seconds ) { 
98
99     Online <B><% $hour %></B>h <B><% $min %></B>m <B><% $sec %></B>s
100 % } else { 
101
102     Has not logged on
103 % } 
104 % if ( $cust_pkg ) { 
105
106     since last bill (<% time2str('%a %b %o %Y', $last_bill) %>)
107 % if ( length($plandata{recur_included_hours}) ) { 
108
109     - <% $plandata{recur_included_hours} %> total hours in plan
110 % } 
111
112     <BR>
113 % } else { 
114
115     (no billing cycle available for unaudited account)<BR>
116 % } 
117
118
119   Upload: <B><% sprintf("%.3f", $input) %></B> megabytes<BR>
120   Download: <B><% sprintf("%.3f", $output) %></B> megabytes<BR>
121 % my $href = qq!<A HREF="${p}search/sqlradius.cgi?svcnum=$svcnum!; 
122
123   View session detail:
124       <% $href %>;begin=<% $last_bill %>">this billing cycle</A>
125     | <% $href %>;begin=<% time-15552000 %>">past six months</A>
126     | <% $href %>">all sessions</A>
127
128   </TD></TR></TABLE><BR>
129 % } 
130
131
132 <SCRIPT TYPE="text/javascript">
133 function enable_change () {
134   if ( document.OneTrueForm.svcpart.selectedIndex > 1 ) {
135     document.OneTrueForm.submit.disabled = false;
136   } else {
137     document.OneTrueForm.submit.disabled = true;
138   }
139 }
140 </SCRIPT>
141 <FORM NAME="OneTrueForm" ACTION="<%$p%>edit/process/cust_svc.cgi">
142 <INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
143 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
144 % #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!; 
145
146 %  my @part_svc = ();
147 %  if ( $pkgnum ) { 
148 %    @part_svc = grep {    $_->svcdb   eq 'svc_acct'
149 %                       && $_->svcpart != $part_svc->svcpart }
150 %                $cust_pkg->available_part_svc;
151 %  } else {
152 %    @part_svc = qsearch('part_svc', {
153 %      svcdb    => 'svc_acct',
154 %      disabled => '',
155 %      svcpart  => { op=>'!=', value=>$part_svc->svcpart },
156 %    } );
157 %  }
158 %
159
160
161 Service #<B><% $svcnum %></B>
162 | <A HREF="<%$p%>edit/svc_acct.cgi?<%$svcnum%>">Edit this service</A>
163 % if ( @part_svc ) { 
164
165 | <SELECT NAME="svcpart" onChange="enable_change()">
166     <OPTION VALUE="">Change service</OPTION>
167     <OPTION VALUE="">--------------</OPTION>
168 % foreach my $opt_part_svc ( @part_svc ) { 
169
170       <OPTION VALUE="<% $opt_part_svc->svcpart %>"><% $opt_part_svc->svc %></OPTION>
171 % } 
172
173   </SELECT>
174   <INPUT NAME="submit" TYPE="submit" VALUE="Change" disabled>
175 % } 
176
177
178 <% &ntable("#cccccc") %><TR><TD><% &ntable("#cccccc",2) %>
179
180 <TR>
181   <TD ALIGN="right">Service</TD>
182   <TD BGCOLOR="#ffffff"><% $part_svc->svc %></TD>
183 </TR>
184 <TR>
185   <TD ALIGN="right">Username</TD>
186   <TD BGCOLOR="#ffffff"><% $svc_acct->username %></TD>
187 </TR>
188 <TR>
189   <TD ALIGN="right">Domain</TD>
190   <TD BGCOLOR="#ffffff"><% $domain %></TD>
191 </TR>
192
193 <TR>
194   <TD ALIGN="right">Password</TD>
195   <TD BGCOLOR="#ffffff">
196 % my $password = $svc_acct->_password; 
197 % if ( $password =~ /^\*\w+\* (.*)$/ ) {
198 %         $password = $1;
199 %    
200
201       <I>(login disabled)</I>
202 % } 
203 % if ( $conf->exists('showpasswords') ) { 
204
205       <PRE><% encode_entities($password) %></PRE>
206 % } else { 
207
208       <I>(hidden)</I>
209 % } 
210
211
212   </TD>
213 </TR>
214 % $password = ''; 
215 % if ( $conf->exists('security_phrase') ) {
216 %     my $sec_phrase = $svc_acct->sec_phrase;
217 %
218
219   <TR>
220     <TD ALIGN="right">Security phrase</TD>
221     <TD BGCOLOR="#ffffff"><% $svc_acct->sec_phrase %></TD>
222   </TR>
223 % } 
224 % if ( $svc_acct->popnum ) {
225 %    my $svc_acct_pop = qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum});
226 %
227
228   <TR>
229     <TD ALIGN="right">Access number</TD>
230     <TD BGCOLOR="#ffffff"><% $svc_acct_pop->text %></TD>
231   </TR>
232 % } 
233 % if ($svc_acct->uid ne '') { 
234
235   <TR>
236     <TD ALIGN="right">UID</TD>
237     <TD BGCOLOR="#ffffff"><% $svc_acct->uid %></TD>
238   </TR>
239 % } 
240 % if ($svc_acct->gid ne '') { 
241
242   <TR>
243     <TD ALIGN="right">GID</TD>
244     <TD BGCOLOR="#ffffff"><% $svc_acct->gid %></TD>
245   </TR>
246 % } 
247 % if ($svc_acct->finger ne '') { 
248
249   <TR>
250     <TD ALIGN="right">GECOS</TD>
251     <TD BGCOLOR="#ffffff"><% $svc_acct->finger %></TD>
252   </TR>
253 % } 
254 % if ($svc_acct->dir ne '') { 
255
256   <TR>
257     <TD ALIGN="right">Home directory</TD>
258     <TD BGCOLOR="#ffffff"><% $svc_acct->dir %></TD>
259   </TR>
260 % } 
261 % if ($svc_acct->shell ne '') { 
262
263   <TR>
264     <TD ALIGN="right">Shell</TD>
265     <TD BGCOLOR="#ffffff"><% $svc_acct->shell %></TD>
266   </TR>
267 % } 
268 % if ($svc_acct->quota ne '') { 
269
270   <TR>
271     <TD ALIGN="right">Quota</TD>
272     <TD BGCOLOR="#ffffff"><% $svc_acct->quota %></TD>
273   </TR>
274 % } 
275 % if ($svc_acct->slipip) { 
276
277   <TR>
278     <TD ALIGN="right">IP address</TD>
279     <TD BGCOLOR="#ffffff">
280       <% ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' )
281             ? "<I>(Dynamic)</I>"
282             : $svc_acct->slipip
283       %>
284     </TD>
285   </TR>
286 % } 
287 % foreach my $attribute ( grep /^radius_/, $svc_acct->fields ) {
288 %  $attribute =~ /^radius_(.*)$/;
289 %  my $pattribute = $FS::raddb::attrib{$1};
290 %
291
292   <TR>
293     <TD ALIGN="right">Radius (reply) <% $pattribute %></TD>
294     <TD BGCOLOR="#ffffff"><% $svc_acct->getfield($attribute) %></TD>
295   </TR>
296 % } 
297 % foreach my $attribute ( grep /^rc_/, $svc_acct->fields ) {
298 %  $attribute =~ /^rc_(.*)$/;
299 %  my $pattribute = $FS::raddb::attrib{$1};
300 %
301
302   <TR>
303     <TD ALIGN="right">Radius (check) <% $pattribute %></TD>
304     <TD BGCOLOR="#ffffff"><% $svc_acct->getfield($attribute) %></TD>
305   </TR>
306 % } 
307
308
309 <TR>
310   <TD ALIGN="right">RADIUS groups</TD>
311   <TD BGCOLOR="#ffffff"><% join('<BR>', $svc_acct->radius_groups) %></TD>
312 </TR>
313 % if ( $svc_acct->seconds =~ /^\d+$/ ) { 
314
315   <TR>
316     <TD ALIGN="right">Prepaid time</TD>
317     <TD BGCOLOR="#ffffff"><% duration_exact($svc_acct->seconds) %></TD>
318   </TR>
319 % } 
320 %
321 %# Can this be abstracted further?  Maybe a library function like
322 %# widget('HTML', 'view', $svc_acct) ?  It would definitely make UI 
323 %# style management easier.
324 %
325 % foreach (sort { $a cmp $b } $svc_acct->virtual_fields) { 
326
327   <% $svc_acct->pvf($_)->widget('HTML', 'view', $svc_acct->getfield($_)) %>
328 % } 
329
330
331 </TABLE></TD></TR></TABLE>
332 </FORM>
333 <BR><BR>
334
335 <% join("<BR>", $conf->config('svc_acct-notes') ) %>
336 <BR><BR>
337
338 <% joblisting({'svcnum'=>$svcnum}, 1) %>
339
340 </BODY>
341 </HTML>