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') );
68 my $action = $custnum ? 'Edit' : 'Add';
69 $action .= ": ". $cust_main->name if $custnum;
71 my $r = qq!<font color="#ff0000">*</font> !;
77 <%= include('/elements/header.html',
80 ' onUnload="myclose()"'
84 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT><BR><BR>
87 <FORM NAME="topform" STYLE="margin-bottom: 0">
88 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
89 <% if ( $custnum ) { %>
90 Customer #<B><%= $custnum %></B> -
91 <B><FONT COLOR="<%= $cust_main->statuscolor %>">
92 <%= ucfirst($cust_main->status) %>
97 <%= &ntable("#cccccc") %>
101 <%= include('/elements/tr-select-agent.html', $cust_main->agentnum,
102 'label' => "<B>${r}Agent</B>",
103 'empty_label' => 'Select agent',
107 <!-- referral (advertising source) -->
110 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
111 if ( $custnum && ! $conf->exists('editreferrals') ) {
114 <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
118 <%= include('/elements/tr-select-part_referral.html') %>
122 <!-- referring customer -->
125 my $referring_cust_main = '';
126 if ( $cust_main->referral_custnum
127 and $referring_cust_main =
128 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
133 <TD ALIGN="right">Referring customer</TD>
135 <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A>
138 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<%= $cust_main->referral_custnum %>">
140 <% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %>
143 <TD ALIGN="right">Referring customer</TD>
145 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
146 <%= include('/elements/search-cust_main.html',
147 'field_name' => 'referral_custnum',
155 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
161 <!-- contact info -->
165 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
167 <!-- service address -->
169 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
172 function bill_changed(what) {
173 if ( what.form.same.checked ) {
174 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
175 what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
178 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
179 function fix_ship_state() {
180 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
182 ship_country_changed(what.form.ship_country, fix_ship_state );
184 function fix_ship_county() {
185 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
187 ship_state_changed(what.form.ship_state, fix_ship_county );
190 function samechanged(what) {
191 if ( what.checked ) {
193 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
194 what.form.ship_<%=$_%>.disabled = true;
195 what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
198 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
199 what.form.ship_<%=$_%>.disabled = false;
200 what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
209 my $disabledselect = '';
210 unless ( $cust_main->ship_last && $same ne 'Y' ) {
211 $checked = 'CHECKED';
212 $disabled = 'DISABLED style="background-color: #dddddd"';
214 qw( last first company address1 address2 city county state zip country
217 $cust_main->set("ship_$_", $cust_main->get($_) );
224 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
225 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
229 <!-- billing info -->
231 <%= include( 'cust_main/billing.html', $cust_main,
232 'invoicing_list' => \@invoicing_list,
237 function bottomfixup(what) {
239 var topvars = new Array(
240 'custnum', 'agentnum', 'refnum', 'referral_custnum',
242 'last', 'first', 'ss', 'company',
243 'address1', 'address2', 'city',
244 'county', 'state', 'zip', 'country',
245 'daytime', 'night', 'fax',
249 'ship_last', 'ship_first', 'ship_company',
250 'ship_address1', 'ship_address2', 'ship_city',
251 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
252 'ship_daytime','ship_night', 'ship_fax',
257 var layervars = new Array(
259 'payinfo', 'payinfo1', 'payinfo2',
260 'payname', 'exp_month', 'exp_year', 'paycvv',
261 'paystart_month', 'paystart_year', 'payissue',
266 var billing_bottomvars = new Array(
268 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
272 for ( f=0; f < topvars.length; f++ ) {
273 var field = topvars[f];
274 copyelement( document.topform.elements[field],
275 document.bottomform.elements[field]
279 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
280 for ( f=0; f < layervars.length; f++ ) {
281 var field = layervars[f];
282 copyelement( document.forms[layerform].elements[field],
283 document.bottomform.elements[field]
287 for ( f=0; f < billing_bottomvars.length; f++ ) {
288 var field = billing_bottomvars[f];
289 copyelement( document.billing_bottomform.elements[field],
290 document.bottomform.elements[field]
296 function copyelement(from, to) {
297 if ( from == undefined ) {
299 } else if ( from.type == 'select-one' ) {
300 to.value = from.options[from.selectedIndex].value;
301 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
302 } else if ( from.type == 'checkbox' ) {
303 if ( from.checked ) {
304 to.value = from.value;
309 if ( from.value == undefined ) {
312 to.value = from.value;
315 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
320 <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">
322 <% foreach my $hidden (
323 'custnum', 'agentnum', 'refnum', 'referral_custnum',
324 'last', 'first', 'ss', 'company',
325 'address1', 'address2', 'city',
326 'county', 'state', 'zip', 'country',
327 'daytime', 'night', 'fax',
331 'ship_last', 'ship_first', 'ship_company',
332 'ship_address1', 'ship_address2', 'ship_city',
333 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
334 'ship_daytime','ship_night', 'ship_fax',
339 'payinfo', 'payinfo1', 'payinfo2',
340 'payname', 'exp_month', 'exp_year', 'paycvv',
341 'paystart_month', 'paystart_year', 'payissue',
346 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
350 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
354 <%= &ntable("#cccccc") %>
357 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
364 unless ( $custnum ) {
365 # pry the wrong place for this logic. also pretty expensive
368 #false laziness, copied from FS::cust_pkg::order
370 my @agents = $FS::CurrentUser::CurrentUser->agents;
371 if ( scalar(@agents) == 1 ) {
372 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
373 $pkgpart = $agents[0]->pkgpart_hashref;
375 #can't know (agent not chosen), so, allow all
377 foreach my $agent ( @agents ) {
378 next if $typenum{$agent->typenum}++;
379 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
380 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
385 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
386 qsearch( 'part_pkg', { 'disabled' => '' } );
390 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
391 #apiabuse & undesirable wrapping
395 <%= ntable("#cccccc") %>
399 <SELECT NAME="pkgpart_svcpart">
400 <OPTION VALUE="">(none)
402 <% foreach my $part_pkg ( @part_pkg ) { %>
404 <OPTION VALUE="<%= $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct') %>"<%= ( $saved_pkgpart && $part_pkg->pkgpart == $saved_pkgpart ) ? ' SELECTED' : '' %>><%= $part_pkg->pkg. " - ". $part_pkg->comment %>
412 #false laziness: (mostly) copied from edit/svc_acct.cgi
413 #$ulen = $svc_acct->dbdef_table->column('username')->length;
414 my $ulen = dbdef->table('svc_acct')->column('username')->length;
416 my $passwordmax = $conf->config('passwordmax') || 8;
417 my $pmax2 = $passwordmax + 2;
421 <TD ALIGN="right">Username</TD>
423 <INPUT TYPE="text" NAME="username" VALUE="<%= $username %>" SIZE=<%= $ulen2 %> MAXLENGTH=<%= $ulen %>>
428 <TD ALIGN="right">Password</TD>
430 <INPUT TYPE="text" NAME="_password" VALUE="<%= $password %>" SIZE=<%= $pmax2 %> MAXLENGTH=<%= $passwordmax %>>
436 <TD ALIGN="right">Access number</TD>
437 <TD><%= FS::svc_acct_pop::popselector($popnum) %></TD>
445 <INPUT TYPE="hidden" NAME="otaker" VALUE="<%= $cust_main->otaker %>">
447 <INPUT TYPE="submit" NAME="submit" VALUE="<%= $custnum ? "Apply Changes" : "Add Customer" %>">
451 <%= include('/elements/footer.html') %>