diff options
Diffstat (limited to 'fs_selfservice/drupal')
-rw-r--r-- | fs_selfservice/drupal/admin.inc | 56 | ||||
-rw-r--r-- | fs_selfservice/drupal/freeside.class.php | 33 | ||||
-rw-r--r-- | fs_selfservice/drupal/freeside.info | 3 | ||||
-rw-r--r-- | fs_selfservice/drupal/freeside.module | 32 | ||||
-rw-r--r-- | fs_selfservice/drupal/signup.inc | 354 |
5 files changed, 0 insertions, 478 deletions
diff --git a/fs_selfservice/drupal/admin.inc b/fs_selfservice/drupal/admin.inc deleted file mode 100644 index 1fb7925..0000000 --- a/fs_selfservice/drupal/admin.inc +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -function freeside_admin() { - return drupal_get_form('freeside_admin_form'); -} - -function freeside_admin_form() { - $hostname = variable_get('freeside_hostname',''); - - $form = array( - 'freeside_hostname'=> array( - '#type' => 'textfield', - '#title' => t('Freeside server address'), - '#default_value'=>variable_get('freeside_hostname',''), - '#required'=>1, - ), - ); - - if($hostname) { - $freeside = new FreesideSelfService(); - $signup_info = $freeside->signup_info( - array( - 'keys' => array('agent') - ) - ); // no agent in this request - - $agents = array(); - foreach((array)$signup_info['agent'] as $a) { - $agents[$a['agentnum']] = $a['agent']; - } - - $form['freeside_agentnum'] = array( - '#type' => 'select', - '#title' => t('Signup agent'), - '#default_value'=>variable_get('freeside_agentnum',''), - '#required'=>1, - '#options'=> $agents, - ); - - $form['freeside_debug'] = array( - '#type' => 'checkbox', - '#title' => t('Enable debugging'), - '#default_value'=>variable_get('freeside_debug',0), - ); - - $form['freeside_redirect_after_signup'] = array( - '#type' => 'textfield', - '#title' => t('Success page (URL or Drupal path)'), - '#default_value'=>variable_get('freeside_redirect_after_signup','/'), - ); - } - - return system_settings_form($form); -} - -?> diff --git a/fs_selfservice/drupal/freeside.class.php b/fs_selfservice/drupal/freeside.class.php deleted file mode 100644 index 161156a..0000000 --- a/fs_selfservice/drupal/freeside.class.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -class FreesideSelfService { - - public $URL = ''; - function FreesideSelfService() { - $this->URL = 'http://' . variable_get('freeside_hostname','') . ':8080'; - $this; - } - - public function __call($name, $arguments) { - - error_log("[FreesideSelfService] $name called, sending to ". $this->URL); - - $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", $arguments); - $context = stream_context_create( array( 'http' => array( - 'method' => "POST", - 'header' => "Content-Type: text/xml", - 'content' => $request - ))); - $file = file_get_contents($this->URL, false, $context); - $response = xmlrpc_decode($file); - if (xmlrpc_is_fault($response)) { - trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])"); - } else { - //error_log("[FreesideSelfService] $response"); - return $response; - } - } - -} - -?> diff --git a/fs_selfservice/drupal/freeside.info b/fs_selfservice/drupal/freeside.info deleted file mode 100644 index 957c7b9..0000000 --- a/fs_selfservice/drupal/freeside.info +++ /dev/null @@ -1,3 +0,0 @@ -name = Freeside -description = Freeside self-service -core = 6.x diff --git a/fs_selfservice/drupal/freeside.module b/fs_selfservice/drupal/freeside.module deleted file mode 100644 index a806e3b..0000000 --- a/fs_selfservice/drupal/freeside.module +++ /dev/null @@ -1,32 +0,0 @@ -<?php -// init freeside API -require('freeside.class.php'); - -// menu actions and node paths -function freeside_menu() { - $items = array(); - $items['freeside/signup'] = array( - 'title' => t('New customer'), - 'page callback' => 'freeside_signup', - 'access arguments' => array('access content'), - 'description' => t('New Customer Signup'), - 'file' => 'signup.inc', - ); - $items['admin/settings/freeside'] = array( - 'title' => t('Configure Freeside'), - 'page callback' => 'freeside_admin', - 'access arguments' => array('administer freeside'), - 'description' => t('Configure Freeside self-service'), - 'file' => 'admin.inc', - ); - return $items; -} - -// access control -function freeside_perm() { - return array( - 'administer freeside' - ); -} - -?> diff --git a/fs_selfservice/drupal/signup.inc b/fs_selfservice/drupal/signup.inc deleted file mode 100644 index b3e54f0..0000000 --- a/fs_selfservice/drupal/signup.inc +++ /dev/null @@ -1,354 +0,0 @@ -<?php -function freeside_signup() { - return drupal_get_form('freeside_signup_form'); -} - -function dkpr($var) { - /* "debug kpr": Krumo-print $var if debugging is on */ - static $debug; - if(empty($debug)) $debug = variable_get('freeside_debug',''); - if($debug) { - kpr($var); - } -} - -function signup_info($keys) { - /* local cache, because transporting the entire signup_info - through XML-RPC is incredibly slow. If you change the config, - you can flush the local cache with the "Clear cached data" - button on the Drupal "Performance" menu. */ - $cid = 'FS_signup_info'; - $info = cache_get($cid); - if($info) { - return($info->data); - } - else { - $packet = array( - 'agentnum' => variable_get('freeside_agentnum',''), - 'promo_code' => '', - 'reg_code' => '', - 'keys' => $keys, - ); - - $freeside = new FreesideSelfService(); - $freeside->clear_signup_cache(); - $info = $freeside->signup_info($packet); - cache_set($cid, $info, 'cache', CACHE_TEMPORARY); - return($info); - } -} - -function subextract($array, $key) { - // map { $_->{$key} } (...) - $out = array(); - foreach ($array as $i) { - $out[] = $i[$key]; - } - return $out; -} - -function freeside_signup_form($form_state) { - dkpr($form_state); - - $agentnum = variable_get('freeside_agentnum',''); - if( !$agentnum || !(variable_get('freeside_hostname','')) ) { - drupal_set_message(t('Freeside self-service is not yet configured.'),'error'); - return array(); - } - - $freeside = new FreesideSelfService(); - $keys = array( - // all the signup_info that we need - 'part_referral', - 'refnum', - 'emailinvoiceonly', - 'payby', - 'payby_longname', - 'part_pkg', - 'default_pkgpart', - 'signup_service', - ); - $signup_info = signup_info($keys); - dkpr($signup_info); - - $form = array(); - - $refs = $signup_info['part_referral']; - $form['refnum'] = count($refs) > 1 ? - array( - '#type' => 'select', - '#title' => t('How did you hear about us?'), - '#options'=> array_combine( - subextract($refs, 'refnum'), - subextract($refs, 'referral') - ), - '#default_value'=>$signup_info['refnum'], - ) : array ( - '#type' => 'hidden', - '#value' => $refs[0]['refnum'], - ); - - $form['contact'] = array( - '#type' => 'fieldset', - '#title' => t('Contact Information'), - 'last' => array( - '#prefix' => '<div class="container-inline">', - '#type' => 'textfield', - '#title' => t('Contact name (last, first)'), - '#size' => 20, - '#required' => 1, - ), - 'first' => array( - '#type' => 'textfield', - '#size' => 20, - '#required' => 1, - '#suffix' => '</div>', - ), - 'company' => array( - '#type' => 'textfield', - '#title' => t('Company'), - '#size' => 20, - ), - 'address1'=> array( - '#type' => 'textfield', - '#title' => t('Address'), - '#size' => 30, - '#required'=>1, - ), - 'address2'=> array( - '#type' => 'textfield', - '#size' => 30, - ), - 'city' => array( - '#prefix' => '<div class="container-inline">', - '#type' => 'textfield', - '#title' => t('City'), - '#size' => 15, - '#required'=>1, - ), - 'state' => array( - '#type' => 'textfield', - '#title' => t('State'), - '#size' => 2, - '#required'=>1, - '#default_value'=>$info['statedefault'], - ), - 'zip' => array( - '#type' => 'textfield', - '#title' => t('Zip'), - '#size' => 10, - '#required'=>1, - '#suffix' => '</div>', - ), - 'daytime' => array( - '#type' => 'textfield', - '#title' => t('Daytime Phone'), - '#size' => 18, - ), - 'night' => array( - '#type' => 'textfield', - '#title' => t('Night Phone'), - '#size' => 18, - ), - ); - - $emailinvoiceonly = $signup_info['emailinvoiceonly']; - - $form['billing'] = array( - 'invoicing_list' => array( - '#type' => 'textfield', - '#title' => t('Email invoice to'), - '#size' => '40', - '#required'=>$emailinvoiceonly, - ), - '#type' => 'fieldset', - '#title' => t('Billing Information'), - 'invoicing_list_POST' => array( - '#type' => $emailinvoiceonly ? 'hidden' : 'checkbox', - '#title' => t('Send a paper invoice'), - '#default_value' => 0, - ), - ); - - if( count($signup_info['payby']) > 1 ) { - $form['billing']['payby'] = array( - '#type' => 'select', - '#title' => t('Payment method'), - '#options'=> array_combine( - $signup_info['payby'], - $signup_info['payby_longname'] - ), - ); - } - else { - $form['billing']['payby'] = array( - '#type' => 'hidden', - '#value' => $signup_info['payby'][0], - ); - } - $form['billing']['payby_CARD'] = array( - '#type' => 'fieldset', - 'cardnum' => array( - '#prefix' => '<div class="container-inline">', - '#type' => 'textfield', - '#title' => t('Credit card number'), - '#size' => 20, - '#maxlength'=>20, - '#required'=>1, - '#suffix' => '</div>', - ), - 'expmonth' => array( - '#prefix' => '<div class="container-inline">', - '#type' => 'textfield', - '#title' => t('Expiration date'), - '#size' => 2, - '#required'=>1, - '#maxlength' => 2, - ), - 'expyear' => array( - '#field_prefix' => '/', - '#type' => 'textfield', - '#size' => 2, - '#maxlength' => 2, - '#required'=>1, - '#suffix' => '</div>', - ), - 'paycvv' => array( - '#prefix' => '<div class="container-inline">', - '#type' => 'textfield', - '#title' => 'CVV', - '#size' => 3, - '#maxlength' => 3, - '#required'=>1, - '#suffix' => '</div>', - ), - 'cardname'=> array( - '#prefix' => '<div class="container-inline">', - '#type' => 'textfield', - '#title' => t('Exact name on card'), - '#size' => 40, - '#maxlength'=>60, - '#suffix' => '</div>', - ), - ); - - $pkgs = $signup_info['part_pkg']; - $form['package'] = array( - '#type' => 'fieldset', - '#title' => t('First Package'), - 'pkgpart' => (count($pkgs) > 1 ? - array( - '#type' => 'select', - '#title' => '', - '#options'=> array_combine( - subextract($pkgs, 'pkgpart'), - subextract($pkgs, 'pkg') - ), - '#default_value'=>$signup_info['default_pkgpart'], - ) : array ( - '#type' => 'hidden', - '#value' => $pkgs[0]['pkgpart'], - ) - ), - ); - - switch($signup_info['signup_service']) { - case 'svc_acct': - $form['package'] += array( - 'username'=> array( - '#type' => 'textfield', - '#title' => t('Username'), - '#size' => 20, - '#required'=>1, - ), - 'password'=> array( - '#type' => 'password_confirm', - '#size' => 20, - '#required'=>1, - '#process'=> array('freeside_expand_password_confirm'), - ) - ); - break; - case 'svc_pbx': - break; // nothing yet implemented - } - $form['package']['pkgpart']['#default_value'] = $signup_info['default_pkgpart']; - - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Sign me up!', - ); - return $form; -} - -/* workaround for silly Drupal behavior */ -function freeside_expand_password_confirm($element) { - $element = expand_password_confirm($element); - $element['pass1']['#attributes']['value'] = $element['#value']['pass1']; - $element['pass2']['#attributes']['value'] = $element['#value']['pass2']; - return $element; -} - -function freeside_signup_form_submit($form, &$form_state) { - $freeside = new FreesideSelfService(); - $values = $form_state['values']; - dkpr($values); - - $customer = array(); - $customer['agentnum'] = variable_get('freeside_agentnum',''); - foreach( array( 'first', - 'last', - 'address1', - 'address2', - 'city', - 'state', - 'zip', - 'daytime', - 'night', - 'fax', - 'payby', - 'refnum', - 'invoicing_list', - 'pkgpart', - 'username' - ) - as $field ) { - $customer[$field] = $values[$field]; - } - if($values['invoicing_list_POST']) { - $customer['invoicing_list'] = - implode(',', array($customer['invoicing_list'], 'POST')); - } - $customer['_password'] = $values['password']; - $customer['country'] = 'US'; - if($customer['payby'] == 'CARD') { - $customer['payinfo'] = preg_replace('/\D/','',$values['cardnum']); - $customer['paydate'] = $values['expmonth'] . '/' . $values['expyear']; - $customer['payname'] = isset($values['cardname']) ? - $values['cardname'] : - ($values['first'] . ' ' . $values['last']); - $customer['paycvv'] = $values['paycvv']; - } - /* other paybys not implemented */ - - dkpr($customer); - $response = $freeside->new_customer($customer); - dkpr($response); - error_log("[new_customer] received response from Freeside: $response"); - $error = $response['error']; - - if ( $error ) { - drupal_set_message(t("Signup error: $error"), 'error'); - $form_state['redirect'] = FALSE; - } - else { - drupal_set_message(t("Signup successful!"),'status'); - $form_state['redirect'] = array( - variable_get('freeside_redirect_after_signup','/'), - //query string would go here - //'custnum='.$response['custnum'].'&svcnum='.$response['svcnum'], - ); - } -} - -?> |