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 'customer_info' => 'MyAccount/customer_info',
32 'edit_info' => 'MyAccount/edit_info', #add to ss cgi!
33 'invoice' => 'MyAccount/invoice',
34 'invoice_logo' => 'MyAccount/invoice_logo',
35 'list_invoices' => 'MyAccount/list_invoices', #?
36 'cancel' => 'MyAccount/cancel', #add to ss cgi!
37 'payment_info' => 'MyAccount/payment_info',
38 'payment_info_renew_info' => 'MyAccount/payment_info_renew_info',
39 'process_payment' => 'MyAccount/process_payment',
40 'process_payment_order_pkg' => 'MyAccount/process_payment_order_pkg',
41 'process_payment_change_pkg' => 'MyAccount/process_payment_change_pkg',
42 'process_payment_order_renew' => 'MyAccount/process_payment_order_renew',
43 'process_prepay' => 'MyAccount/process_prepay',
44 'realtime_collect' => 'MyAccount/realtime_collect',
45 'list_pkgs' => 'MyAccount/list_pkgs', #add to ss (added?)
46 'list_svcs' => 'MyAccount/list_svcs', #add to ss (added?)
47 'list_svc_usage' => 'MyAccount/list_svc_usage',
48 'list_cdr_usage' => 'MyAccount/list_cdr_usage',
49 'list_support_usage' => 'MyAccount/list_support_usage',
50 'order_pkg' => 'MyAccount/order_pkg', #add to ss cgi!
51 'change_pkg' => 'MyAccount/change_pkg',
52 'order_recharge' => 'MyAccount/order_recharge',
53 'renew_info' => 'MyAccount/renew_info',
54 'order_renew' => 'MyAccount/order_renew',
55 'cancel_pkg' => 'MyAccount/cancel_pkg', #add to ss cgi!
56 'charge' => 'MyAccount/charge', #?
57 'part_svc_info' => 'MyAccount/part_svc_info',
58 'provision_acct' => 'MyAccount/provision_acct',
59 'provision_external' => 'MyAccount/provision_external',
60 'unprovision_svc' => 'MyAccount/unprovision_svc',
61 'myaccount_passwd' => 'MyAccount/myaccount_passwd',
62 'create_ticket' => 'MyAccount/create_ticket',
63 'signup_info' => 'Signup/signup_info',
64 'skin_info' => 'MyAccount/skin_info',
65 'access_info' => 'MyAccount/access_info',
66 'domain_select_hash' => 'Signup/domain_select_hash', # expose?
67 'new_customer' => 'Signup/new_customer',
68 'capture_payment' => 'Signup/capture_payment',
69 'agent_login' => 'Agent/agent_login',
70 'agent_logout' => 'Agent/agent_logout',
71 'agent_info' => 'Agent/agent_info',
72 'agent_list_customers' => 'Agent/agent_list_customers',
73 'mason_comp' => 'MasonComponent/mason_comp',
74 'call_time' => 'PrepaidPhone/call_time',
75 'call_time_nanpa' => 'PrepaidPhone/call_time_nanpa',
76 'phonenum_balance' => 'PrepaidPhone/phonenum_balance',
77 'bulk_processrow' => 'Bulk/processrow',
78 'check_username' => 'Bulk/check_username',
80 'ping' => 'SGNG/ping',
81 'decompify_pkgs' => 'SGNG/decompify_pkgs',
82 'previous_payment_info' => 'SGNG/previous_payment_info',
83 'previous_payment_info_renew_info'
84 => 'SGNG/previous_payment_info_renew_info',
85 'previous_process_payment' => 'SGNG/previous_process_payment',
86 'previous_process_payment_order_pkg'
87 => 'SGNG/previous_process_payment_order_pkg',
88 'previous_process_payment_change_pkg'
89 => 'SGNG/previous_process_payment_change_pkg',
90 'previous_process_payment_order_renew'
91 => 'SGNG/previous_process_payment_order_renew',
95 qw( regionselector regionselector_hashref location_form
96 expselect popselector domainselector didselector
100 $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
101 $ENV{'SHELL'} = '/bin/sh';
102 $ENV{'IFS'} = " \t\n";
105 $ENV{'BASH_ENV'} = '';
107 #you can add BEGIN { $FS::SelfService::skip_uid_check = 1; }
108 #if you grant appropriate permissions to whatever user
109 my $freeside_uid = scalar(getpwnam('freeside'));
110 die "not running as the freeside user\n"
111 if $> != $freeside_uid && ! $skip_uid_check;
113 -e $dir or die "FATAL: $dir doesn't exist!";
114 -d $dir or die "FATAL: $dir isn't a directory!";
115 -r $dir or die "FATAL: Can't read $dir as freeside user!";
116 -x $dir or die "FATAL: $dir not searchable (executable) as freeside user!";
118 foreach my $autoload ( keys %autoload ) {
121 "sub $autoload { ". '
126 #warn scalar(@_). ": ". join(" / ", @_);
130 $param->{_packet} = \''. $autoload{$autoload}. '\';
132 simple_packet($param);
142 warn "sending ". $packet->{_packet}. " to server"
144 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
145 connect(SOCK, sockaddr_un($socket)) or die "connect to $socket: $!";
146 nstore_fd($packet, \*SOCK) or die "can't send packet: $!";
149 #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
151 #block until there is a message on socket
152 # my $w = new IO::Select;
154 # my @wait = $w->can_read;
156 warn "reading message from server"
159 my $return = fd_retrieve(\*SOCK) or die "error reading result: $!";
160 die $return->{'_error'} if defined $return->{_error} && $return->{_error};
162 warn "returning message to client"
170 FS::SelfService - Freeside self-service API
174 # password and shell account changes
175 use FS::SelfService qw(passwd chfn chsh);
177 # "my account" functionality
178 use FS::SelfService qw( login customer_info invoice cancel payment_info process_payment );
180 my $rv = login( { 'username' => $username,
182 'password' => $password,
186 if ( $rv->{'error'} ) {
187 #handle login error...
190 my $session_id = $rv->{'session_id'};
193 my $customer_info = customer_info( { 'session_id' => $session_id } );
195 #payment_info and process_payment are available in 1.5+ only
196 my $payment_info = payment_info( { 'session_id' => $session_id } );
198 #!!! process_payment example
200 #!!! list_pkgs example
202 #!!! order_pkg example
204 #!!! cancel_pkg example
206 # signup functionality
207 use FS::SelfService qw( signup_info new_customer );
209 my $signup_info = signup_info;
211 $rv = new_customer( {
214 'company' => $company,
215 'address1' => $address1,
216 'address2' => $address2,
220 'country' => $country,
221 'daytime' => $daytime,
225 'payinfo' => $payinfo,
227 'paystart_month' => $paystart_month
228 'paystart_year' => $paystart_year,
229 'payissue' => $payissue,
231 'paydate' => $paydate,
232 'payname' => $payname,
233 'invoicing_list' => $invoicing_list,
234 'referral_custnum' => $referral_custnum,
235 'agentnum' => $agentnum,
236 'pkgpart' => $pkgpart,
238 'username' => $username,
239 '_password' => $password,
243 'phonenum' => $phonenum,
248 my $error = $rv->{'error'};
249 if ( $error eq '_decline' ) {
259 Use this API to implement your own client "self-service" module.
261 If you just want to customize the look of the existing "self-service" module,
264 =head1 PASSWORD, GECOS, SHELL CHANGING FUNCTIONS
276 =head1 "MY ACCOUNT" FUNCTIONS
282 Creates a user session. Takes a hash reference as parameter with the
301 Returns a hash reference with the following keys:
307 Empty on success, or an error message on errors.
311 Session identifier for successful logins
315 =item customer_info HASHREF
317 Returns general customer information.
319 Takes a hash reference as parameter with a single key: B<session_id>
321 Returns a hash reference with the following keys:
335 Array reference of hash references of open inoices. Each hash reference has
336 the following keys: invnum, date, owed
340 An HTML fragment containing shipping and billing addresses.
342 =item The following fields are also returned
344 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
348 =item edit_info HASHREF
350 Takes a hash reference as parameter with any of the following keys:
352 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
354 If a field exists, the customer record is updated with the new value of that
355 field. If a field does not exist, that field is not changed on the customer
358 Returns a hash reference with a single key, B<error>, empty on success, or an
359 error message on errors
361 =item invoice HASHREF
363 Returns an invoice. Takes a hash reference as parameter with two keys:
364 session_id and invnum
366 Returns a hash reference with the following keys:
372 Empty on success, or an error message on errors
384 =item list_invoices HASHREF
386 Returns a list of all customer invoices. Takes a hash references with a single
389 Returns a hash reference with the following keys:
395 Empty on success, or an error message on errors
399 Reference to array of hash references with the following keys:
409 Invoice date, in UNIX epoch time
417 Cancels this customer.
419 Takes a hash reference as parameter with a single key: B<session_id>
421 Returns a hash reference with a single key, B<error>, which is empty on
422 success or an error message on errors.
424 =item payment_info HASHREF
426 Returns information that may be useful in displaying a payment page.
428 Takes a hash reference as parameter with a single key: B<session_id>.
430 Returns a hash reference with the following keys:
436 Empty on success, or an error message on errors
444 Exact name on credit card (CARD/DCRD)
468 Customer's current default payment type.
472 For CARD/DCRD payment types, the card type (Visa card, MasterCard, Discover card, American Express card, etc.)
476 For CARD/DCRD payment types, the card number
480 For CARD/DCRD payment types, expiration month
484 For CARD/DCRD payment types, expiration year
486 =item cust_main_county
488 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.
492 Array reference of all states in the current default country.
496 Hash reference of card types; keys are card types, values are the exact strings
497 passed to the process_payment function
501 #this doesn't actually work yet
505 #Unique transaction identifier (prevents multiple charges), passed to the
506 #process_payment function
510 =item process_payment HASHREF
512 Processes a payment and possible change of address or payment type. Takes a
513 hash reference as parameter with the following keys:
527 If true, address and card information entered will be saved for subsequent
532 If true, future credit card payments will be done automatically (sets payby to
533 CARD). If false, future credit card payments will be done on-demand (sets
534 payby to DCRD). This option only has meaning if B<save> is set true.
562 Two-letter country code
570 Card expiration month
578 #this doesn't actually work yet
582 #Unique transaction identifier, returned from the payment_info function.
583 #Prevents multiple charges.
587 Returns a hash reference with a single key, B<error>, empty on success, or an
588 error message on errors.
590 =item process_payment_order_pkg
592 Combines the B<process_payment> and B<order_pkg> functions in one step. If the
593 payment processes sucessfully, the package is ordered. Takes a hash reference
594 as parameter with the keys of both methods.
596 Returns a hash reference with a single key, B<error>, empty on success, or an
597 error message on errors.
599 =item process_payment_change_pkg
601 Combines the B<process_payment> and B<change_pkg> functions in one step. If the
602 payment processes sucessfully, the package is ordered. Takes a hash reference
603 as parameter with the keys of both methods.
605 Returns a hash reference with a single key, B<error>, empty on success, or an
606 error message on errors.
609 =item process_payment_order_renew
611 Combines the B<process_payment> and B<order_renew> functions in one step. If
612 the payment processes sucessfully, the renewal is processed. Takes a hash
613 reference as parameter with the keys of both methods.
615 Returns a hash reference with a single key, B<error>, empty on success, or an
616 error message on errors.
620 Returns package information for this customer. For more detail on services,
623 Takes a hash reference as parameter with a single key: B<session_id>
625 Returns a hash reference containing customer package information. The hash reference contains the following keys:
635 Empty on success, or an error message on errors.
637 =item cust_pkg HASHREF
639 Array reference of hash references, each of which has the fields of a cust_pkg
640 record (see L<FS::cust_pkg>) as well as the fields below. Note these are not
641 the internal FS:: objects, but hash references of columns and values.
645 =item part_pkg fields
647 All fields of part_pkg for this specific cust_pkg (be careful with this
648 information - it may reveal more about your available packages than you would
649 like users to know in aggregate)
653 #XXX pare part_pkg fields down to a more secure subset
657 An array of hash references indicating information on unprovisioned services
658 available for provisioning for this specific cust_pkg. Each has the following
663 =item part_svc fields
665 All fields of part_svc (be careful with this information - it may reveal more
666 about your available packages than you would like users to know in aggregate)
670 #XXX pare part_svc fields down to a more secure subset
676 An array of hash references indicating information on the customer services
677 already provisioned for this specific cust_pkg. Each has the following keys:
683 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.
689 Primary key for this service
693 Service definition (see L<FS::part_svc>)
697 Customer package (see L<FS::cust_pkg>)
701 Blank if the service is not over limit, or the date the service exceeded its usage limit (as a UNIX timestamp).
709 Returns service information for this customer.
711 Takes a hash reference as parameter with a single key: B<session_id>
713 Returns a hash reference containing customer package information. The hash reference contains the following keys:
723 An array of hash references indicating information on all of this customer's
724 services. Each has the following keys:
730 Primary key for this service
738 Meaningful user-specific identifier for the service (i.e. username, domain, or
743 Account (svc_acct) services also have the following keys:
761 Upload bytes remaining
765 Download bytes remaining
769 Total bytes remaining
771 =item recharge_amount
775 =item recharge_seconds
777 Number of seconds gained by recharge
779 =item recharge_upbytes
781 Number of upload bytes gained by recharge
783 =item recharge_downbytes
785 Number of download bytes gained by recharge
787 =item recharge_totalbytes
789 Number of total bytes gained by recharge
797 Orders a package for this customer.
799 Takes a hash reference as parameter with the following keys:
809 Package to order (see L<FS::part_pkg>).
813 Service to order (see L<FS::part_svc>).
815 Normally optional; required only to provision a non-svc_acct service, or if the
816 package definition does not contain one svc_acct service definition with
817 quantity 1 (it may contain others with quantity >1). A svcpart of "none" can
818 also be specified to indicate that no initial service should be provisioned.
822 Fields used when provisioning an svc_acct service:
836 Optional security phrase
840 Optional Access number number
844 Fields used when provisioning an svc_domain service:
854 Fields used when provisioning an svc_phone service:
872 Fields used when provisioning an svc_external service:
886 Returns a hash reference with a single key, B<error>, empty on success, or an
887 error message on errors. The special error '_decline' is returned for
888 declined transactions.
892 Changes a package for this customer.
894 Takes a hash reference as parameter with the following keys:
904 Existing customer package.
908 New package to order (see L<FS::part_pkg>).
912 Returns a hash reference with a single key, B<error>, empty on success, or an
913 error message on errors.
917 Provides useful info for early renewals.
919 Takes a hash reference as parameter with the following keys:
929 Returns a hash reference. On errors, it contains a single key, B<error>, with
930 the error message. Otherwise, contains a single key, B<dates>, pointing to
931 an array refernce of hash references. Each hash reference contains the
938 (Future) Bill date. Indicates a future date for which billing could be run.
939 Specified as a integer UNIX timestamp. Pass this value to the B<order_renew>
942 =item bill_date_pretty
944 (Future) Bill date as a human-readable string. (Convenience for display;
945 subject to change, so best not to parse for the date.)
949 Base amount which will be charged if renewed early as of this date.
953 Renewal date; i.e. even-futher future date at which the customer will be paid
954 through if the early renewal is completed with the given B<bill-date>.
955 Specified as a integer UNIX timestamp.
957 =item renew_date_pretty
959 Renewal date as a human-readable string. (Convenience for display;
960 subject to change, so best not to parse for the date.)
964 Package that will be renewed.
968 Expiration date of the package that will be renewed.
970 =item expire_date_pretty
972 Expiration date of the package that will be renewed, as a human-readable
973 string. (Convenience for display; subject to change, so best not to parse for
980 Renews this customer early; i.e. runs billing for this customer in advance.
982 Takes a hash reference as parameter with the following keys:
992 Integer date as returned by the B<renew_info> function, indicating the advance
993 date for which to run billing.
997 Returns a hash reference with a single key, B<error>, empty on success, or an
998 error message on errors.
1002 Cancels a package for this customer.
1004 Takes a hash reference as parameter with the following keys:
1014 pkgpart of package to cancel
1018 Returns a hash reference with a single key, B<error>, empty on success, or an
1019 error message on errors.
1023 =head1 SIGNUP FUNCTIONS
1027 =item signup_info HASHREF
1029 Takes a hash reference as parameter with the following keys:
1033 =item session_id - Optional agent/reseller interface session
1037 Returns a hash reference containing information that may be useful in
1038 displaying a signup page. The hash reference contains the following keys:
1042 =item cust_main_county
1044 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.
1048 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
1049 an agentnum specified explicitly via reseller interface session_id in the
1054 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.
1056 =item agentnum2part_pkg
1058 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.
1062 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.
1064 =item security_phrase
1066 True if the "security_phrase" feature is enabled
1070 Array reference of acceptable payment types for signup
1076 credit card - automatic
1080 credit card - on-demand - version 1.5+ only
1084 electronic check - automatic
1088 electronic check - on-demand - version 1.5+ only
1096 billing, not recommended for signups
1100 free, definitely not recommended for signups
1104 special billing type: applies a credit (see FS::prepay_credit) and sets billing type to BILL
1110 True if CVV features are available (1.5+ or 1.4.2 with CVV schema patch)
1114 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".
1120 =item countrydefault
1126 =item new_customer HASHREF
1128 Creates a new customer. Takes a hash reference as parameter with the
1135 first name (required)
1139 last name (required)
1143 (not typically collected; mostly used for ACH transactions)
1149 =item address1 (required)
1157 =item city (required)
1165 =item state (required)
1169 =item zip (required)
1175 Daytime phone number
1179 Evening phone number
1187 CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY (see L</signup_info> (required)
1191 Card number for CARD/DCRD, account_number@aba_number for CHEK/DCHK, prepaid "pin" for PREPAY, purchase order number for BILL
1195 Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
1199 Expiration date for CARD/DCRD
1203 Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
1205 =item invoicing_list
1207 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),
1209 =item referral_custnum
1211 referring customer number
1219 pkgpart of initial package
1235 Access number (index, not the literal number)
1239 Country code (to be provisioned as a service)
1243 Phone number (to be provisioned as a service)
1251 Returns a hash reference with the following keys:
1257 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)
1261 =item regionselector HASHREF | LIST
1263 Takes as input a hashref or list of key/value pairs with the following keys:
1267 =item selected_county
1269 Currently selected county
1271 =item selected_state
1273 Currently selected state
1275 =item selected_country
1277 Currently selected country
1281 Specify a unique prefix string if you intend to use the HTML output multiple time son one page.
1285 Specify a javascript subroutine to call on changes
1291 =item default_country
1297 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>.
1301 Returns a list consisting of three HTML fragments for county selection,
1302 state selection and country selection, respectively.
1306 #false laziness w/FS::cust_main_county (this is currently the "newest" version)
1307 sub regionselector {
1314 $param->{'selected_country'} ||= $param->{'default_country'};
1315 $param->{'selected_state'} ||= $param->{'default_state'};
1317 my $prefix = exists($param->{'prefix'}) ? $param->{'prefix'} : '';
1321 my %cust_main_county;
1323 # unless ( @cust_main_county ) { #cache
1324 #@cust_main_county = qsearch('cust_main_county', {} );
1325 #foreach my $c ( @cust_main_county ) {
1326 foreach my $c ( @{ $param->{'locales'} } ) {
1327 #$countyflag=1 if $c->county;
1328 $countyflag=1 if $c->{county};
1329 #push @{$cust_main_county{$c->country}{$c->state}}, $c->county;
1330 #$cust_main_county{$c->country}{$c->state}{$c->county} = 1;
1331 $cust_main_county{$c->{country}}{$c->{state}}{$c->{county}} = 1;
1334 $countyflag=1 if $param->{selected_county};
1336 my $script_html = <<END;
1338 function opt(what,value,text) {
1339 var optionName = new Option(text, value, false, false);
1340 var length = what.length;
1341 what.options[length] = optionName;
1343 function ${prefix}country_changed(what) {
1344 country = what.options[what.selectedIndex].text;
1345 for ( var i = what.form.${prefix}state.length; i >= 0; i-- )
1346 what.form.${prefix}state.options[i] = null;
1348 #what.form.${prefix}state.options[0] = new Option('', '', false, true);
1350 foreach my $country ( sort keys %cust_main_county ) {
1351 $script_html .= "\nif ( country == \"$country\" ) {\n";
1352 foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
1353 my $text = $state || '(n/a)';
1354 $script_html .= qq!opt(what.form.${prefix}state, "$state", "$text");\n!;
1356 $script_html .= "}\n";
1359 $script_html .= <<END;
1361 function ${prefix}state_changed(what) {
1364 if ( $countyflag ) {
1365 $script_html .= <<END;
1366 state = what.options[what.selectedIndex].text;
1367 country = what.form.${prefix}country.options[what.form.${prefix}country.selectedIndex].text;
1368 for ( var i = what.form.${prefix}county.length; i >= 0; i-- )
1369 what.form.${prefix}county.options[i] = null;
1372 foreach my $country ( sort keys %cust_main_county ) {
1373 $script_html .= "\nif ( country == \"$country\" ) {\n";
1374 foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
1375 $script_html .= "\nif ( state == \"$state\" ) {\n";
1376 #foreach my $county ( sort @{$cust_main_county{$country}{$state}} ) {
1377 foreach my $county ( sort keys %{$cust_main_county{$country}{$state}} ) {
1378 my $text = $county || '(n/a)';
1380 qq!opt(what.form.${prefix}county, "$county", "$text");\n!;
1382 $script_html .= "}\n";
1384 $script_html .= "}\n";
1388 $script_html .= <<END;
1393 my $county_html = $script_html;
1394 if ( $countyflag ) {
1395 $county_html .= qq!<SELECT NAME="${prefix}county" onChange="$param->{'onchange'}">!;
1396 $county_html .= '</SELECT>';
1399 qq!<INPUT TYPE="hidden" NAME="${prefix}county" VALUE="$param->{'selected_county'}">!;
1402 my $state_html = qq!<SELECT NAME="${prefix}state" !.
1403 qq!onChange="${prefix}state_changed(this); $param->{'onchange'}">!;
1404 foreach my $state ( sort keys %{ $cust_main_county{$param->{'selected_country'}} } ) {
1405 my $text = $state || '(n/a)';
1406 my $selected = $state eq $param->{'selected_state'} ? 'SELECTED' : '';
1407 $state_html .= "\n<OPTION $selected VALUE=$state>$text</OPTION>"
1409 $state_html .= '</SELECT>';
1411 my $country_html = '';
1412 if ( scalar( keys %cust_main_county ) > 1 ) {
1414 $country_html = qq(<SELECT NAME="${prefix}country" ).
1415 qq(onChange="${prefix}country_changed(this); ).
1416 $param->{'onchange'}.
1419 my $countrydefault = $param->{default_country} || 'US';
1420 foreach my $country (
1421 sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b }
1422 keys %cust_main_county
1424 my $selected = $country eq $param->{'selected_country'}
1427 $country_html .= "\n<OPTION$selected>$country</OPTION>"
1429 $country_html .= '</SELECT>';
1432 $country_html = qq(<INPUT TYPE="hidden" NAME="${prefix}country" ).
1433 ' VALUE="'. (keys %cust_main_county )[0]. '">';
1437 ($county_html, $state_html, $country_html);
1441 sub regionselector_hashref {
1442 my ($county_html, $state_html, $country_html) = regionselector(@_);
1444 'county_html' => $county_html,
1445 'state_html' => $state_html,
1446 'country_html' => $country_html,
1450 =item location_form HASHREF | LIST
1452 Takes as input a hashref or list of key/value pairs with the following keys:
1458 Current customer session_id
1462 Omit red asterisks from required fields.
1464 =item address1_label
1466 Label for first address line.
1470 Returns an HTML fragment for a location form (address, city, state, zip,
1483 my $session_id = delete $param->{'session_id'};
1485 my $rv = mason_comp( 'session_id' => $session_id,
1486 'comp' => '/elements/location.html',
1487 'args' => [ %$param ],
1491 $rv->{'error'} || $rv->{'output'};
1496 #=item expselect HASHREF | LIST
1498 #Takes as input a hashref or list of key/value pairs with the following keys:
1502 #=item prefix - Specify a unique prefix string if you intend to use the HTML output multiple time son one page.
1504 #=item date - current date, in yyyy-mm-dd or m-d-yyyy format
1508 =item expselect PREFIX [ DATE ]
1510 Takes as input a unique prefix string and the current expiration date, in
1511 yyyy-mm-dd or m-d-yyyy format
1513 Returns an HTML fragments for expiration date selection.
1519 #if ( ref($_[0]) ) {
1523 #my $prefix = $param->{'prefix'};
1524 #my $prefix = exists($param->{'prefix'}) ? $param->{'prefix'} : '';
1525 #my $date = exists($param->{'date'}) ? $param->{'date'} : '';
1527 my $date = scalar(@_) ? shift : '';
1529 my( $m, $y ) = ( 0, 0 );
1530 if ( $date =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
1531 ( $m, $y ) = ( $2, $1 );
1532 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
1533 ( $m, $y ) = ( $1, $3 );
1535 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
1537 $return .= qq!<OPTION VALUE="$_"!;
1538 $return .= " SELECTED" if $_ == $m;
1541 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
1543 my $thisYear = $t[5] + 1900;
1544 for ( ($thisYear > $y && $y > 0 ? $y : $thisYear) .. ($thisYear+10) ) {
1545 $return .= qq!<OPTION VALUE="$_"!;
1546 $return .= " SELECTED" if $_ == $y;
1549 $return .= "</SELECT>";
1554 =item popselector HASHREF | LIST
1556 Takes as input a hashref or list of key/value pairs with the following keys:
1562 Access number number
1566 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>.
1570 Returns an HTML fragment for access number selection.
1574 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
1582 my $popnum = $param->{'popnum'};
1583 my $pops = $param->{'pops'};
1585 return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
1586 return $pops->[0]{city}. ', '. $pops->[0]{state}.
1587 ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}. '-'. $pops->[0]{loc}.
1588 '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
1589 if scalar(@$pops) == 1;
1592 my %popnum2pop = ();
1594 push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
1595 $popnum2pop{$_->{popnum}} = $_;
1600 function opt(what,href,text) {
1601 var optionName = new Option(text, href, false, false)
1602 var length = what.length;
1603 what.options[length] = optionName;
1607 my $init_popstate = $param->{'init_popstate'};
1608 if ( $init_popstate ) {
1609 $text .= '<INPUT TYPE="hidden" NAME="init_popstate" VALUE="'.
1610 $init_popstate. '">';
1613 function acstate_changed(what) {
1614 state = what.options[what.selectedIndex].text;
1615 what.form.popac.options.length = 0
1616 what.form.popac.options[0] = new Option("Area code", "-1", false, true);
1620 my @states = $init_popstate ? ( $init_popstate ) : keys %pop;
1621 foreach my $state ( sort { $a cmp $b } @states ) {
1622 $text .= "\nif ( state == \"$state\" ) {\n" unless $init_popstate;
1624 foreach my $ac ( sort { $a cmp $b } keys %{ $pop{$state} }) {
1625 $text .= "opt(what.form.popac, \"$ac\", \"$ac\");\n";
1626 if ($ac eq $param->{'popac'}) {
1627 $text .= "what.form.popac.options[what.form.popac.length-1].selected = true;\n";
1630 $text .= "}\n" unless $init_popstate;
1632 $text .= "popac_changed(what.form.popac)}\n";
1635 function popac_changed(what) {
1636 ac = what.options[what.selectedIndex].text;
1637 what.form.popnum.options.length = 0;
1638 what.form.popnum.options[0] = new Option("City", "-1", false, true);
1642 foreach my $state ( @states ) {
1643 foreach my $popac ( keys %{ $pop{$state} } ) {
1644 $text .= "\nif ( ac == \"$popac\" ) {\n";
1646 foreach my $pop ( @{$pop{$state}->{$popac}}) {
1647 my $o_popnum = $pop->{popnum};
1648 my $poptext = $pop->{city}. ', '. $pop->{state}.
1649 ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
1651 $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n";
1652 if ($popnum == $o_popnum) {
1653 $text .= "what.form.popnum.options[what.form.popnum.length-1].selected = true;\n";
1661 $text .= "}\n</SCRIPT>\n";
1663 $param->{'acstate'} = '' unless defined($param->{'acstate'});
1666 qq!<TABLE CELLPADDING="0"><TR><TD><SELECT NAME="acstate"! .
1667 qq!SIZE=1 onChange="acstate_changed(this)"><OPTION VALUE=-1>State!;
1668 $text .= "<OPTION" . ($_ eq $param->{'acstate'} ? " SELECTED" : "") .
1669 ">$_" foreach sort { $a cmp $b } @states;
1670 $text .= '</SELECT>'; #callback? return 3 html pieces? #'</TD>';
1673 qq!<SELECT NAME="popac" SIZE=1 onChange="popac_changed(this)">!.
1674 qq!<OPTION>Area code</SELECT></TR><TR VALIGN="top">!;
1676 $text .= qq!<TR><TD><SELECT NAME="popnum" SIZE=1 STYLE="width: 20em"><OPTION>City!;
1679 #comment this block to disable initial list polulation
1680 my @initial_select = ();
1681 if ( scalar( @$pops ) > 100 ) {
1682 push @initial_select, $popnum2pop{$popnum} if $popnum2pop{$popnum};
1684 @initial_select = @$pops;
1686 foreach my $pop ( sort { $a->{state} cmp $b->{state} } @initial_select ) {
1687 $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
1688 ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
1689 $pop->{city}. ', '. $pop->{state}.
1690 ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
1693 $text .= qq!</SELECT></TD></TR></TABLE>!;
1699 =item domainselector HASHREF | LIST
1701 Takes as input a hashref or list of key/value pairs with the following keys:
1711 Service number of the selected item.
1715 Returns an HTML fragment for domain selection.
1719 sub domainselector {
1726 my $domsvc= $param->{'domsvc'};
1728 domain_select_hash(map {$_ => $param->{$_}} qw(pkgnum svcpart pkgpart) );
1729 my $domains = $rv->{'domains'};
1730 $domsvc = $rv->{'domsvc'} unless $domsvc;
1732 return '<INPUT TYPE="hidden" NAME="domsvc" VALUE="">'
1733 unless scalar(keys %$domains);
1735 if (scalar(keys %$domains) == 1) {
1737 foreach(keys %$domains) {
1740 return '<TR><TD ALIGN="right">Domain</TD><TD>'. $domains->{$key}.
1741 '<INPUT TYPE="hidden" NAME="domsvc" VALUE="'. $key. '"></TD></TR>'
1744 my $text .= qq!<TR><TD ALIGN="right">Domain</TD><TD><SELECT NAME="domsvc" SIZE=1 STYLE="width: 20em"><OPTION>(Choose Domain)!;
1747 foreach my $domain ( sort { $domains->{$a} cmp $domains->{$b} } keys %$domains ) {
1748 $text .= qq!<OPTION VALUE="!. $domain. '"'.
1749 ( ( $domsvc && $domain == $domsvc ) ? ' SELECTED' : '' ). ">".
1750 $domains->{$domain};
1753 $text .= qq!</SELECT></TD></TR>!;
1759 =item didselector HASHREF | LIST
1761 Takes as input a hashref or list of key/value pairs with the following keys:
1767 Field name for the returned HTML fragment.
1771 Service definition (see L<FS::part_svc>)
1775 Returns an HTML fragment for DID selection.
1787 my $rv = mason_comp( 'comp'=>'/elements/select-did.html',
1788 'args'=>[ %$param ],
1792 $rv->{'error'} || $rv->{'output'};
1798 =head1 RESELLER FUNCTIONS
1800 Note: Resellers can also use the B<signup_info> and B<new_customer> functions
1801 with their active session, and the B<customer_info> and B<order_pkg> functions
1802 with their active session and an additional I<custnum> parameter.
1804 For the most part, development of the reseller web interface has been
1805 superceded by agent-virtualized access to the backend.
1817 =item agent_list_customers
1819 List agent's customers.
1827 L<freeside-selfservice-clientd>, L<freeside-selfservice-server>