so Search.tsf and Search.rdf work
[freeside.git] / httemplate / edit / cust_main.cgi
1 <!-- mason kludge -->
2 <%
3
4   #for misplaced logic below
5   #use FS::part_pkg;
6
7   #for false laziness below (now more properly lazy)
8   #use FS::svc_acct_pop;
9
10   #for (other) false laziness below
11   #use FS::agent;
12   #use FS::type_pkgs;
13
14 my $conf = new FS::Conf;
15
16 #get record
17
18 my $error = '';
19 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart);
20 my(@invoicing_list);
21 if ( $cgi->param('error') ) {
22   $error = $cgi->param('error');
23   $cust_main = new FS::cust_main ( {
24     map { $_, scalar($cgi->param($_)) } fields('cust_main')
25   } );
26   $custnum = $cust_main->custnum;
27   $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
28   if ( $saved_pkgpart =~ /^(\d+)_/ ) {
29     $saved_pkgpart = $1;
30   } else {
31     $saved_pkgpart = '';
32   }
33   $username = $cgi->param('username');
34   $password = $cgi->param('_password');
35   $popnum = $cgi->param('popnum');
36   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
37 } elsif ( $cgi->keywords ) { #editing
38   my( $query ) = $cgi->keywords;
39   $query =~ /^(\d+)$/;
40   $custnum=$1;
41   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
42   if ( $cust_main->dbdef_table->column('paycvv')
43        && length($cust_main->paycvv)             ) {
44     my $paycvv = $cust_main->paycvv;
45     $paycvv =~ s/./*/g;
46     $cust_main->paycvv($paycvv);
47   }
48   $saved_pkgpart = 0;
49   $username = '';
50   $password = '';
51   $popnum = 0;
52   @invoicing_list = $cust_main->invoicing_list;
53 } else {
54   $custnum='';
55   $cust_main = new FS::cust_main ( {} );
56   $cust_main->otaker( &getotaker );
57   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
58   $saved_pkgpart = 0;
59   $username = '';
60   $password = '';
61   $popnum = 0;
62   @invoicing_list = ();
63 }
64 $cgi->delete_all();
65 my $action = $custnum ? 'Edit' : 'Add';
66
67 %>
68
69 <!-- top -->
70
71 <%= header("Customer $action", '', ' onUnload="myclose()"') %>
72
73 <% if ( $error ) { %>
74 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT>
75 <% } %>
76
77 <FORM ACTION="<%= popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="form1" onSubmit="document.form1.submit.disabled=true">
78 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
79 Customer # <%= $custnum ? "<B>$custnum</B>" : " (NEW)" %>
80
81 <!-- agent -->
82
83 <%
84
85 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
86
87 my %agent_search = dbdef->table('agent')->column('disabled')
88                      ? ( 'disabled' => '' ) : ();
89 my @agents = qsearch( 'agent', \%agent_search );
90 #die "No agents created!" unless @agents;
91 eidiot "You have not created any agents (or all agents are disabled).  You must create at least one agent before adding a customer.  Go to ". popurl(2). "browse/agent.cgi and create one or more agents." unless @agents;
92 my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
93
94 %>
95
96 <% if ( scalar(@agents) == 1 ) { %>
97   <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agentnum %>">
98 <% } else { %>
99   <BR><BR><%=$r%>Agent <SELECT NAME="agentnum" SIZE="1">
100   <% foreach my $agent (sort { $a->agent cmp $b->agent; } @agents) { %>
101     <OPTION VALUE="<%= $agent->agentnum %>"<%= " SELECTED"x($agent->agentnum==$agentnum) %>><%= $agent->agent %>
102   <% } %>
103   </SELECT>
104 <% } %>
105
106 <%
107
108 # (referral and referring customer still need to be "template"ized)
109
110 #referral
111
112 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
113 if ( $custnum && ! $conf->exists('editreferrals') ) {
114   print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
115 } else {
116   my(@referrals) = qsearch('part_referral',{});
117   if ( scalar(@referrals) == 0 ) {
118     eidiot "You have not created any advertising sources.  You must create at least one advertising source before adding a customer.  Go to ". popurl(2). "browse/part_referral.cgi and create one or more advertising sources.";
119   } elsif ( scalar(@referrals) == 1 ) {
120     $refnum ||= $referrals[0]->refnum;
121     print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
122   } else {
123     print qq!<BR><BR>${r}Advertising source <SELECT NAME="refnum" SIZE="1">!;
124     print "<OPTION> " unless $refnum;
125     my($referral);
126     foreach $referral (sort {
127       $a->refnum <=> $b->refnum;
128     } @referrals) {
129       print "<OPTION" . " SELECTED"x($referral->refnum==$refnum),
130       ">", $referral->refnum, ": ", $referral->referral;
131     }
132     print "</SELECT>";
133   }
134 }
135
136 #referring customer
137
138 #print qq!<BR><BR>Referring Customer: !;
139 my $referring_cust_main = '';
140 if ( $cust_main->referral_custnum
141      and $referring_cust_main =
142            qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
143 ) {
144   print '<BR><BR>Referring Customer: <A HREF="'. popurl(1). '/cust_main.cgi?'.
145         $cust_main->referral_custnum. '">'.
146         $cust_main->referral_custnum. ': '.
147         ( $referring_cust_main->company
148           || $referring_cust_main->last. ', '. $referring_cust_main->first ).
149         '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
150         $cust_main->referral_custnum. '">';
151 } elsif ( ! $conf->exists('disable_customer_referrals') ) {
152   print '<BR><BR>Referring customer number: <INPUT TYPE="text" NAME="referral_custnum" VALUE="">';
153 } else {
154   print '<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
155 }
156
157 %>
158
159 <!-- contact info -->
160
161 <BR><BR>
162 Billing address
163 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
164
165 <!-- service address -->
166
167 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
168
169 <SCRIPT>
170 function bill_changed(what) {
171   if ( what.form.same.checked ) {
172 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
173     what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
174 <% } %>
175     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
176     ship_country_changed(what.form.ship_country);
177     what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
178     ship_state_changed(what.form.ship_state);
179     what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
180   }
181 }
182 function samechanged(what) {
183   if ( what.checked ) {
184     bill_changed(what);
185 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
186     what.form.ship_<%=$_%>.disabled = true;
187     what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
188 <% } %>
189   } else {
190 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
191     what.form.ship_<%=$_%>.disabled = false;
192     what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
193 <% } %>
194   }
195 }
196 </SCRIPT>
197
198 <%
199   my $checked = '';
200   my $disabled = '';
201   my $disabledselect = '';
202   unless ( $cust_main->ship_last && $cgi->param('same') ne 'Y' ) {
203     $checked = 'CHECKED';
204     $disabled = 'DISABLED style="background-color: #dddddd"';
205     foreach (
206       qw( last first company address1 address2 city county state zip country
207           daytime night fax )
208     ) {
209       $cust_main->set("ship_$_", $cust_main->get($_) );
210     }
211   }
212 %>
213
214 <BR>
215 Service address 
216 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
217 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
218
219 <% } %>
220
221 <%
222 # billing info
223
224 sub expselect {
225   my $prefix = shift;
226   my( $m, $y ) = (0, 0);
227   if ( scalar(@_) ) {
228     my $date = shift || '01-2000';
229     if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
230       ( $m, $y ) = ( $2, $1 );
231     } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
232       ( $m, $y ) = ( $1, $3 );
233     } else {
234       die "unrecognized expiration date format: $date";
235     }
236   }
237
238   my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
239   for ( 1 .. 12 ) {
240     $return .= "<OPTION";
241     $return .= " SELECTED" if $_ == $m;
242     $return .= ">$_";
243   }
244   $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
245   my @t = localtime;
246   my $thisYear = $t[5] + 1900;
247   for ( ($thisYear > $y && $y > 0 ? $y : $thisYear) .. 2037 ) {
248     $return .= "<OPTION";
249     $return .= " SELECTED" if $_ == $y;
250     $return .= ">$_";
251   }
252   $return .= "</SELECT>";
253
254   $return;
255 }
256
257 my $payby_default = $conf->config('payby-default');
258
259 if ( $payby_default eq 'HIDE' ) {
260
261   $cust_main->payby('BILL') unless $cust_main->payby;
262
263   foreach my $field (qw( tax payby )) {
264     print qq!<INPUT TYPE="hidden" NAME="$field" VALUE="!.
265           $cust_main->getfield($field). '">';
266   }
267
268   print qq!<INPUT TYPE="hidden" NAME="invoicing_list" VALUE="!.
269         join(', ', $cust_main->invoicing_list). '">';
270
271   foreach my $payby (qw( CARD DCRD CHEK DCHK LECB BILL COMP )) {
272     foreach my $field (qw( payinfo payname )) {
273       print qq!<INPUT TYPE="hidden" NAME="${payby}_$field" VALUE="!.
274             $cust_main->getfield($field). '">';
275     }
276
277     #false laziness w/expselect
278     my( $m, $y );
279     my $date = $cust_main->paydate || '12-2037';
280     if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
281       ( $m, $y ) = ( $2, $1 );
282     } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
283       ( $m, $y ) = ( $1, $3 );
284     } else {
285       die "unrecognized expiration date format: $date";
286     }
287
288     print qq!<INPUT TYPE="hidden" NAME="${payby}_month" VALUE="$m">!.
289           qq!<INPUT TYPE="hidden" NAME="${payby}_year"  VALUE="$y">!;
290
291   }
292
293 } else {
294
295   print "<BR>Billing information", &itable("#cccccc"),
296         qq!<TR><TD><INPUT TYPE="checkbox" NAME="tax" VALUE="Y"!;
297   print qq! CHECKED! if $cust_main->tax eq "Y";
298   print qq!>Tax Exempt</TD></TR><TR><TD>!.
299         qq!<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"!;
300
301   #my @invoicing_list = $cust_main->invoicing_list;
302   print qq! CHECKED!
303     if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') )
304        || grep { $_ eq 'POST' } @invoicing_list;
305   print qq!>Postal mail invoice</TD></TR><TR><TD>!;
306   print qq!<INPUT TYPE="checkbox" NAME="invoicing_list_FAX" VALUE="FAX"!;
307   print qq! CHECKED! if (grep { $_ eq 'FAX' } @invoicing_list);
308   print qq!>FAX invoice</TD></TR>!;
309   my $invoicing_list = join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list );
310   print qq!<TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="$invoicing_list"></TD></TR>!;
311
312   print "<TR><TD>Billing type</TD></TR>",
313         "</TABLE>", '<SCRIPT>
314                        var mywindow = -1;
315                        function myopen(filename,windowname,properties) {
316                          myclose();
317                          mywindow = window.open(filename,windowname,properties);
318                        }
319                        function myclose() {
320                          if ( mywindow != -1 )
321                            mywindow.close();
322                          mywindow = -1;
323                        }
324                        var achwindow = -1;
325                        function achopen(filename,windowname,properties) {
326                          achclose();
327                          achwindow = window.open(filename,windowname,properties);
328                        }
329                        function achclose() {
330                          if ( achwindow != -1 )
331                            achwindow.close();
332                          achwindow = -1;
333                        }
334                      </SCRIPT>',
335         &table("#cccccc"), "<TR>";
336
337   my($payinfo, $payname)=(
338     $cust_main->payinfo,
339     $cust_main->payname,
340   );
341
342   my %payby = (
343     'CARD' => qq!Credit card (automatic)<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
344     'DCRD' => qq!Credit card (on-demand)<BR>${r}<INPUT TYPE="text" NAME="DCRD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("DCRD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="DCRD_payname" VALUE="">!,
345     'CHEK' => qq!Electronic check (automatic)<BR>${r}Account number <INPUT TYPE="text" NAME="CHEK_payinfo1" VALUE=""><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="CHEK_payinfo2" VALUE="" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="CHEK_month" VALUE="12"><INPUT TYPE="hidden" NAME="CHEK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="CHEK_payname" VALUE="">!,
346     'DCHK' => qq!Electronic check (on-demand)<BR>${r}Account number <INPUT TYPE="text" NAME="DCHK_payinfo1" VALUE=""><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="DCHK_payinfo2" VALUE="" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="DCHK_month" VALUE="12"><INPUT TYPE="hidden" NAME="DCHK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="DCHK_payname" VALUE="">!,
347     'LECB' => qq!Phone bill billing<BR>${r}Phone number <INPUT TYPE="text" BANE="LECB_payinfo" VALUE="" MAXLENGTH=15 SIZE=16><INPUT TYPE="hidden" NAME="LECB_month" VALUE="12"><INPUT TYPE="hidden" NAME="LECB_year" VALUE="2037"><INPUT TYPE="hidden" NAME="LECB_payname" VALUE="">!,
348     'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR><INPUT TYPE="hidden" NAME="BILL_month" VALUE="12"><INPUT TYPE="hidden" NAME="BILL_year" VALUE="2037">Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="">!,
349     'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
350 );
351
352   if ( $cust_main->dbdef_table->column('paycvv') ) {
353     foreach my $payby ( grep { exists $payby{$_} } qw(CARD DCRD) ) { #1.4/1.5 bs
354       $payby{$payby} .= qq!<BR>CVV2&nbsp;(<A HREF="javascript:myopen('../docs/cvv2.html','cvv2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=480,height=288')">help</A>)&nbsp;<INPUT TYPE="text" NAME=${payby}_paycvv VALUE="" SIZE=4 MAXLENGTH=4>!;
355     }
356   }
357
358   my( $account, $aba ) = split('@', $payinfo);
359
360   my %paybychecked = (
361     'CARD' => qq!Credit card (automatic)<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD", $cust_main->paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
362     'DCRD' => qq!Credit card (on-demand)<BR>${r}<INPUT TYPE="text" NAME="DCRD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("DCRD", $cust_main->paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="DCRD_payname" VALUE="$payname">!,
363     'CHEK' => qq!Electronic check (automatic)<BR>${r}Account number <INPUT TYPE="text" NAME="CHEK_payinfo1" VALUE="$account"><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="CHEK_payinfo2" VALUE="$aba" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="CHEK_month" VALUE="12"><INPUT TYPE="hidden" NAME="CHEK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="CHEK_payname" VALUE="$payname">!,
364     'DCHK' => qq!Electronic check (on-demand)<BR>${r}Account number <INPUT TYPE="text" NAME="DCHK_payinfo1" VALUE="$account"><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="DCHK_payinfo2" VALUE="$aba" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="DCHK_month" VALUE="12"><INPUT TYPE="hidden" NAME="DCHK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="DCHK_payname" VALUE="$payname">!,
365     'LECB' => qq!Phone bill billing<BR>${r}Phone number <INPUT TYPE="text" BANE="LECB_payinfo" VALUE="$payinfo" MAXLENGTH=15 SIZE=16><INPUT TYPE="hidden" NAME="LECB_month" VALUE="12"><INPUT TYPE="hidden" NAME="LECB_year" VALUE="2037"><INPUT TYPE="hidden" NAME="LECB_payname" VALUE="">!,
366     'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR><INPUT TYPE="hidden" NAME="BILL_month" VALUE="12"><INPUT TYPE="hidden" NAME="BILL_year" VALUE="2037">Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
367     'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $cust_main->paydate),
368 );
369
370   if ( $cust_main->dbdef_table->column('paycvv') ) {
371     my $paycvv = $cust_main->paycvv;
372
373     foreach my $payby ( grep { exists $payby{$_} } qw(CARD DCRD) ) { #1.4/1.5 bs
374       $paybychecked{$payby} .= qq!<BR>CVV2&nbsp;(<A HREF="javascript:myopen('../docs/cvv2.html','cvv2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=480,height=288')">help</A>)&nbsp;<INPUT TYPE="text" NAME=${payby}_paycvv VALUE="$paycvv" SIZE=4 MAXLENGTH=4>!;
375     }
376   }
377
378
379   $cust_main->payby($payby_default) unless $cust_main->payby;
380   for (qw(CARD DCRD CHEK DCHK LECB BILL COMP)) {
381     print qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
382     if ($cust_main->payby eq "$_") {
383       print qq! CHECKED> $paybychecked{$_}</TD>!;
384     } else {
385       print qq!> $payby{$_}</TD>!;
386     }
387   }
388
389   print "</TR></TABLE>$r required fields for each billing type";
390
391 }
392
393 if ( defined $cust_main->dbdef_table->column('comments') ) {
394     print "<BR><BR>Comments", &itable("#cccccc"),
395           qq!<TR><TD><TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments">!,
396           $cust_main->comments, "</TEXTAREA>",
397           "</TD></TR></TABLE>";
398 }
399
400 unless ( $custnum ) {
401   # pry the wrong place for this logic.  also pretty expensive
402   #use FS::part_pkg;
403
404   #false laziness, copied from FS::cust_pkg::order
405   my $pkgpart;
406   if ( scalar(@agents) == 1 ) {
407     # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
408     my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
409     $pkgpart = $agent->pkgpart_hashref;
410   } else {
411     #can't know (agent not chosen), so, allow all
412     my %typenum;
413     foreach my $agent ( @agents ) {
414       next if $typenum{$agent->typenum}++;
415       #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
416       foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
417     }
418   }
419   #eslaf
420
421   my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
422     qsearch( 'part_pkg', { 'disabled' => '' } );
423
424   if ( @part_pkg ) {
425
426 #    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
427 #apiabuse & undesirable wrapping
428     print "<BR><BR>First package", &itable("#cccccc"),
429           qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
430
431     print qq!<OPTION VALUE="">(none)!;
432
433     foreach my $part_pkg ( @part_pkg ) {
434       print qq!<OPTION VALUE="!,
435 #              $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
436               $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
437       print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
438       print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
439     }
440     print "</SELECT></TD></TR>";
441
442     #false laziness: (mostly) copied from edit/svc_acct.cgi
443     #$ulen = $svc_acct->dbdef_table->column('username')->length;
444     my $ulen = dbdef->table('svc_acct')->column('username')->length;
445     my $ulen2 = $ulen+2;
446     my $passwordmax = $conf->config('passwordmax') || 8;
447     my $pmax2 = $passwordmax + 2;
448     print <<END;
449 <TR><TD ALIGN="right">Username</TD>
450 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
451 <TR><TD ALIGN="right">Password</TD>
452 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
453 (blank to generate)</TD></TR>
454 END
455
456     print '<TR><TD ALIGN="right">Access number</TD><TD WIDTH="100%">'
457           .
458           &FS::svc_acct_pop::popselector($popnum).
459           '</TD></TR></TABLE>'
460           ;
461   }
462 }
463
464 my $otaker = $cust_main->otaker;
465 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
466       qq!<BR><INPUT NAME="submit" TYPE="submit" VALUE="!,
467       $custnum ?  "Apply Changes" : "Add Customer", qq!">!,
468       "</FORM></BODY></HTML>",
469 ;
470
471 %>