use consistant terminology
[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
62   my $last_bill;
63   if ( $cust_pkg ) {
64     #false laziness w/httemplate/edit/part_pkg... this stuff doesn't really
65     #belong in plan data
66      my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
67                       split("\n", $cust_pkg->part_pkg->plandata );
68
69     $last_bill = $cust_pkg->last_bill;
70   } else {
71     $last_bill = 0;
72   }
73
74   my $seconds = $svc_acct->seconds_since_sqlradacct( $last_bill, time );
75   my $h = int($seconds/3600);
76   my $m = int( ($seconds%3600) / 60 );
77   my $s = $seconds%60;
78
79   if ( $seconds ) {
80     print "Online <B>$h</B>h <B>$m</B>m <B>$s</B>s";
81   } else {
82     print 'Has not logged on';
83   }
84
85   if ( $cust_pkg ) {
86     print ' this billing cycle (since '. time2str(%C, $last_bill). ') - '. 
87           $plandata{recur_included_hours}. ' total hours in plan<BR><BR>';
88   } else {
89     print ' (no billing cycle available for unaudited account)<BR><BR>';
90   }
91
92 }
93
94 #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!;
95
96 print qq!<A HREF="${p}edit/svc_acct.cgi?$svcnum">Edit this information</A><BR>!.
97       &ntable("#cccccc"). '<TR><TD>'. &ntable("#cccccc",2).
98       "<TR><TD ALIGN=\"right\">Service number</TD>".
99         "<TD BGCOLOR=\"#ffffff\">$svcnum</TD></TR>".
100       "<TR><TD ALIGN=\"right\">Service</TD>".
101         "<TD BGCOLOR=\"#ffffff\">". $part_svc->svc. "</TD></TR>".
102       "<TR><TD ALIGN=\"right\">Username</TD>".
103         "<TD BGCOLOR=\"#ffffff\">". $svc_acct->username. "</TD></TR>"
104 ;
105
106 print "<TR><TD ALIGN=\"right\">Domain</TD>".
107         "<TD BGCOLOR=\"#ffffff\">". $domain, "</TD></TR>";
108
109 print "<TR><TD ALIGN=\"right\">Password</TD><TD BGCOLOR=\"#ffffff\">";
110 my $password = $svc_acct->_password;
111 if ( $password =~ /^\*\w+\* (.*)$/ ) {
112   $password = $1;
113   print "<I>(login disabled)</I> ";
114 }
115 if ( $conf->exists('showpasswords') ) {
116   print '<PRE>'. encode_entities($password). '</PRE>';
117 } else {
118   print "<I>(hidden)</I>";
119 }
120 print "</TR></TD>";
121 $password = '';
122
123 if ( $conf->exists('security_phrase') ) {
124   my $sec_phrase = $svc_acct->sec_phrase;
125   print '<TR><TD ALIGN="right">Security phrase</TD><TD BGCOLOR="#ffffff">'.
126         $svc_acct->sec_phrase. '</TD></TR>';
127 }
128
129 my $svc_acct_pop = qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum});
130 print "<TR><TD ALIGN=\"right\">Access number</TD>".
131       "<TD BGCOLOR=\"#ffffff\">". $svc_acct_pop->text. '</TD></TR>'
132   if $svc_acct_pop;
133
134 if ($svc_acct->uid ne '') {
135   print "<TR><TD ALIGN=\"right\">Uid</TD>".
136           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->uid. "</TD></TR>",
137         "<TR><TD ALIGN=\"right\">Gid</TD>".
138           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->gid. "</TD></TR>",
139         "<TR><TD ALIGN=\"right\">GECOS</TD>".
140           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->finger. "</TD></TR>",
141         "<TR><TD ALIGN=\"right\">Home directory</TD>".
142           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->dir. "</TD></TR>",
143         "<TR><TD ALIGN=\"right\">Shell</TD>".
144           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->shell. "</TD></TR>",
145         "<TR><TD ALIGN=\"right\">Quota</TD>".
146           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->quota. "</TD></TR>"
147   ;
148 } else {
149   print "<TR><TH COLSPAN=2>(No shell account)</TH></TR>";
150 }
151
152 if ($svc_acct->slipip) {
153   print "<TR><TD ALIGN=\"right\">IP address</TD><TD BGCOLOR=\"#ffffff\">".
154         ( ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' )
155           ? "<I>(Dynamic)</I>"
156           : $svc_acct->slipip
157         ). "</TD>";
158   my($attribute);
159   foreach $attribute ( grep /^radius_/, fields('svc_acct') ) {
160     #warn $attribute;
161     $attribute =~ /^radius_(.*)$/;
162     my $pattribute = $FS::raddb::attrib{$1};
163     print "<TR><TD ALIGN=\"right\">Radius (reply) $pattribute</TD>".
164           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
165           "</TD></TR>";
166   }
167   foreach $attribute ( grep /^rc_/, fields('svc_acct') ) {
168     #warn $attribute;
169     $attribute =~ /^rc_(.*)$/;
170     my $pattribute = $FS::raddb::attrib{$1};
171     print "<TR><TD ALIGN=\"right\">Radius (check) $pattribute: </TD>".
172           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
173           "</TD></TR>";
174   }
175 } else {
176   print "<TR><TH COLSPAN=2>(No SLIP/PPP account)</TH></TR>";
177 }
178
179 print '<TR><TD ALIGN="right">RADIUS groups</TD><TD BGCOLOR="#ffffff">'.
180       join('<BR>', $svc_acct->radius_groups). '</TD></TR>';
181
182 print '</TABLE></TD></TR></TABLE><BR><BR>';
183
184 print join("\n", $conf->config('svc_acct-notes') ).  '<BR><BR>'.
185       joblisting({'svcnum'=>$svcnum}, 1). '</BODY></HTML>';
186
187 %>