further small UI tweaks
[freeside.git] / httemplate / view / svc_acct.cgi
1 <!-- mason kludge -->
2 <%
3
4 my $conf = new FS::Conf;
5
6 my($query) = $cgi->keywords;
7 $query =~ /^(\d+)$/;
8 my $svcnum = $1;
9 my $svc_acct = qsearchs('svc_acct',{'svcnum'=>$svcnum});
10 die "Unknown svcnum" unless $svc_acct;
11
12 #false laziness w/all svc_*.cgi
13 my $cust_svc = qsearchs( 'cust_svc' , { 'svcnum' => $svcnum } );
14 my $pkgnum = $cust_svc->getfield('pkgnum');
15 my($cust_pkg, $custnum);
16 if ($pkgnum) {
17   $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } );
18   $custnum = $cust_pkg->custnum;
19 } else {
20   $cust_pkg = '';
21   $custnum = '';
22 }
23 #eofalse
24
25 my $part_svc = qsearchs('part_svc',{'svcpart'=> $cust_svc->svcpart } );
26 die "Unknown svcpart" unless $part_svc;
27
28 my $domain;
29 if ( $svc_acct->domsvc ) {
30   my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $svc_acct->domsvc } );
31   die "Unknown domain" unless $svc_domain;
32   $domain = $svc_domain->domain;
33 } else {
34   die "No svc_domain.svcnum record for svc_acct.domsvc: ". $cust_svc->domsvc;
35 }
36
37 %>
38
39 <SCRIPT>
40 function areyousure(href) {
41     if (confirm("Permanently delete this account?") == true)
42         window.location.href = href;
43 }
44 </SCRIPT>
45
46 <%= header('Account View', menubar(
47   ( ( $pkgnum || $custnum )
48     ? ( "View this package (#$pkgnum)" => "${p}view/cust_pkg.cgi?$pkgnum",
49         "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
50       )
51     : ( "Cancel this (unaudited) account" =>
52           "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')" )
53   ),
54   "Main menu" => $p,
55 )) %>
56
57 <%
58
59 #if ( $cust_pkg && $cust_pkg->part_pkg->plan eq 'sqlradacct_hour' ) {
60 if (    $part_svc->part_export('sqlradius')
61      || $part_svc->part_export('sqlradius_withdomain')
62 ) {
63
64   my $last_bill;
65   my %plandata;
66   if ( $cust_pkg ) {
67     #false laziness w/httemplate/edit/part_pkg... this stuff doesn't really
68     #belong in plan data
69     %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
70                     split("\n", $cust_pkg->part_pkg->plandata );
71
72     $last_bill = $cust_pkg->last_bill;
73   } else {
74     $last_bill = 0;
75     %plandata = ();
76   }
77
78   my $seconds = $svc_acct->seconds_since_sqlradacct( $last_bill, time );
79   my $hour = int($seconds/3600);
80   my $min = int( ($seconds%3600) / 60 );
81   my $sec = $seconds%60;
82
83   my $input = $svc_acct->attribute_since_sqlradacct(
84     $last_bill, time, 'AcctInputOctets'
85   ) / 1048576;
86   my $output = $svc_acct->attribute_since_sqlradacct(
87     $last_bill, time, 'AcctOutputOctets'
88   ) / 1048576;
89
90   if ( $seconds ) {
91     print "Online <B>$hour</B>h <B>$min</B>m <B>$sec</B>s";
92   } else {
93     print 'Has not logged on';
94   }
95
96   if ( $cust_pkg ) {
97     print ' since last bill ('. time2str("%C", $last_bill). ') - '. 
98           $plandata{recur_included_hours}. ' total hours in plan<BR>';
99   } else {
100     print ' (no billing cycle available for unaudited account)<BR>';
101   }
102
103   print 'Input: <B>'. sprintf("%.3f", $input). '</B> megabytes<BR>';
104   print 'Output: <B>'. sprintf("%.3f", $output). '</B> megabytes<BR>';
105
106   print '<BR>';
107
108 }
109
110 #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!;
111
112 print qq!<A HREF="${p}edit/svc_acct.cgi?$svcnum">Edit this information</A><BR>!.
113       &ntable("#cccccc"). '<TR><TD>'. &ntable("#cccccc",2).
114       "<TR><TD ALIGN=\"right\">Service number</TD>".
115         "<TD BGCOLOR=\"#ffffff\">$svcnum</TD></TR>".
116       "<TR><TD ALIGN=\"right\">Service</TD>".
117         "<TD BGCOLOR=\"#ffffff\">". $part_svc->svc. "</TD></TR>".
118       "<TR><TD ALIGN=\"right\">Username</TD>".
119         "<TD BGCOLOR=\"#ffffff\">". $svc_acct->username. "</TD></TR>"
120 ;
121
122 print "<TR><TD ALIGN=\"right\">Domain</TD>".
123         "<TD BGCOLOR=\"#ffffff\">". $domain, "</TD></TR>";
124
125 print "<TR><TD ALIGN=\"right\">Password</TD><TD BGCOLOR=\"#ffffff\">";
126 my $password = $svc_acct->_password;
127 if ( $password =~ /^\*\w+\* (.*)$/ ) {
128   $password = $1;
129   print "<I>(login disabled)</I> ";
130 }
131 if ( $conf->exists('showpasswords') ) {
132   print '<PRE>'. encode_entities($password). '</PRE>';
133 } else {
134   print "<I>(hidden)</I>";
135 }
136 print "</TR></TD>";
137 $password = '';
138
139 if ( $conf->exists('security_phrase') ) {
140   my $sec_phrase = $svc_acct->sec_phrase;
141   print '<TR><TD ALIGN="right">Security phrase</TD><TD BGCOLOR="#ffffff">'.
142         $svc_acct->sec_phrase. '</TD></TR>';
143 }
144
145 my $svc_acct_pop = $svc_acct->popnum
146                      ? qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum})
147                      : '';
148 print "<TR><TD ALIGN=\"right\">Access number</TD>".
149       "<TD BGCOLOR=\"#ffffff\">". $svc_acct_pop->text. '</TD></TR>'
150   if $svc_acct_pop;
151
152 if ($svc_acct->uid ne '') {
153   print "<TR><TD ALIGN=\"right\">Uid</TD>".
154           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->uid. "</TD></TR>",
155         "<TR><TD ALIGN=\"right\">Gid</TD>".
156           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->gid. "</TD></TR>",
157         "<TR><TD ALIGN=\"right\">GECOS</TD>".
158           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->finger. "</TD></TR>",
159         "<TR><TD ALIGN=\"right\">Home directory</TD>".
160           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->dir. "</TD></TR>",
161         "<TR><TD ALIGN=\"right\">Shell</TD>".
162           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->shell. "</TD></TR>",
163         "<TR><TD ALIGN=\"right\">Quota</TD>".
164           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->quota. "</TD></TR>"
165   ;
166 } else {
167   print "<TR><TH COLSPAN=2>(No shell account)</TH></TR>";
168 }
169
170 if ($svc_acct->slipip) {
171   print "<TR><TD ALIGN=\"right\">IP address</TD><TD BGCOLOR=\"#ffffff\">".
172         ( ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' )
173           ? "<I>(Dynamic)</I>"
174           : $svc_acct->slipip
175         ). "</TD>";
176   my($attribute);
177   foreach $attribute ( grep /^radius_/, $svc_acct->fields ) {
178     #warn $attribute;
179     $attribute =~ /^radius_(.*)$/;
180     my $pattribute = $FS::raddb::attrib{$1};
181     print "<TR><TD ALIGN=\"right\">Radius (reply) $pattribute</TD>".
182           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
183           "</TD></TR>";
184   }
185   foreach $attribute ( grep /^rc_/, $svc_acct->fields ) {
186     #warn $attribute;
187     $attribute =~ /^rc_(.*)$/;
188     my $pattribute = $FS::raddb::attrib{$1};
189     print "<TR><TD ALIGN=\"right\">Radius (check) $pattribute: </TD>".
190           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
191           "</TD></TR>";
192   }
193 } else {
194   print "<TR><TH COLSPAN=2>(No SLIP/PPP account)</TH></TR>";
195 }
196
197 print '<TR><TD ALIGN="right">RADIUS groups</TD><TD BGCOLOR="#ffffff">'.
198       join('<BR>', $svc_acct->radius_groups). '</TD></TR>';
199
200 # Can this be abstracted further?  Maybe a library function like
201 # widget('HTML', 'view', $svc_acct) ?  It would definitely make UI 
202 # style management easier.
203
204 foreach (sort { $a cmp $b } $svc_acct->virtual_fields) {
205   print $svc_acct->pvf($_)->widget('HTML', 'view', $svc_acct->getfield($_)),
206       "\n";
207 }
208 %>
209 </TABLE></TD></TR></TABLE>
210 <%
211
212 print '<BR><BR>';
213
214 print join("\n", $conf->config('svc_acct-notes') ). '<BR><BR>'.
215       joblisting({'svcnum'=>$svcnum}, 1). '</BODY></HTML>';
216
217 %>