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