You are here

function book_access_user_add_submit in Book access 6

Submission callback to add a new user to the permissions table.

1 string reference to 'book_access_user_add_submit'
book_access_permissions_form in ./book_access.admin.inc
Book access configuration page.

File

./book_access.admin.inc, line 166
Administration interface for the Book access module.

Code

function book_access_user_add_submit($form, &$form_state) {
  $bid = $form['#bid'];
  $grants = array(
    'grant_view' => 'view',
    'grant_update' => 'update',
    'grant_delete' => 'delete',
  );
  $username = $form_state['values']['user']['username'];
  if (!($user = user_load(array(
    'name' => $username,
  )))) {
    drupal_set_message(t('The user %user does not exist.', array(
      '%user' => $username,
    )), 'error');
  }
  else {
    $bool = db_result(db_query_range("SELECT 1 FROM {book_access_user} WHERE nid = %d AND uid = %d", $bid, $user->uid, 0, 1));
    $row = new stdClass();
    $row->nid = $bid;
    $row->uid = $user->uid;
    foreach ($grants as $grant => $var) {
      $row->{$grant} = $form_state['values']['user'][$var];
    }
    drupal_write_record('book_access_user', $row, $bool ? array(
      'nid',
      'uid',
    ) : array());
    _book_access_permissions_warning();
  }
  $form_state['redirect'] = 'node/' . $bid . '/book_access';
}