function shib_auth_new_rule in Shibboleth Authentication 6.3
Same name and namespace in other branches
- 6.4 shib_auth_roles_forms.inc \shib_auth_new_rule()
- 7.4 shib_auth_roles_forms.inc \shib_auth_new_rule()
Saves a new rule, containing he rule name, the server attrubite, the RegExp, and the role names
@returns an edit form, if there was a problem with the input values
Parameters
$received_form - the identifier of the form, which we have just received:
2 string references to 'shib_auth_new_rule'
- shib_auth_edit_form in ./
shib_auth.module - Generate the shibboleth rule adding form
- shib_auth_menu in ./
shib_auth.module - Generate the menu element to access the Shibboleth authentication module's administration page @returns HTML text of the administer menu element
File
- ./
shib_auth.module, line 682 - This is a Shibboleth authentication module.
Code
function shib_auth_new_rule($received_form) {
$form = array();
if ($received_form['post']['form_id'] == 'shib_auth_new_rule' || $received_form['#parameters'][1]['post']['form_id'] == 'shib_auth_edit_rule') {
$update = array();
if (isset($received_form['#parameters'])) {
$received_form = $received_form['#parameters'][1];
$update = "id";
}
// if the received informations weren't empty
if (!empty($received_form['post']['shib_auth_new_attrib']) && !empty($received_form['post']['shib_auth_new_regexp'])) {
$new_id = $received_form['post']['shib_auth_new_id'] == '0' ? NULL : (int) $received_form['post']['shib_auth_new_id'];
// collect ther roles into an array
$roles = array();
if (is_array($received_form['post']['shib_auth_roles'])) {
foreach ($received_form['post']['shib_auth_roles'] as $role_id) {
$role_entry = db_query("SELECT * FROM {role} WHERE rid = %d", array(
$role_id,
));
$role_ent = db_fetch_array($role_entry);
$role = $role_ent['name'];
$roles[$role_id] = $role;
}
}
//save the new element into an array
$new_element = array(
'id' => $new_id,
'field' => urlencode($received_form['post']['shib_auth_new_attrib']),
'regexpression' => urlencode($received_form['post']['shib_auth_new_regexp']),
'role' => urlencode(serialize($roles)),
);
//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('New rule has been stored.');
}
else {
drupal_set_message('Unexpected error has been detected.');
}
}
else {
if ($ret = SAVED_UPDATED) {
drupal_set_message('The rule has been modified.');
}
else {
drupal_set_message('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');
}
}
// if something was wrang, print the edit form again
return shib_auth_edit_form(array(
0,
'',
'',
'',
'Add rule',
));
}