3 #for misplaced logic below
6 #for false laziness below (now more properly lazy)
9 #for (other) false laziness below
13 my $conf = new FS::Conf;
18 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart);
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')
26 $custnum = $cust_main->custnum;
27 $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
28 if ( $saved_pkgpart =~ /^(\d+)_/ ) {
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 $same = $cgi->param('same');
38 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
39 } elsif ( $cgi->keywords ) { #editing
40 my( $query ) = $cgi->keywords;
43 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
44 if ( $cust_main->dbdef_table->column('paycvv')
45 && length($cust_main->paycvv) ) {
46 my $paycvv = $cust_main->paycvv;
48 $cust_main->paycvv($paycvv);
54 @invoicing_list = $cust_main->invoicing_list;
57 $cust_main = new FS::cust_main ( {} );
58 $cust_main->otaker( &getotaker );
59 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
67 my $action = $custnum ? 'Edit' : 'Add';
69 my $r = qq!<font color="#ff0000">*</font> !;
75 <%= include('/elements/header.html',
78 ' onUnload="myclose()"'
82 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT><BR><BR>
85 <FORM NAME="topform" STYLE="margin-bottom: 0">
86 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
87 <% if ( $custnum ) { %>
88 Customer #<B><%= $custnum %></B> -
89 <B><FONT COLOR="<%= $cust_main->statuscolor %>">
90 <%= ucfirst($cust_main->status) %>
95 <%= &ntable("#cccccc") %>
99 <%= include('/elements/tr-select-agent.html', $cust_main->agentnum,
100 'label' => "<B>${r}Agent</B>",
101 'empty_label' => 'Select agent',
105 <!-- referral (advertising source) -->
108 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
109 if ( $custnum && ! $conf->exists('editreferrals') ) {
112 <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
116 <%= include('/elements/tr-select-part_referral.html') %>
120 <!-- referring customer -->
123 my $referring_cust_main = '';
124 if ( $cust_main->referral_custnum
125 and $referring_cust_main =
126 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
131 <TD ALIGN="right">Referring customer</TD>
133 <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A>
136 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<%= $cust_main->referral_custnum %>">
138 <% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %>
141 <TD ALIGN="right">Referring customer</TD>
142 <TD><INPUT TYPE="text" NAME="referral_custnum" VALUE=""></TD>
147 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
153 <!-- contact info -->
157 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
159 <!-- service address -->
161 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
164 function bill_changed(what) {
165 if ( what.form.same.checked ) {
166 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
167 what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
170 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
171 function fix_ship_state() {
172 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
174 ship_country_changed(what.form.ship_country, fix_ship_state );
176 function fix_ship_county() {
177 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
179 ship_state_changed(what.form.ship_state, fix_ship_county );
182 function samechanged(what) {
183 if ( what.checked ) {
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';
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';
201 my $disabledselect = '';
202 unless ( $cust_main->ship_last && $same ne 'Y' ) {
203 $checked = 'CHECKED';
204 $disabled = 'DISABLED style="background-color: #dddddd"';
206 qw( last first company address1 address2 city county state zip country
209 $cust_main->set("ship_$_", $cust_main->get($_) );
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 ) %>
221 <!-- billing info -->
223 <%= include( 'cust_main/billing.html', $cust_main,
224 'invoicing_list' => \@invoicing_list,
229 function bottomfixup(what) {
231 var topvars = new Array(
232 'custnum', 'agentnum', 'refnum', 'referral_custnum',
234 'last', 'first', 'ss', 'company',
235 'address1', 'address2', 'city',
236 'county', 'state', 'zip', 'country',
237 'daytime', 'night', 'fax',
241 'ship_last', 'ship_first', 'ship_company',
242 'ship_address1', 'ship_address2', 'ship_city',
243 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
244 'ship_daytime','ship_night', 'ship_fax',
249 var layervars = new Array(
251 'payinfo', 'payinfo1', 'payinfo2',
252 'payname', 'exp_month', 'exp_year', 'paycvv',
253 'paystart_month', 'paystart_year', 'payissue',
258 var billing_bottomvars = new Array(
260 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
264 for ( f=0; f < topvars.length; f++ ) {
265 var field = topvars[f];
266 copyelement( document.topform.elements[field],
267 document.bottomform.elements[field]
271 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
272 for ( f=0; f < layervars.length; f++ ) {
273 var field = layervars[f];
274 copyelement( document.forms[layerform].elements[field],
275 document.bottomform.elements[field]
279 for ( f=0; f < billing_bottomvars.length; f++ ) {
280 var field = billing_bottomvars[f];
281 copyelement( document.billing_bottomform.elements[field],
282 document.bottomform.elements[field]
288 function copyelement(from, to) {
289 if ( from == undefined ) {
291 } else if ( from.type == 'select-one' ) {
292 to.value = from.options[from.selectedIndex].value;
293 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
294 } else if ( from.type == 'checkbox' ) {
295 if ( from.checked ) {
296 to.value = from.value;
301 if ( from.value == undefined ) {
304 to.value = from.value;
307 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
312 <FORM ACTION="<%= popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" onSubmit="document.bottomform.submit.disabled=true; bottomfixup(this.form);" STYLE="margin-top: 0; margin-bottom: 0">
314 <% foreach my $hidden (
315 'custnum', 'agentnum', 'refnum', 'referral_custnum',
316 'last', 'first', 'ss', 'company',
317 'address1', 'address2', 'city',
318 'county', 'state', 'zip', 'country',
319 'daytime', 'night', 'fax',
323 'ship_last', 'ship_first', 'ship_company',
324 'ship_address1', 'ship_address2', 'ship_city',
325 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
326 'ship_daytime','ship_night', 'ship_fax',
331 'payinfo', 'payinfo1', 'payinfo2',
332 'payname', 'exp_month', 'exp_year', 'paycvv',
333 'paystart_month', 'paystart_year', 'payissue',
338 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
342 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
346 <%= &ntable("#cccccc") %>
349 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
356 unless ( $custnum ) {
357 # pry the wrong place for this logic. also pretty expensive
360 #false laziness, copied from FS::cust_pkg::order
362 my @agents = $FS::CurrentUser::CurrentUser->agents;
363 if ( scalar(@agents) == 1 ) {
364 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
365 $pkgpart = $agents[0]->pkgpart_hashref;
367 #can't know (agent not chosen), so, allow all
369 foreach my $agent ( @agents ) {
370 next if $typenum{$agent->typenum}++;
371 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
372 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
377 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
378 qsearch( 'part_pkg', { 'disabled' => '' } );
382 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
383 #apiabuse & undesirable wrapping
387 <%= ntable("#cccccc") %>
391 <SELECT NAME="pkgpart_svcpart">
392 <OPTION VALUE="">(none)
394 <% foreach my $part_pkg ( @part_pkg ) { %>
396 <OPTION VALUE="<%= $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct') %>"<%= ( $saved_pkgpart && $part_pkg->pkgpart == $saved_pkgpart ) ? ' SELECTED' : '' %>><%= $part_pkg->pkg. " - ". $part_pkg->comment %>
404 #false laziness: (mostly) copied from edit/svc_acct.cgi
405 #$ulen = $svc_acct->dbdef_table->column('username')->length;
406 my $ulen = dbdef->table('svc_acct')->column('username')->length;
408 my $passwordmax = $conf->config('passwordmax') || 8;
409 my $pmax2 = $passwordmax + 2;
413 <TD ALIGN="right">Username</TD>
415 <INPUT TYPE="text" NAME="username" VALUE="<%= $username %>" SIZE=<%= $ulen2 %> MAXLENGTH=<%= $ulen %>>
420 <TD ALIGN="right">Password</TD>
422 <INPUT TYPE="text" NAME="_password" VALUE="<%= $password %>" SIZE=<%= $pmax2 %> MAXLENGTH=<%= $passwordmax %>>
428 <TD ALIGN="right">Access number</TD>
429 <TD><%= FS::svc_acct_pop::popselector($popnum) %></TD>
437 <INPUT TYPE="hidden" NAME="otaker" VALUE="<%= $cust_main->otaker %>">
439 <INPUT TYPE="submit" NAME="submit" VALUE="<%= $custnum ? "Apply Changes" : "Add Customer" %>">
443 <%= include('/elements/footer.html') %>