You are here

function sms_valid_admin_ruleset_form in SMS Framework 6

Same name and namespace in other branches
  1. 6.2 modules/sms_valid/sms_valid.admin.inc \sms_valid_admin_ruleset_form()
  2. 7 modules/sms_valid/sms_valid.admin.inc \sms_valid_admin_ruleset_form()

Validation ruleset editing form

Parameters

$prefix: Prefix for ruleset that will be displayed on page load.

1 string reference to 'sms_valid_admin_ruleset_form'
sms_valid_menu in modules/sms_valid/sms_valid.module
Implementation of hook_menu()

File

modules/sms_valid/sms_valid.admin.inc, line 279
SMS Framework core module: Admin settings form functions

Code

function sms_valid_admin_ruleset_form(&$form_state, $prefix = NULL) {
  if ($prefix === NULL) {
    $ruleset = FALSE;
  }
  else {
    $ruleset = sms_valid_get_ruleset($prefix);
  }

  // Ruleset selection area
  $form['title'] = array(
    '#type' => 'item',
    '#value' => t('Select a ruleset from the drop-down box and click Refresh to update the ruleset form below'),
  );
  $form['select_prefix'] = array(
    '#type' => 'select',
    '#options' => sms_valid_get_rulesets_for_form(),
    '#default_value' => $prefix,
  );
  $form['select'] = array(
    '#type' => 'submit',
    '#value' => t('Refresh Editor (below)'),
    '#submit' => array(
      'sms_valid_admin_ruleset_form_select',
    ),
  );

  // Ruleset editor area
  $form['ruleset'] = array(
    '#type' => 'fieldset',
    '#title' => 'Ruleset',
  );

  // If this is a new ruleset then this should be a textfield
  $form['ruleset']['prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Prefix'),
    '#size' => 5,
    '#maxlength' => 5,
    '#value' => $ruleset ? $ruleset['prefix'] : '',
    '#description' => 'Should be 4 digits or less. Highest allowed prefix is 65535.',
  );
  $form['ruleset']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 80,
    '#maxlength' => 200,
    '#default_value' => $ruleset ? $ruleset['name'] : '',
  );

  // Display a proper country list if the countries_api module is loaded
  if (function_exists('countries_api_get_array')) {
    $options[''] = '(none)';
    $options = array_merge($options, countries_api_get_array());
    $form['ruleset']['iso2'] = array(
      '#type' => 'select',
      '#title' => t('Associated country (optional)'),
      '#options' => $options,
      '#default_value' => $ruleset ? $ruleset['iso2'] : '',
    );
  }
  else {
    $form['ruleset']['iso2'] = array(
      '#type' => 'textfield',
      '#title' => t('Country code (ISO 3166-1 alpha-2) (optional)'),
      '#size' => 2,
      '#maxlength' => 2,
      '#default_value' => $ruleset ? $ruleset['iso2'] : '',
      '#description' => 'This would be a nice drop-down box if you had the Countries API module enabled.',
    );
  }
  $form['ruleset']['out'] = array(
    '#type' => 'checkbox',
    '#title' => 'Allow outbound communication',
    '#default_value' => $ruleset ? sms_valid_ruleset_is_enabled($prefix, SMS_DIR_OUT) : 0,
  );
  $form['ruleset']['in'] = array(
    '#type' => 'checkbox',
    '#title' => 'Allow inbound commmunication',
    '#default_value' => $ruleset ? sms_valid_ruleset_is_enabled($prefix, SMS_DIR_IN) : 0,
  );
  $form['ruleset']['rules'] = array(
    '#type' => 'textarea',
    '#title' => 'Rules',
    '#cols' => 80,
    '#rows' => 15,
    '#default_value' => $ruleset ? sms_valid_rules_to_text($ruleset['rules']) : '',
    '#description' => t('One rule per line. Enter a number prefix (any length), not including the ruleset prefix.<br />Any prefix with a "-" at the end signifies an expicit deny.<br />Any prefix with a "+" at the end signifies an explicit allow.<br />All other rules are ignored.<br />Default is to deny any numbers that do not match.<br />Comments must be prefixed with a hash (#). You may place comments in-line only.<br />See the guide at %url', array(
      '%url' => 'http://moo0.net/smsframework/?q=node/19',
    )),
  );
  $form['ruleset']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Ruleset'),
  );
  return $form;
}