You are here

function uc_roles_notify_settings in Ubercart 5

Form builder for role notification settings.

1 string reference to 'uc_roles_notify_settings'
uc_roles_menu in uc_roles/uc_roles.module
Implementation of hook_menu().

File

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

Code

function uc_roles_notify_settings() {
  uc_add_js('$(document).ready(function() { if ($("#edit-uc-roles-reminder-granularity").val() == "never") {$("#edit-uc-roles-reminder-length").attr("disabled", "disabled").val("");} });', 'inline');

  //Set Granted Notifications
  $form['grant'] = array(
    '#type' => 'fieldset',
    '#title' => t('Granted message'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['grant']['uc_roles_grant_notification'] = array(
    '#type' => 'checkbox',
    '#default_value' => variable_get('uc_roles_grant_notification', FALSE),
    '#title' => t('Send email after customer receives new role'),
  );
  $form['grant']['uc_roles_grant_notification_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Message subject'),
    '#default_value' => variable_get('uc_roles_grant_notification_subject', uc_get_message('uc_roles_grant_subject')),
  );
  $form['grant']['uc_roles_grant_notification_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message text'),
    '#default_value' => variable_get('uc_roles_grant_notification_message', uc_get_message('uc_roles_grant_message')),
    '#description' => t('The message the user receives when granted a new role (<a href="!url">uses order, uc_roles, and global tokens</a>).', array(
      '!url' => url('admin/store/help/tokens'),
    )),
    '#rows' => 10,
  );
  $form['grant']['uc_roles_grant_notification_format'] = filter_form(variable_get('uc_roles_grant_notification_format', FILTER_FORMAT_DEFAULT), NULL, array(
    'uc_roles_grant_notification_format',
  ));

  //Set Revocation Notifications
  $form['revoke'] = array(
    '#type' => 'fieldset',
    '#title' => t('Expiration message'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['revoke']['uc_roles_revocation_notification'] = array(
    '#type' => 'checkbox',
    '#default_value' => variable_get('uc_roles_revocation_notification', FALSE),
    '#title' => t('Send email after customer loses role'),
  );
  $form['revoke']['uc_roles_revocation_notification_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Message subject'),
    '#default_value' => variable_get('uc_roles_revocation_notification_subject', uc_get_message('uc_roles_revoke_subject')),
  );
  $form['revoke']['uc_roles_revocation_notification_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message text'),
    '#default_value' => variable_get('uc_roles_revocation_notification_message', uc_get_message('uc_roles_revoke_message')),
    '#description' => t('The message the user receives when a role expires (<a href="!url">uses order, uc_roles, and global tokens</a>).', array(
      '!url' => url('admin/store/help/tokens'),
    )),
    '#rows' => 10,
  );
  $form['revoke']['uc_roles_revocation_notification_format'] = filter_form(variable_get('uc_roles_revocation_notification_format', FILTER_FORMAT_DEFAULT), NULL, array(
    'uc_roles_revocation_notification_format',
  ));

  //Set Renewal Notifications
  $form['renew'] = array(
    '#type' => 'fieldset',
    '#title' => t('Renewal message'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['renew']['uc_roles_renewal_notification'] = array(
    '#type' => 'checkbox',
    '#default_value' => variable_get('uc_roles_renewal_notification', FALSE),
    '#title' => t('Send email after customer renews existing role'),
  );
  $form['renew']['uc_roles_renewal_notification_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Message subject'),
    '#default_value' => variable_get('uc_roles_renewal_notification_subject', uc_get_message('uc_roles_renew_subject')),
  );
  $form['renew']['uc_roles_renewal_notification_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message text'),
    '#default_value' => variable_get('uc_roles_renewal_notification_message', uc_get_message('uc_roles_renew_message')),
    '#description' => t('The message the user receives when a role is renewed (<a href="!url">uses order, uc_roles, and global tokens</a>).', array(
      '!url' => url('admin/store/help/tokens'),
    )),
    '#rows' => 10,
  );
  $form['renew']['uc_roles_renewal_notification_format'] = filter_form(variable_get('uc_roles_renewal_notification_format', FILTER_FORMAT_DEFAULT), NULL, array(
    'uc_roles_renewal_notification_format',
  ));

  //Set Reminder Notifications
  $form['reminder'] = array(
    '#type' => 'fieldset',
    '#title' => t('Expiration reminder message'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $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>',
  );
  $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>',
    '#attributes' => array(
      //Javascript to disable qty on never select
      'onchange' => 'if (this.value == "never") {$("#edit-uc-roles-reminder-length").attr("disabled", "disabled").val("");} else {$("#edit-uc-roles-reminder-length").removeAttr("disabled");}',
    ),
  );
  $form['reminder']['uc_roles_reminder_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Message subject'),
    '#default_value' => variable_get('uc_roles_reminder_subject', uc_get_message('uc_roles_reminder_subject')),
  );
  $form['reminder']['uc_roles_reminder_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message text'),
    '#default_value' => variable_get('uc_roles_reminder_message', uc_get_message('uc_roles_reminder_message')),
    '#description' => t('The message the user receives reminding them of the role expiration (<a href="!url">uses order, uc_roles, and global tokens</a>).', array(
      '!url' => url('admin/store/help/tokens'),
    )),
    '#rows' => 10,
  );
  $form['reminder']['uc_roles_reminder_format'] = filter_form(variable_get('uc_roles_reminder_format', FILTER_FORMAT_DEFAULT), NULL, array(
    'uc_roles_reminder_format',
  ));
  return system_settings_form($form);
}