You are here

function uc_recurring_admin_edit_form in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 uc_recurring.admin.inc \uc_recurring_admin_edit_form()
  2. 6 uc_recurring.admin.inc \uc_recurring_admin_edit_form()

Let an admin edit a recurring fee.

2 string references to 'uc_recurring_admin_edit_form'
hook_recurring_info in ./uc_recurring.api.php
Define the recurring payment method/gateway function callbacks.
uc_recurring_recurring_info in ./uc_recurring.module
Implements hook_recurring_info().

File

./uc_recurring.admin.inc, line 171
Recurring payments administration page callbacks and form builder functions.

Code

function uc_recurring_admin_edit_form($form, $form_state, $rfid, $fee_handler) {
  $fee = uc_recurring_fee_user_load($rfid);
  if ($fee->fee_handler == $fee_handler) {
    drupal_add_css(drupal_get_path('module', 'uc_recurring') . '/uc_recurring.css');
    drupal_add_js(drupal_get_path('module', 'uc_recurring') . '/uc_recurring.js');
    $form['rfid'] = array(
      '#type' => 'hidden',
      '#value' => $rfid,
    );
    $form['fee_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Recurring order title'),
      '#description' => t('This is the text that appears on the order as the name of the product.'),
      '#default_value' => $fee->fee_title,
      '#size' => 60,
    );
    $form['fee_status'] = array(
      '#type' => 'select',
      '#title' => t('Recurring fee status'),
      '#default_value' => $fee->status,
      '#options' => uc_recurring_fee_status_label(),
    );
    $form['fee_amount'] = array(
      '#type' => 'textfield',
      '#title' => t('Recurring fee amount'),
      '#description' => t('Charge this amount each billing period.'),
      '#default_value' => $fee->fee_amount,
      '#size' => 16,
      '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
      '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
    );
    $form['num_interval'] = array(
      '#type' => 'fieldset',
      '#title' => t('Number of billing periods'),
      '#collapsible' => FALSE,
      '#description' => t('Specify how many more recurring fees will be charged.'),
    );
    $unlimited_intervals_attributes = array();
    $number_intervals_attributes = array();
    if ($fee->remaining_intervals < 0 && !isset($form_state['values']['unlimited_intervals']) || isset($form_state['values']) && isset($form_state['values']['unlimited_intervals']) && $form_state['values']['unlimited_intervals'] == 1) {
      $unlimited_intervals_attributes['checked'] = 'checked';
      $number_intervals_default_value = 1;
      $number_intervals_attributes = array(
        'disabled' => 'disabled',
      );
    }
    else {
      $number_intervals_default_value = $fee->remaining_intervals > 0 ? $fee->remaining_intervals : 1;
    }
    $form['num_interval']['unlimited_intervals'] = array(
      '#type' => 'checkbox',
      '#title' => t('Unlimited rebillings.'),
      '#attributes' => $unlimited_intervals_attributes,
      '#ajax' => array(
        'callback' => 'rebilling_num_intervals_callback',
        'wrapper' => 'rebilling_num_intervals_replace',
      ),
    );
    $form['num_interval']['number_intervals'] = array(
      '#type' => 'textfield',
      '#title' => t('Remaining billing periods'),
      '#size' => 16,
      '#prefix' => '<div id="rebilling_num_intervals_replace">',
      '#suffix' => '</div>',
      '#default_value' => $number_intervals_default_value,
      '#attributes' => $number_intervals_attributes,
    );
    $form['next_charge'] = array(
      '#type' => 'fieldset',
      '#title' => t('Next charge'),
      '#collapsible' => FALSE,
      '#description' => t('Specify when the next charge should occur.'),
      '#attributes' => array(
        'class' => array(
          'interval-fieldset',
        ),
      ),
    );
    if (module_exists('date_popup')) {
      $form['next_charge']['next_charge_time'] = array(
        '#type' => 'date_popup',
        '#title' => t('Date/Time'),
        '#date_format' => 'm/d/Y H:i',
        '#default_value' => date('Y-m-d H:i', $fee->next_charge),
        '#timezone' => 'UTC',
      );
    }
    else {
      $form['next_charge']['next_charge_date'] = array(
        '#type' => 'date',
        '#title' => t('Date'),
        '#default_value' => array(
          'year' => date('Y', $fee->next_charge),
          'month' => date('n', $fee->next_charge),
          'day' => date('j', $fee->next_charge),
        ),
      );
    }
    $form['regular'] = array(
      '#type' => 'fieldset',
      '#title' => t('Regular interval'),
      '#collapsible' => FALSE,
      '#description' => t('Modify the length of the billing period for this fee. Changing this value will reset the timer for the next charge. You can also charge the fee manually to collect payment ahead of time and reset the interval.'),
      '#attributes' => array(
        'class' => array(
          'interval-fieldset',
        ),
      ),
    );

    // There are different interval settings for recurring orders & products.
    if ($fee->module == 'uc_recurring_product') {
      list($fee->regular_interval_value, $fee->regular_interval_unit) = explode(' ', $fee->regular_interval);
      $form['regular']['regular_interval_value'] = array(
        '#type' => 'select',
        '#options' => drupal_map_assoc(range(1, 52)),
        '#default_value' => $fee->regular_interval_value,
      );
      $form['regular']['regular_interval_unit'] = array(
        '#type' => 'select',
        '#options' => array(
          'days' => t('day(s)'),
          'weeks' => t('week(s)'),
          'months' => t('month(s)'),
          'years' => t('year(s)'),
        ),
        '#default_value' => $fee->regular_interval_unit,
      );
    }
    else {
      $form['regular']['regular_interval'] = array(
        '#type' => 'select',
        '#options' => uc_recurring_order_get_intervals(),
        '#default_value' => $fee->regular_interval,
      );
    }
    $form['reset_next_charge'] = array(
      '#type' => 'checkbox',
      '#title' => t('Reset the next charge timer upon form submission using the specified interval.'),
      '#description' => t('This will ignore the next charge field above and instead reset the next charge date to one regular interval from now.'),
      '#attributes' => array(
        'class' => array(
          'reset-next-charge',
        ),
      ),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#suffix' => l(t('Cancel'), request_uri()),
    );
    return $form;
  }
  else {
    drupal_set_message(t('Invalid fee handler was given, try again from the operations for this <a href="@url">recurring fee</a>, if problem persists contact the site administrator.', array(
      '@url' => url(request_uri()),
    )), 'error');
  }
}