You are here

function autoassignrole_admin_form_submit in Auto Assign Role 6.2

Same name and namespace in other branches
  1. 6 autoassignrole-admin.inc \autoassignrole_admin_form_submit()

Admin form submit handler.

File

./autoassignrole-admin.inc, line 346
The autoassignrole-admin.inc file

Code

function autoassignrole_admin_form_submit($form_id, &$form_state) {
  $sql = "UPDATE {autoassignrole} set value = '%s' where arid = '%s'";
  db_query($sql, $form_state['values']['auto_active'], 'auto_active');
  db_query($sql, serialize($form_state['values']['auto_roles']), 'auto_roles');
  db_query($sql, $form_state['values']['user_active'], 'user_active');
  db_query($sql, serialize($form_state['values']['user_roles']), 'user_roles');
  db_query($sql, $form_state['values']['user_multiple'], 'user_multiple');
  db_query($sql, $form_state['values']['user_title'], 'user_title');
  db_query($sql, $form_state['values']['user_fieldset_title'], 'user_fieldset_title');
  db_query($sql, $form_state['values']['user_required'], 'user_required');
  db_query($sql, $form_state['values']['user_sort'], 'user_sort');
  db_query($sql, $form_state['values']['user_description'], 'user_description');
  db_query($sql, $form_state['values']['user_selection'], 'user_selection');
  db_query($sql, $form_state['values']['auto_admin_active'], 'auto_admin_active');
  preg_match('/\\[nid:(\\d+)\\]/', $form_state['values']['node_user_register'], $matches);
  db_query($sql, isset($matches[1]) ? $matches[1] : '', 'node_user_register');

  // Role assignment based on path.
  db_query("truncate {autoassignrole_page}");
  $roles = user_roles(TRUE);
  unset($roles[DRUPAL_AUTHENTICATED_RID]);
  foreach ($roles as $k => $v) {
    if ($form_state['values']["path_active_{$k}"]) {
      $path = $form_state['values']["path_{$k}"];
      $title = $form_state['values']["path_title_{$k}"];
      $description = $form_state['values']["path_description_{$k}"];
      $display = $form_state['values']["path_display_{$k}"];
      $format = $form_state['values']["path_format_{$k}"];
      $weight = $form_state['values']["path_weight_{$k}"];
      $menu = $form_state['values']["path_menu_{$k}"];
      $registration = $form_state['values']["path_registration_{$k}"];
      db_query("INSERT INTO {autoassignrole_page} (rid, display, path, title, description, format, weight, menu, registration) VALUES(%d, '%s', '%s', '%s', '%s', %d, %d, '%s', %d)", $k, $display, $path, $title, $description, $format, $weight, $menu, $registration);
    }
  }

  // Rebuild the menu.
  menu_rebuild();
  drupal_set_message(t('The changes have been saved.'));
}