You are here

function uc_roles_feature_settings in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_roles/uc_roles.module \uc_roles_feature_settings()
  2. 6.2 uc_roles/uc_roles.module \uc_roles_feature_settings()

Form builder for role settings.

1 string reference to 'uc_roles_feature_settings'
uc_roles_uc_product_feature in uc_roles/uc_roles.module
Implements hook_uc_product_feature().

File

uc_roles/uc_roles.module, line 785
Grants roles upon accepted payment of products.

Code

function uc_roles_feature_settings($form, &$form_state) {
  $default_role_choices = user_roles(TRUE);
  unset($default_role_choices[DRUPAL_AUTHENTICATED_RID]);
  if (!count($default_role_choices)) {
    $form['no_roles'] = array(
      '#markup' => t('You need to <a href="!url">create new roles</a> before any can be added as product features.', array(
        '!url' => url('admin/people/permissions/roles', array(
          'query' => array(
            'destination' => 'admin/store/settings/products',
          ),
        )),
      )),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
    return $form;
  }
  foreach (uc_order_status_list('general') as $status) {
    $statuses[$status['id']] = $status['title'];
  }
  $form['uc_roles_default_role'] = array(
    '#type' => 'select',
    '#title' => t('Default role'),
    '#default_value' => variable_get('uc_roles_default_role', NULL),
    '#description' => t('The default role Ubercart grants on specified products.'),
    '#options' => _uc_roles_get_choices(),
  );
  $form['uc_roles_default_role_choices'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Product roles'),
    '#default_value' => variable_get('uc_roles_default_role_choices', array()),
    '#multiple' => TRUE,
    '#description' => t('These are roles that Ubercart can grant to customers who purchase specified products. If you leave all roles unchecked, they will all be eligible for adding to a product.'),
    '#options' => $default_role_choices,
  );
  $form['role_lifetime'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default role expiration'),
  );
  $form['role_lifetime']['uc_roles_default_end_expiration'] = array(
    '#type' => 'select',
    '#title' => t('Expiration type'),
    '#options' => array(
      'rel' => t('Relative to purchase date'),
      'abs' => t('Fixed date'),
    ),
    '#default_value' => variable_get('uc_roles_default_end_expiration', 'rel'),
  );
  $form['role_lifetime']['uc_roles_default_length'] = array(
    '#type' => 'textfield',
    '#default_value' => variable_get('uc_roles_default_granularity', 'never') == 'never' ? NULL : variable_get('uc_roles_default_length', NULL),
    '#size' => 4,
    '#maxlength' => 4,
    '#prefix' => '<div class="expiration">',
    '#suffix' => '</div>',
    '#states' => array(
      'visible' => array(
        'select[name="uc_roles_default_end_expiration"]' => array(
          'value' => 'rel',
        ),
      ),
      'invisible' => array(
        'select[name="uc_roles_default_granularity"]' => array(
          'value' => 'never',
        ),
      ),
    ),
  );
  $form['role_lifetime']['uc_roles_default_granularity'] = array(
    '#type' => 'select',
    '#default_value' => variable_get('uc_roles_default_granularity', 'never'),
    '#options' => array(
      'never' => t('never'),
      'day' => t('day(s)'),
      'week' => t('week(s)'),
      'month' => t('month(s)'),
      'year' => t('year(s)'),
    ),
    '#description' => t('From the time the role was purchased.'),
    '#prefix' => '<div class="expiration">',
    '#suffix' => '</div>',
    '#states' => array(
      'visible' => array(
        'select[name="uc_roles_default_end_expiration"]' => array(
          'value' => 'rel',
        ),
      ),
    ),
  );
  $form['role_lifetime']['absolute'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => array(
        'select[name="uc_roles_default_end_expiration"]' => array(
          'value' => 'abs',
        ),
      ),
    ),
  );
  $form['role_lifetime']['absolute']['uc_roles_default_end_time'] = array(
    '#type' => 'date',
    '#description' => t('Expire the role at the beginning of this day.'),
    '#default_value' => variable_get('uc_roles_default_end_time', array(
      'day' => date('j'),
      'month' => date('n'),
      'year' => date('Y'),
    )),
  );
  $form['role_lifetime']['uc_roles_default_by_quantity'] = array(
    '#type' => 'checkbox',
    '#title' => t('Multiply by quantity'),
    '#description' => t('Check if the role duration should be multiplied by the quantity purchased.'),
    '#default_value' => variable_get('uc_roles_default_by_quantity', FALSE),
  );
  $form['reminder']['uc_roles_reminder_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Time before reminder'),
    '#default_value' => variable_get('uc_roles_reminder_granularity', 'never') == 'never' ? NULL : variable_get('uc_roles_reminder_length', NULL),
    '#size' => 4,
    '#maxlength' => 4,
    '#prefix' => '<div class="expiration">',
    '#suffix' => '</div>',
    '#states' => array(
      'disabled' => array(
        'select[name="uc_roles_reminder_granularity"]' => array(
          'value' => 'never',
        ),
      ),
    ),
  );
  $form['reminder']['uc_roles_reminder_granularity'] = array(
    '#type' => 'select',
    '#default_value' => variable_get('uc_roles_reminder_granularity', 'never'),
    '#options' => array(
      'never' => t('never'),
      'day' => t('day(s)'),
      'week' => t('week(s)'),
      'month' => t('month(s)'),
      'year' => t('year(s)'),
    ),
    '#description' => t('The amount of time before a role expiration takes place that a customer is notified of its expiration.'),
    '#prefix' => '<div class="expiration">',
    '#suffix' => '</div>',
  );
  $form['uc_roles_default_show_expiration'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show expirations on user page'),
    '#default_value' => variable_get('uc_roles_default_show_expiration', TRUE),
    '#description' => t('If users have any role expirations they will be displayed on their account page.'),
  );
  return $form;
}