1 package FS::SelfService;
4 use vars qw( $VERSION @ISA @EXPORT_OK $DEBUG
5 $skip_uid_check $dir $socket %autoload $tag );
11 use Storable 2.09 qw(nstore_fd fd_retrieve);
15 @ISA = qw( Exporter );
19 $dir = "/usr/local/freeside";
20 $socket = "$dir/selfservice_socket";
21 $socket .= '.'.$tag if defined $tag && length($tag);
23 #maybe should ask ClientAPI for this list
25 'passwd' => 'passwd/passwd',
26 'chfn' => 'passwd/passwd',
27 'chsh' => 'passwd/passwd',
28 'login_info' => 'MyAccount/login_info',
29 'login' => 'MyAccount/login',
30 'logout' => 'MyAccount/logout',
31 'switch_acct' => 'MyAccount/switch_acct',
32 'customer_info' => 'MyAccount/customer_info',
33 'customer_info_short' => 'MyAccount/customer_info_short',
34 'edit_info' => 'MyAccount/edit_info', #add to ss cgi!
35 'invoice' => 'MyAccount/invoice',
36 'invoice_pdf' => 'MyAccount/invoice_pdf',
37 'legacy_invoice' => 'MyAccount/legacy_invoice',
38 'legacy_invoice_pdf' => 'MyAccount/legacy_invoice_pdf',
39 'invoice_logo' => 'MyAccount/invoice_logo',
40 'list_invoices' => 'MyAccount/list_invoices', #?
41 'cancel' => 'MyAccount/cancel', #add to ss cgi!
42 'payment_info' => 'MyAccount/payment_info',
43 'payment_info_renew_info' => 'MyAccount/payment_info_renew_info',
44 'process_payment' => 'MyAccount/process_payment',
45 'store_payment' => 'MyAccount/store_payment',
46 'process_stored_payment' => 'MyAccount/process_stored_payment',
47 'process_payment_order_pkg' => 'MyAccount/process_payment_order_pkg',
48 'process_payment_change_pkg' => 'MyAccount/process_payment_change_pkg',
49 'process_payment_order_renew' => 'MyAccount/process_payment_order_renew',
50 'process_prepay' => 'MyAccount/process_prepay',
51 'realtime_collect' => 'MyAccount/realtime_collect',
52 'list_pkgs' => 'MyAccount/list_pkgs', #add to ss (added?)
53 'list_svcs' => 'MyAccount/list_svcs', #add to ss (added?)
54 'list_svc_usage' => 'MyAccount/list_svc_usage',
55 'list_dsl_devices' => 'MyAccount/list_dsl_devices',
56 'add_dsl_device' => 'MyAccount/add_dsl_device',
57 'delete_dsl_device' => 'MyAccount/delete_dsl_device',
58 'port_graph' => 'MyAccount/port_graph',
59 'list_cdr_usage' => 'MyAccount/list_cdr_usage',
60 'list_support_usage' => 'MyAccount/list_support_usage',
61 'order_pkg' => 'MyAccount/order_pkg', #add to ss cgi!
62 'change_pkg' => 'MyAccount/change_pkg',
63 'order_recharge' => 'MyAccount/order_recharge',
64 'renew_info' => 'MyAccount/renew_info',
65 'order_renew' => 'MyAccount/order_renew',
66 'cancel_pkg' => 'MyAccount/cancel_pkg', #add to ss cgi!
67 'suspend_pkg' => 'MyAccount/suspend_pkg', #add to ss cgi!
68 'charge' => 'MyAccount/charge', #?
69 'part_svc_info' => 'MyAccount/part_svc_info',
70 'provision_acct' => 'MyAccount/provision_acct',
71 'provision_phone' => 'MyAccount/provision_phone',
72 'provision_external' => 'MyAccount/provision_external',
73 'unprovision_svc' => 'MyAccount/unprovision_svc',
74 'myaccount_passwd' => 'MyAccount/myaccount_passwd',
75 'reset_passwd' => 'MyAccount/reset_passwd',
76 'create_ticket' => 'MyAccount/create_ticket',
77 'get_ticket' => 'MyAccount/get_ticket',
78 'adjust_ticket_priority' => 'MyAccount/adjust_ticket_priority',
79 'did_report' => 'MyAccount/did_report',
80 'signup_info' => 'Signup/signup_info',
81 'skin_info' => 'MyAccount/skin_info',
82 'access_info' => 'MyAccount/access_info',
83 'domain_select_hash' => 'Signup/domain_select_hash', # expose?
84 'new_customer' => 'Signup/new_customer',
85 'capture_payment' => 'Signup/capture_payment',
86 #N/A 'clear_signup_cache' => 'Signup/clear_cache',
87 'new_agent' => 'Agent/new_agent',
88 'agent_login' => 'Agent/agent_login',
89 'agent_logout' => 'Agent/agent_logout',
90 'agent_info' => 'Agent/agent_info',
91 'agent_list_customers' => 'Agent/agent_list_customers',
92 'check_username' => 'Agent/check_username',
93 'suspend_username' => 'Agent/suspend_username',
94 'unsuspend_username' => 'Agent/unsuspend_username',
95 'mason_comp' => 'MasonComponent/mason_comp',
96 'call_time' => 'PrepaidPhone/call_time',
97 'call_time_nanpa' => 'PrepaidPhone/call_time_nanpa',
98 'phonenum_balance' => 'PrepaidPhone/phonenum_balance',
100 #'bulk_processrow' => 'Bulk/processrow',
101 #conflicts w/Agent one# 'check_username' => 'Bulk/check_username',
103 'ping' => 'SGNG/ping',
104 'decompify_pkgs' => 'SGNG/decompify_pkgs',
105 'previous_payment_info' => 'SGNG/previous_payment_info',
106 'previous_payment_info_renew_info'
107 => 'SGNG/previous_payment_info_renew_info',
108 'previous_process_payment' => 'SGNG/previous_process_payment',
109 'previous_process_payment_order_pkg'
110 => 'SGNG/previous_process_payment_order_pkg',
111 'previous_process_payment_change_pkg'
112 => 'SGNG/previous_process_payment_change_pkg',
113 'previous_process_payment_order_renew'
114 => 'SGNG/previous_process_payment_order_renew',
118 qw( regionselector regionselector_hashref location_form
119 expselect popselector domainselector didselector
123 $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
124 $ENV{'SHELL'} = '/bin/sh';
125 $ENV{'IFS'} = " \t\n";
128 $ENV{'BASH_ENV'} = '';
130 #you can add BEGIN { $FS::SelfService::skip_uid_check = 1; }
131 #if you grant appropriate permissions to whatever user
132 my $freeside_uid = scalar(getpwnam('freeside'));
133 die "not running as the freeside user\n"
134 if $> != $freeside_uid && ! $skip_uid_check;
136 -e $dir or die "FATAL: $dir doesn't exist!";
137 -d $dir or die "FATAL: $dir isn't a directory!";
138 -r $dir or die "FATAL: Can't read $dir as freeside user!";
139 -x $dir or die "FATAL: $dir not searchable (executable) as freeside user!";
141 foreach my $autoload ( keys %autoload ) {
144 "sub $autoload { ". '
149 #warn scalar(@_). ": ". join(" / ", @_);
153 $param->{_packet} = \''. $autoload{$autoload}. '\';
155 simple_packet($param);
165 warn "sending ". $packet->{_packet}. " to server"
167 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
168 connect(SOCK, sockaddr_un($socket)) or die "connect to $socket: $!";
169 nstore_fd($packet, \*SOCK) or die "can't send packet: $!";
172 #shoudl trap: Magic number checking on storable file failed at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/fd_retrieve.al) line 337, at /usr/local/share/perl/5.6.1/FS/SelfService.pm line 71
174 #block until there is a message on socket
175 # my $w = new IO::Select;
177 # my @wait = $w->can_read;
179 warn "reading message from server"
182 my $return = fd_retrieve(\*SOCK) or die "error reading result: $!";
183 die $return->{'_error'} if defined $return->{_error} && $return->{_error};
185 warn "returning message to client"
193 FS::SelfService - Freeside self-service API
197 # password and shell account changes
198 use FS::SelfService qw(passwd chfn chsh);
200 # "my account" functionality
201 use FS::SelfService qw( login customer_info invoice cancel payment_info process_payment );
203 my $rv = login( { 'username' => $username,
205 'password' => $password,
209 if ( $rv->{'error'} ) {
210 #handle login error...
213 my $session_id = $rv->{'session_id'};
216 my $customer_info = customer_info( { 'session_id' => $session_id } );
218 #payment_info and process_payment are available in 1.5+ only
219 my $payment_info = payment_info( { 'session_id' => $session_id } );
221 #!!! process_payment example
223 #!!! list_pkgs example
225 #!!! order_pkg example
227 #!!! cancel_pkg example
229 # signup functionality
230 use FS::SelfService qw( signup_info new_customer );
232 my $signup_info = signup_info;
234 $rv = new_customer( {
237 'company' => $company,
238 'address1' => $address1,
239 'address2' => $address2,
243 'country' => $country,
244 'daytime' => $daytime,
248 'payinfo' => $payinfo,
250 'paystart_month' => $paystart_month
251 'paystart_year' => $paystart_year,
252 'payissue' => $payissue,
254 'paydate' => $paydate,
255 'payname' => $payname,
256 'invoicing_list' => $invoicing_list,
257 'referral_custnum' => $referral_custnum,
258 'agentnum' => $agentnum,
259 'pkgpart' => $pkgpart,
261 'username' => $username,
262 '_password' => $password,
266 'phonenum' => $phonenum,
271 my $error = $rv->{'error'};
272 if ( $error eq '_decline' ) {
282 Use this API to implement your own client "self-service" module.
284 If you just want to customize the look of the existing "self-service" module,
287 =head1 PASSWORD, GECOS, SHELL CHANGING FUNCTIONS
299 =head1 "MY ACCOUNT" FUNCTIONS
305 Creates a user session. Takes a hash reference as parameter with the
324 Returns a hash reference with the following keys:
330 Empty on success, or an error message on errors.
334 Session identifier for successful logins
338 =item customer_info HASHREF
340 Returns general customer information.
342 Takes a hash reference as parameter with a single key: B<session_id>
344 Returns a hash reference with the following keys:
358 Array reference of hash references of open inoices. Each hash reference has
359 the following keys: invnum, date, owed
363 An HTML fragment containing shipping and billing addresses.
365 =item The following fields are also returned
367 first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax payby payinfo payname month year invoicing_list postal_invoicing
371 =item edit_info HASHREF
373 Takes a hash reference as parameter with any of the following keys:
375 first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax payby payinfo paycvv payname month year invoicing_list postal_invoicing
377 If a field exists, the customer record is updated with the new value of that
378 field. If a field does not exist, that field is not changed on the customer
381 Returns a hash reference with a single key, B<error>, empty on success, or an
382 error message on errors
384 =item invoice HASHREF
386 Returns an invoice. Takes a hash reference as parameter with two keys:
387 session_id and invnum
389 Returns a hash reference with the following keys:
395 Empty on success, or an error message on errors
407 =item list_invoices HASHREF
409 Returns a list of all customer invoices. Takes a hash references with a single
412 Returns a hash reference with the following keys:
418 Empty on success, or an error message on errors
422 Reference to array of hash references with the following keys:
432 Invoice date, in UNIX epoch time
440 Cancels this customer.
442 Takes a hash reference as parameter with a single key: B<session_id>
444 Returns a hash reference with a single key, B<error>, which is empty on
445 success or an error message on errors.
447 =item payment_info HASHREF
449 Returns information that may be useful in displaying a payment page.
451 Takes a hash reference as parameter with a single key: B<session_id>.
453 Returns a hash reference with the following keys:
459 Empty on success, or an error message on errors
467 Exact name on credit card (CARD/DCRD)
491 Customer's current default payment type.
495 For CARD/DCRD payment types, the card type (Visa card, MasterCard, Discover card, American Express card, etc.)
499 For CARD/DCRD payment types, the card number
503 For CARD/DCRD payment types, expiration month
507 For CARD/DCRD payment types, expiration year
509 =item cust_main_county
511 County/state/country data - array reference of hash references, each of which has the fields of a cust_main_county record (see L<FS::cust_main_county>). Note these are not FS::cust_main_county objects, but hash references of columns and values.
515 Array reference of all states in the current default country.
519 Hash reference of card types; keys are card types, values are the exact strings
520 passed to the process_payment function
524 #this doesn't actually work yet
528 #Unique transaction identifier (prevents multiple charges), passed to the
529 #process_payment function
533 =item process_payment HASHREF
535 Processes a payment and possible change of address or payment type. Takes a
536 hash reference as parameter with the following keys:
550 If true, address and card information entered will be saved for subsequent
555 If true, future credit card payments will be done automatically (sets payby to
556 CARD). If false, future credit card payments will be done on-demand (sets
557 payby to DCRD). This option only has meaning if B<save> is set true.
585 Two-letter country code
593 Card expiration month
601 #this doesn't actually work yet
605 #Unique transaction identifier, returned from the payment_info function.
606 #Prevents multiple charges.
610 Returns a hash reference with a single key, B<error>, empty on success, or an
611 error message on errors.
613 =item process_payment_order_pkg
615 Combines the B<process_payment> and B<order_pkg> functions in one step. If the
616 payment processes sucessfully, the package is ordered. Takes a hash reference
617 as parameter with the keys of both methods.
619 Returns a hash reference with a single key, B<error>, empty on success, or an
620 error message on errors.
622 =item process_payment_change_pkg
624 Combines the B<process_payment> and B<change_pkg> functions in one step. If the
625 payment processes sucessfully, the package is ordered. Takes a hash reference
626 as parameter with the keys of both methods.
628 Returns a hash reference with a single key, B<error>, empty on success, or an
629 error message on errors.
632 =item process_payment_order_renew
634 Combines the B<process_payment> and B<order_renew> functions in one step. If
635 the payment processes sucessfully, the renewal is processed. Takes a hash
636 reference as parameter with the keys of both methods.
638 Returns a hash reference with a single key, B<error>, empty on success, or an
639 error message on errors.
643 Returns package information for this customer. For more detail on services,
646 Takes a hash reference as parameter with a single key: B<session_id>
648 Returns a hash reference containing customer package information. The hash reference contains the following keys:
658 Empty on success, or an error message on errors.
660 =item cust_pkg HASHREF
662 Array reference of hash references, each of which has the fields of a cust_pkg
663 record (see L<FS::cust_pkg>) as well as the fields below. Note these are not
664 the internal FS:: objects, but hash references of columns and values.
668 =item part_pkg fields
670 All fields of part_pkg for this specific cust_pkg (be careful with this
671 information - it may reveal more about your available packages than you would
672 like users to know in aggregate)
676 #XXX pare part_pkg fields down to a more secure subset
680 An array of hash references indicating information on unprovisioned services
681 available for provisioning for this specific cust_pkg. Each has the following
686 =item part_svc fields
688 All fields of part_svc (be careful with this information - it may reveal more
689 about your available packages than you would like users to know in aggregate)
693 #XXX pare part_svc fields down to a more secure subset
699 An array of hash references indicating information on the customer services
700 already provisioned for this specific cust_pkg. Each has the following keys:
706 Array reference with three elements: The first element is the name of this service. The second element is a meaningful user-specific identifier for the service (i.e. username, domain or mail alias). The last element is the table name of this service.
712 Primary key for this service
716 Service definition (see L<FS::part_svc>)
720 Customer package (see L<FS::cust_pkg>)
724 Blank if the service is not over limit, or the date the service exceeded its usage limit (as a UNIX timestamp).
732 Returns service information for this customer.
734 Takes a hash reference as parameter with a single key: B<session_id>
736 Returns a hash reference containing customer package information. The hash reference contains the following keys:
746 An array of hash references indicating information on all of this customer's
747 services. Each has the following keys:
753 Primary key for this service
761 Meaningful user-specific identifier for the service (i.e. username, domain, or
766 Account (svc_acct) services also have the following keys:
784 Upload bytes remaining
788 Download bytes remaining
792 Total bytes remaining
794 =item recharge_amount
798 =item recharge_seconds
800 Number of seconds gained by recharge
802 =item recharge_upbytes
804 Number of upload bytes gained by recharge
806 =item recharge_downbytes
808 Number of download bytes gained by recharge
810 =item recharge_totalbytes
812 Number of total bytes gained by recharge
820 Orders a package for this customer.
822 Takes a hash reference as parameter with the following keys:
832 Package to order (see L<FS::part_pkg>).
836 Service to order (see L<FS::part_svc>).
838 Normally optional; required only to provision a non-svc_acct service, or if the
839 package definition does not contain one svc_acct service definition with
840 quantity 1 (it may contain others with quantity >1). A svcpart of "none" can
841 also be specified to indicate that no initial service should be provisioned.
845 Fields used when provisioning an svc_acct service:
859 Optional security phrase
863 Optional Access number number
867 Fields used when provisioning an svc_domain service:
877 Fields used when provisioning an svc_phone service:
895 Fields used when provisioning an svc_external service:
909 Fields used when provisioning an svc_pbx service:
923 Returns a hash reference with a single key, B<error>, empty on success, or an
924 error message on errors. The special error '_decline' is returned for
925 declined transactions.
929 Changes a package for this customer.
931 Takes a hash reference as parameter with the following keys:
941 Existing customer package.
945 New package to order (see L<FS::part_pkg>).
949 Returns a hash reference with the following keys:
955 Empty on success, or an error message on errors.
959 On success, the new pkgnum
966 Provides useful info for early renewals.
968 Takes a hash reference as parameter with the following keys:
978 Returns a hash reference. On errors, it contains a single key, B<error>, with
979 the error message. Otherwise, contains a single key, B<dates>, pointing to
980 an array refernce of hash references. Each hash reference contains the
987 (Future) Bill date. Indicates a future date for which billing could be run.
988 Specified as a integer UNIX timestamp. Pass this value to the B<order_renew>
991 =item bill_date_pretty
993 (Future) Bill date as a human-readable string. (Convenience for display;
994 subject to change, so best not to parse for the date.)
998 Base amount which will be charged if renewed early as of this date.
1002 Renewal date; i.e. even-futher future date at which the customer will be paid
1003 through if the early renewal is completed with the given B<bill-date>.
1004 Specified as a integer UNIX timestamp.
1006 =item renew_date_pretty
1008 Renewal date as a human-readable string. (Convenience for display;
1009 subject to change, so best not to parse for the date.)
1013 Package that will be renewed.
1017 Expiration date of the package that will be renewed.
1019 =item expire_date_pretty
1021 Expiration date of the package that will be renewed, as a human-readable
1022 string. (Convenience for display; subject to change, so best not to parse for
1029 Renews this customer early; i.e. runs billing for this customer in advance.
1031 Takes a hash reference as parameter with the following keys:
1041 Integer date as returned by the B<renew_info> function, indicating the advance
1042 date for which to run billing.
1046 Returns a hash reference with a single key, B<error>, empty on success, or an
1047 error message on errors.
1051 Cancels a package for this customer.
1053 Takes a hash reference as parameter with the following keys:
1063 pkgpart of package to cancel
1067 Returns a hash reference with a single key, B<error>, empty on success, or an
1068 error message on errors.
1072 =head1 SIGNUP FUNCTIONS
1076 =item signup_info HASHREF
1078 Takes a hash reference as parameter with the following keys:
1082 =item session_id - Optional agent/reseller interface session
1086 Returns a hash reference containing information that may be useful in
1087 displaying a signup page. The hash reference contains the following keys:
1091 =item cust_main_county
1093 County/state/country data - array reference of hash references, each of which has the fields of a cust_main_county record (see L<FS::cust_main_county>). Note these are not FS::cust_main_county objects, but hash references of columns and values.
1097 Available packages - array reference of hash references, each of which has the fields of a part_pkg record (see L<FS::part_pkg>). Each hash reference also has an additional 'payby' field containing an array reference of acceptable payment types specific to this package (see below and L<FS::part_pkg/payby>). Note these are not FS::part_pkg objects, but hash references of columns and values. Requires the 'signup_server-default_agentnum' configuration value to be set, or
1098 an agentnum specified explicitly via reseller interface session_id in the
1103 Array reference of hash references, each of which has the fields of an agent record (see L<FS::agent>). Note these are not FS::agent objects, but hash references of columns and values.
1105 =item agentnum2part_pkg
1107 Hash reference; keys are agentnums, values are array references of available packages for that agent, in the same format as the part_pkg arrayref above.
1111 Access numbers - array reference of hash references, each of which has the fields of an svc_acct_pop record (see L<FS::svc_acct_pop>). Note these are not FS::svc_acct_pop objects, but hash references of columns and values.
1113 =item security_phrase
1115 True if the "security_phrase" feature is enabled
1119 Array reference of acceptable payment types for signup
1125 credit card - automatic
1129 credit card - on-demand - version 1.5+ only
1133 electronic check - automatic
1137 electronic check - on-demand - version 1.5+ only
1145 billing, not recommended for signups
1149 free, definitely not recommended for signups
1153 special billing type: applies a credit (see FS::prepay_credit) and sets billing type to BILL
1159 True if CVV features are available (1.5+ or 1.4.2 with CVV schema patch)
1163 Hash reference of message catalog values, to support error message customization. Currently available keys are: passwords_dont_match, invalid_card, unknown_card_type, and not_a (as in "Not a Discover card"). Values are configured in the web interface under "View/Edit message catalog".
1169 =item countrydefault
1175 =item new_customer HASHREF
1177 Creates a new customer. Takes a hash reference as parameter with the
1184 first name (required)
1188 last name (required)
1192 (not typically collected; mostly used for ACH transactions)
1198 =item address1 (required)
1206 =item city (required)
1214 =item state (required)
1218 =item zip (required)
1224 Daytime phone number
1228 Evening phone number
1236 CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY (see L</signup_info> (required)
1240 Card number for CARD/DCRD, account_number@aba_number for CHEK/DCHK, prepaid "pin" for PREPAY, purchase order number for BILL
1244 Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
1248 Expiration date for CARD/DCRD
1252 Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
1254 =item invoicing_list
1256 comma-separated list of email addresses for email invoices. The special value 'POST' is used to designate postal invoicing (it may be specified alone or in addition to email addresses),
1258 =item referral_custnum
1260 referring customer number
1268 pkgpart of initial package
1284 Access number (index, not the literal number)
1288 Country code (to be provisioned as a service)
1292 Phone number (to be provisioned as a service)
1300 Returns a hash reference with the following keys:
1306 Empty on success, or an error message on errors. The special error '_decline' is returned for declined transactions; other error messages should be suitable for display to the user (and are customizable in under Configuration | View/Edit message catalog)
1310 =item regionselector HASHREF | LIST
1312 Takes as input a hashref or list of key/value pairs with the following keys:
1316 =item selected_county
1318 Currently selected county
1320 =item selected_state
1322 Currently selected state
1324 =item selected_country
1326 Currently selected country
1330 Specify a unique prefix string if you intend to use the HTML output multiple time son one page.
1334 Specify a javascript subroutine to call on changes
1340 =item default_country
1346 An arrayref of hash references specifying regions. Normally you can just pass the value of the I<cust_main_county> field returned by B<signup_info>.
1350 Returns a list consisting of three HTML fragments for county selection,
1351 state selection and country selection, respectively.
1355 #false laziness w/FS::cust_main_county (this is currently the "newest" version)
1356 sub regionselector {
1363 $param->{'selected_country'} ||= $param->{'default_country'};
1364 $param->{'selected_state'} ||= $param->{'default_state'};
1366 my $prefix = exists($param->{'prefix'}) ? $param->{'prefix'} : '';
1370 my %cust_main_county;
1372 # unless ( @cust_main_county ) { #cache
1373 #@cust_main_county = qsearch('cust_main_county', {} );
1374 #foreach my $c ( @cust_main_county ) {
1375 foreach my $c ( @{ $param->{'locales'} } ) {
1376 #$countyflag=1 if $c->county;
1377 $countyflag=1 if $c->{county};
1378 #push @{$cust_main_county{$c->country}{$c->state}}, $c->county;
1379 #$cust_main_county{$c->country}{$c->state}{$c->county} = 1;
1380 $cust_main_county{$c->{country}}{$c->{state}}{$c->{county}} = 1;
1383 $countyflag=1 if $param->{selected_county};
1385 my $script_html = <<END;
1387 function opt(what,value,text) {
1388 var optionName = new Option(text, value, false, false);
1389 var length = what.length;
1390 what.options[length] = optionName;
1392 function ${prefix}country_changed(what) {
1393 country = what.options[what.selectedIndex].text;
1394 for ( var i = what.form.${prefix}state.length; i >= 0; i-- )
1395 what.form.${prefix}state.options[i] = null;
1397 #what.form.${prefix}state.options[0] = new Option('', '', false, true);
1399 foreach my $country ( sort keys %cust_main_county ) {
1400 $script_html .= "\nif ( country == \"$country\" ) {\n";
1401 foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
1402 my $text = $state || '(n/a)';
1403 $script_html .= qq!opt(what.form.${prefix}state, "$state", "$text");\n!;
1405 $script_html .= "}\n";
1408 $script_html .= <<END;
1410 function ${prefix}state_changed(what) {
1413 if ( $countyflag ) {
1414 $script_html .= <<END;
1415 state = what.options[what.selectedIndex].text;
1416 country = what.form.${prefix}country.options[what.form.${prefix}country.selectedIndex].text;
1417 for ( var i = what.form.${prefix}county.length; i >= 0; i-- )
1418 what.form.${prefix}county.options[i] = null;
1421 foreach my $country ( sort keys %cust_main_county ) {
1422 $script_html .= "\nif ( country == \"$country\" ) {\n";
1423 foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
1424 $script_html .= "\nif ( state == \"$state\" ) {\n";
1425 #foreach my $county ( sort @{$cust_main_county{$country}{$state}} ) {
1426 foreach my $county ( sort keys %{$cust_main_county{$country}{$state}} ) {
1427 my $text = $county || '(n/a)';
1429 qq!opt(what.form.${prefix}county, "$county", "$text");\n!;
1431 $script_html .= "}\n";
1433 $script_html .= "}\n";
1437 $script_html .= <<END;
1442 my $county_html = $script_html;
1443 if ( $countyflag ) {
1444 $county_html .= qq!<SELECT NAME="${prefix}county" onChange="$param->{'onchange'}">!;
1445 foreach my $county (
1446 sort keys %{ $cust_main_county{$param->{'selected_country'}}{$param->{'selected_state'}} }
1448 my $text = $county || '(n/a)';
1449 $county_html .= qq!<OPTION VALUE="$county"!.
1450 ($county eq $param->{'selected_county'} ?
1457 $county_html .= '</SELECT>';
1460 qq!<INPUT TYPE="hidden" NAME="${prefix}county" VALUE="$param->{'selected_county'}">!;
1463 my $state_html = qq!<SELECT NAME="${prefix}state" !.
1464 qq!onChange="${prefix}state_changed(this); $param->{'onchange'}">!;
1465 foreach my $state ( sort keys %{ $cust_main_county{$param->{'selected_country'}} } ) {
1466 my $text = $state || '(n/a)';
1467 my $selected = $state eq $param->{'selected_state'} ? 'SELECTED' : '';
1468 $state_html .= "\n<OPTION $selected VALUE=$state>$text</OPTION>"
1470 $state_html .= '</SELECT>';
1472 my $country_html = '';
1473 if ( scalar( keys %cust_main_county ) > 1 ) {
1475 $country_html = qq(<SELECT NAME="${prefix}country" ).
1476 qq(onChange="${prefix}country_changed(this); ).
1477 $param->{'onchange'}.
1480 my $countrydefault = $param->{default_country} || 'US';
1481 foreach my $country (
1482 sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b }
1483 keys %cust_main_county
1485 my $selected = $country eq $param->{'selected_country'}
1488 $country_html .= "\n<OPTION$selected>$country</OPTION>"
1490 $country_html .= '</SELECT>';
1493 $country_html = qq(<INPUT TYPE="hidden" NAME="${prefix}country" ).
1494 ' VALUE="'. (keys %cust_main_county )[0]. '">';
1498 ($county_html, $state_html, $country_html);
1502 sub regionselector_hashref {
1503 my ($county_html, $state_html, $country_html) = regionselector(@_);
1505 'county_html' => $county_html,
1506 'state_html' => $state_html,
1507 'country_html' => $country_html,
1511 =item location_form HASHREF | LIST
1513 Takes as input a hashref or list of key/value pairs with the following keys:
1519 Current customer session_id
1523 Omit red asterisks from required fields.
1525 =item address1_label
1527 Label for first address line.
1531 Returns an HTML fragment for a location form (address, city, state, zip,
1544 my $session_id = delete $param->{'session_id'};
1546 my $rv = mason_comp( 'session_id' => $session_id,
1547 'comp' => '/elements/location.html',
1548 'args' => [ %$param ],
1552 $rv->{'error'} || $rv->{'output'};
1557 #=item expselect HASHREF | LIST
1559 #Takes as input a hashref or list of key/value pairs with the following keys:
1563 #=item prefix - Specify a unique prefix string if you intend to use the HTML output multiple time son one page.
1565 #=item date - current date, in yyyy-mm-dd or m-d-yyyy format
1569 =item expselect PREFIX [ DATE ]
1571 Takes as input a unique prefix string and the current expiration date, in
1572 yyyy-mm-dd or m-d-yyyy format
1574 Returns an HTML fragments for expiration date selection.
1580 #if ( ref($_[0]) ) {
1584 #my $prefix = $param->{'prefix'};
1585 #my $prefix = exists($param->{'prefix'}) ? $param->{'prefix'} : '';
1586 #my $date = exists($param->{'date'}) ? $param->{'date'} : '';
1588 my $date = scalar(@_) ? shift : '';
1590 my( $m, $y ) = ( 0, 0 );
1591 if ( $date =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
1592 ( $m, $y ) = ( $2, $1 );
1593 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
1594 ( $m, $y ) = ( $1, $3 );
1596 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
1598 $return .= qq!<OPTION VALUE="$_"!;
1599 $return .= " SELECTED" if $_ == $m;
1602 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
1604 my $thisYear = $t[5] + 1900;
1605 for ( ($thisYear > $y && $y > 0 ? $y : $thisYear) .. ($thisYear+10) ) {
1606 $return .= qq!<OPTION VALUE="$_"!;
1607 $return .= " SELECTED" if $_ == $y;
1610 $return .= "</SELECT>";
1615 =item popselector HASHREF | LIST
1617 Takes as input a hashref or list of key/value pairs with the following keys:
1623 Access number number
1627 An arrayref of hash references specifying access numbers. Normally you can just pass the value of the I<svc_acct_pop> field returned by B<signup_info>.
1631 Returns an HTML fragment for access number selection.
1635 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
1643 my $popnum = $param->{'popnum'};
1644 my $pops = $param->{'pops'};
1646 return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
1647 return $pops->[0]{city}. ', '. $pops->[0]{state}.
1648 ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}. '-'. $pops->[0]{loc}.
1649 '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
1650 if scalar(@$pops) == 1;
1653 my %popnum2pop = ();
1655 push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
1656 $popnum2pop{$_->{popnum}} = $_;
1661 function opt(what,href,text) {
1662 var optionName = new Option(text, href, false, false)
1663 var length = what.length;
1664 what.options[length] = optionName;
1668 my $init_popstate = $param->{'init_popstate'};
1669 if ( $init_popstate ) {
1670 $text .= '<INPUT TYPE="hidden" NAME="init_popstate" VALUE="'.
1671 $init_popstate. '">';
1674 function acstate_changed(what) {
1675 state = what.options[what.selectedIndex].text;
1676 what.form.popac.options.length = 0
1677 what.form.popac.options[0] = new Option("Area code", "-1", false, true);
1681 my @states = $init_popstate ? ( $init_popstate ) : keys %pop;
1682 foreach my $state ( sort { $a cmp $b } @states ) {
1683 $text .= "\nif ( state == \"$state\" ) {\n" unless $init_popstate;
1685 foreach my $ac ( sort { $a cmp $b } keys %{ $pop{$state} }) {
1686 $text .= "opt(what.form.popac, \"$ac\", \"$ac\");\n";
1687 if ($ac eq $param->{'popac'}) {
1688 $text .= "what.form.popac.options[what.form.popac.length-1].selected = true;\n";
1691 $text .= "}\n" unless $init_popstate;
1693 $text .= "popac_changed(what.form.popac)}\n";
1696 function popac_changed(what) {
1697 ac = what.options[what.selectedIndex].text;
1698 what.form.popnum.options.length = 0;
1699 what.form.popnum.options[0] = new Option("City", "-1", false, true);
1703 foreach my $state ( @states ) {
1704 foreach my $popac ( keys %{ $pop{$state} } ) {
1705 $text .= "\nif ( ac == \"$popac\" ) {\n";
1707 foreach my $pop ( @{$pop{$state}->{$popac}}) {
1708 my $o_popnum = $pop->{popnum};
1709 my $poptext = $pop->{city}. ', '. $pop->{state}.
1710 ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
1712 $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n";
1713 if ($popnum == $o_popnum) {
1714 $text .= "what.form.popnum.options[what.form.popnum.length-1].selected = true;\n";
1722 $text .= "}\n</SCRIPT>\n";
1724 $param->{'acstate'} = '' unless defined($param->{'acstate'});
1727 qq!<TABLE CELLPADDING="0"><TR><TD><SELECT NAME="acstate"! .
1728 qq!SIZE=1 onChange="acstate_changed(this)"><OPTION VALUE=-1>State!;
1729 $text .= "<OPTION" . ($_ eq $param->{'acstate'} ? " SELECTED" : "") .
1730 ">$_" foreach sort { $a cmp $b } @states;
1731 $text .= '</SELECT>'; #callback? return 3 html pieces? #'</TD>';
1734 qq!<SELECT NAME="popac" SIZE=1 onChange="popac_changed(this)">!.
1735 qq!<OPTION>Area code</SELECT></TR><TR VALIGN="top">!;
1737 $text .= qq!<TR><TD><SELECT NAME="popnum" SIZE=1 STYLE="width: 20em"><OPTION>City!;
1740 #comment this block to disable initial list polulation
1741 my @initial_select = ();
1742 if ( scalar( @$pops ) > 100 ) {
1743 push @initial_select, $popnum2pop{$popnum} if $popnum2pop{$popnum};
1745 @initial_select = @$pops;
1747 foreach my $pop ( sort { $a->{state} cmp $b->{state} } @initial_select ) {
1748 $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
1749 ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
1750 $pop->{city}. ', '. $pop->{state}.
1751 ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
1754 $text .= qq!</SELECT></TD></TR></TABLE>!;
1760 =item domainselector HASHREF | LIST
1762 Takes as input a hashref or list of key/value pairs with the following keys:
1772 Service number of the selected item.
1776 Returns an HTML fragment for domain selection.
1780 sub domainselector {
1787 my $domsvc= $param->{'domsvc'};
1789 domain_select_hash(map {$_ => $param->{$_}} qw(pkgnum svcpart pkgpart) );
1790 my $domains = $rv->{'domains'};
1791 $domsvc = $rv->{'domsvc'} unless $domsvc;
1793 return '<INPUT TYPE="hidden" NAME="domsvc" VALUE="">'
1794 unless scalar(keys %$domains);
1796 if (scalar(keys %$domains) == 1) {
1798 foreach(keys %$domains) {
1801 return '<TR><TD ALIGN="right">Domain</TD><TD>'. $domains->{$key}.
1802 '<INPUT TYPE="hidden" NAME="domsvc" VALUE="'. $key. '"></TD></TR>'
1805 my $text .= qq!<TR><TD ALIGN="right">Domain</TD><TD><SELECT NAME="domsvc" SIZE=1 STYLE="width: 20em"><OPTION>(Choose Domain)!;
1808 foreach my $domain ( sort { $domains->{$a} cmp $domains->{$b} } keys %$domains ) {
1809 $text .= qq!<OPTION VALUE="!. $domain. '"'.
1810 ( ( $domsvc && $domain == $domsvc ) ? ' SELECTED' : '' ). ">".
1811 $domains->{$domain};
1814 $text .= qq!</SELECT></TD></TR>!;
1820 =item didselector HASHREF | LIST
1822 Takes as input a hashref or list of key/value pairs with the following keys:
1828 Field name for the returned HTML fragment.
1832 Service definition (see L<FS::part_svc>)
1836 Returns an HTML fragment for DID selection.
1848 my $rv = mason_comp( 'comp'=>'/elements/select-did.html',
1849 'args'=>[ %$param ],
1853 $rv->{'error'} || $rv->{'output'};
1859 =head1 RESELLER FUNCTIONS
1861 Note: Resellers can also use the B<signup_info> and B<new_customer> functions
1862 with their active session, and the B<customer_info> and B<order_pkg> functions
1863 with their active session and an additional I<custnum> parameter.
1865 For the most part, development of the reseller web interface has been
1866 superceded by agent-virtualized access to the backend.
1878 =item agent_list_customers
1880 List agent's customers.
1888 L<freeside-selfservice-clientd>, L<freeside-selfservice-server>