You are here

function shib_auth_save_rule in Shibboleth Authentication 6.4

Same name and namespace in other branches
  1. 7.4 shib_auth_roles_forms.inc \shib_auth_save_rule()

Saves a new rule into database

Parameters

$update - decides if it is a new rule (NULL), or we're just modifing one ('id'):

$form_state - the state of the form, which we have just received, including all of the variables:

2 calls to shib_auth_save_rule()
shib_auth_edit_rule_submit in ./shib_auth_roles_forms.inc
Edits a rule, containing he rule name, the server attrubite, the RegExp, and the role names by calling save rule
shib_auth_new_rule_submit in ./shib_auth_roles_forms.inc
Creates a new rule, containing he rule name, the server attrubite, the RegExp, and the role names by calling save rule

File

./shib_auth_roles_forms.inc, line 230
Roles manager forms.

Code

function shib_auth_save_rule($form_state, $update) {
  $new_id = $form_state['values']['shib_auth_new_id'] == '0' ? NULL : (int) $form_state['values']['shib_auth_new_id'];

  // collect ther roles into an array
  $roles = array();
  if (is_array($form_state['values']['shib_auth_roles'])) {
    foreach ($form_state['values']['shib_auth_roles'] as $role_id) {
      if ($role_id) {
        $roles[] = $role_id;
      }
    }
  }

  //save the new element into an array
  $new_element = array(
    'id' => $new_id,
    'field' => urlencode($form_state['values']['shib_auth_new_attrib']),
    'regexpression' => urlencode($form_state['values']['shib_auth_new_regexp']),
    'role' => serialize($roles),
    'sticky' => urlencode($form_state['values']['shib_auth_new_sticky']),
  );

  //write it in a record
  $ret = drupal_write_record('shib_auth', $new_element, $update);

  // if it wasn't an error
  if (empty($update)) {
    if ($ret = SAVED_NEW) {
      drupal_set_message(t('New rule has been stored.'));
    }
    else {
      drupal_set_message(t('Unexpected error has been detected.'));
    }
  }
  else {
    if ($ret = SAVED_UPDATED) {
      drupal_set_message(t('The rule has been modified.'));
    }
    else {
      drupal_set_message(t('Unexpected error has been detected.'));
    }
  }

  //if everything was fine, print the rules with the newly added/modified one
  drupal_goto('admin/user/shib_auth/rules');
}