7badfe6966e0d0efdf94faf06e9daebd1c26a50c
[freeside.git] / httemplate / edit / svc_acct.cgi
1 <%
2 #
3 # $Id: svc_acct.cgi,v 1.1 2001-07-30 07:36:04 ivan Exp $
4 #
5 # Usage: svc_acct.cgi {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
6 #        http://server.name/path/svc_acct.cgi? {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
7 #
8 # ivan@voicenet.com 96-dec-18
9 #
10 # rewrite ivan@sisd.com 98-mar-8
11 #
12 # Changes to allow page to work at a relative position in server
13 # Changed 'password' to '_password' because Pg6.3 reserves the password word
14 #       bmccane@maxbaud.net     98-apr-3
15 #
16 # use conf/shells and dbdef username length ivan@sisd.com 98-jul-13
17 #
18 # $Log: svc_acct.cgi,v $
19 # Revision 1.1  2001-07-30 07:36:04  ivan
20 # templates!!!
21 #
22 # Revision 1.10  1999/04/14 11:27:06  ivan
23 # showpasswords config option to show passwords
24 #
25 # Revision 1.9  1999/02/28 00:03:37  ivan
26 # removed misleading comments
27 #
28 # Revision 1.8  1999/02/23 08:09:22  ivan
29 # beginnings of one-screen new customer entry and some other miscellania
30 #
31 # Revision 1.7  1999/02/07 09:59:22  ivan
32 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
33 #
34 # Revision 1.6  1999/01/19 05:13:43  ivan
35 # for mod_perl: no more top-level my() variables; use vars instead
36 # also the last s/create/new/;
37 #
38 # Revision 1.5  1999/01/18 09:41:32  ivan
39 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
40 # (good idea anyway)
41 #
42 # Revision 1.4  1998/12/30 23:03:22  ivan
43 # bugfixes; fields isn't exported by derived classes
44 #
45 # Revision 1.3  1998/12/17 06:17:08  ivan
46 # fix double // in relative URLs, s/CGI::Base/CGI/;
47 #
48
49 use strict;
50 use vars qw( $conf $cgi @shells $action $svcnum $svc_acct $pkgnum $svcpart
51              $part_svc $svc $otaker $username $password $ulen $ulen2 $p1
52              $popnum $uid $gid $finger $dir $shell $quota $slipip );
53 use CGI;
54 use CGI::Carp qw(fatalsToBrowser);
55 use FS::UID qw(cgisuidsetup getotaker);
56 use FS::CGI qw(header popurl);
57 use FS::Record qw(qsearch qsearchs fields);
58 use FS::svc_acct;
59 use FS::Conf;
60
61 $cgi = new CGI;
62 &cgisuidsetup($cgi);
63
64 $conf = new FS::Conf;
65 @shells = $conf->config('shells');
66
67 if ( $cgi->param('error') ) {
68   $svc_acct = new FS::svc_acct ( {
69     map { $_, scalar($cgi->param($_)) } fields('svc_acct')
70   } );
71   $svcnum = $svc_acct->svcnum;
72   $pkgnum = $cgi->param('pkgnum');
73   $svcpart = $cgi->param('svcpart');
74   $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
75   die "No part_svc entry!" unless $part_svc;
76 } else {
77   my($query) = $cgi->keywords;
78   if ( $query =~ /^(\d+)$/ ) { #editing
79     $svcnum=$1;
80     $svc_acct=qsearchs('svc_acct',{'svcnum'=>$svcnum})
81       or die "Unknown (svc_acct) svcnum!";
82
83     my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum})
84       or die "Unknown (cust_svc) svcnum!";
85
86     $pkgnum=$cust_svc->pkgnum;
87     $svcpart=$cust_svc->svcpart;
88
89     $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
90     die "No part_svc entry!" unless $part_svc;
91
92   } else { #adding
93
94     $svc_acct = new FS::svc_acct({}); 
95
96     foreach $_ (split(/-/,$query)) {
97       $pkgnum=$1 if /^pkgnum(\d+)$/;
98       $svcpart=$1 if /^svcpart(\d+)$/;
99     }
100     $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
101     die "No part_svc entry!" unless $part_svc;
102
103     $svcnum='';
104
105     #set gecos
106     my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
107     if ($cust_pkg) {
108       my($cust_main)=qsearchs('cust_main',{'custnum'=> $cust_pkg->custnum } );
109       $svc_acct->setfield('finger',
110         $cust_main->getfield('first') . " " . $cust_main->getfield('last')
111       ) ;
112     }
113
114     #set fixed and default fields from part_svc
115     my($field);
116     foreach $field ( fields('svc_acct') ) {
117       if ( $part_svc->getfield('svc_acct__'. $field. '_flag') ne '' ) {
118         $svc_acct->setfield($field,$part_svc->getfield('svc_acct__'. $field) );
119       }
120     }
121
122   }
123 }
124 $action = $svcnum ? 'Edit' : 'Add';
125
126 $svc = $part_svc->getfield('svc');
127
128 $otaker = getotaker;
129
130 $username = $svc_acct->username;
131 if ( $svc_acct->_password ) {
132   if ( $conf->exists('showpasswords') ) {
133     $password = $svc_acct->_password;
134   } else {
135     $password = "*HIDDEN*";
136   }
137 } else {
138   $password = '';
139 }
140
141 $ulen = $svc_acct->dbdef_table->column('username')->length;
142 $ulen2 = $ulen+2;
143
144 $p1 = popurl(1);
145 print $cgi->header( '-expires' => 'now' ), header("$action $svc account");
146
147 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
148       "</FONT>"
149   if $cgi->param('error');
150
151 print <<END;
152     <FORM ACTION="${p1}process/svc_acct.cgi" METHOD=POST>
153       <INPUT TYPE="hidden" NAME="svcnum" VALUE="$svcnum">
154       <INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">
155       <INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">
156 Username: 
157 <INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen>
158 <BR>Password: 
159 <INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=10 MAXLENGTH=8> 
160 (blank to generate)
161 END
162
163 #pop
164 $popnum = $svc_acct->popnum || 0;
165 if ( $part_svc->svc_acct__popnum_flag eq "F" ) {
166   print qq!<INPUT TYPE="hidden" NAME="popnum" VALUE="$popnum">!;
167 } else { 
168   print qq!<BR>POP: <SELECT NAME="popnum" SIZE=1><OPTION>\n!;
169   my($svc_acct_pop);
170   foreach $svc_acct_pop ( qsearch ('svc_acct_pop',{} ) ) {
171   print "<OPTION", $svc_acct_pop->popnum == $popnum ? ' SELECTED' : '', ">", 
172         $svc_acct_pop->popnum, ": ", 
173         $svc_acct_pop->city, ", ",
174         $svc_acct_pop->state,
175         " (", $svc_acct_pop->ac, ")/",
176         $svc_acct_pop->exch, "\n"
177       ;
178   }
179   print "</SELECT>";
180 }
181
182 ($uid,$gid,$finger,$dir)=(
183   $svc_acct->uid,
184   $svc_acct->gid,
185   $svc_acct->finger,
186   $svc_acct->dir,
187 );
188
189 print <<END;
190 <INPUT TYPE="hidden" NAME="uid" VALUE="$uid">
191 <INPUT TYPE="hidden" NAME="gid" VALUE="$gid">
192 <BR>GECOS: <INPUT TYPE="text" NAME="finger" VALUE="$finger">
193 <INPUT TYPE="hidden" NAME="dir" VALUE="$dir">
194 END
195
196 $shell = $svc_acct->shell;
197 if ( $part_svc->svc_acct__shell_flag eq "F" ) {
198   print qq!<INPUT TYPE="hidden" NAME="shell" VALUE="$shell">!;
199 } else {
200   print qq!<BR>Shell: <SELECT NAME="shell" SIZE=1>!;
201   my($etc_shell);
202   foreach $etc_shell (@shells) {
203     print "<OPTION", $etc_shell eq $shell ? ' SELECTED' : '', ">",
204           $etc_shell, "\n";
205   }
206   print "</SELECT>";
207 }
208
209 ($quota,$slipip)=(
210   $svc_acct->quota,
211   $svc_acct->slipip,
212 );
213
214 print qq!<INPUT TYPE="hidden" NAME="quota" VALUE="$quota">!;
215
216 if ( $part_svc->svc_acct__slipip_flag eq "F" ) {
217   print qq!<INPUT TYPE="hidden" NAME="slipip" VALUE="$slipip">!;
218 } else {
219   print qq!<BR>IP: <INPUT TYPE="text" NAME="slipip" VALUE="$slipip">!;
220 }
221
222 #submit
223 print qq!<P><INPUT TYPE="submit" VALUE="Submit">!; 
224
225 print <<END;
226     </FORM>
227   </BODY>
228 </HTML>
229 END
230
231
232 %>