You are here

function book_access_permissions_form_submit in Book access 6

Submission callback for the administration settings.

File

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

Code

function book_access_permissions_form_submit($form, &$form_state) {
  $bid = $form['#bid'];
  $grants = array(
    'grant_view' => 'view',
    'grant_update' => 'update',
    'grant_delete' => 'delete',
  );
  $row = new stdClass();
  $row->nid = $bid;
  db_query("DELETE FROM {book_access_role} WHERE nid = %d", $bid);
  foreach ($form['#rids'] as $rid) {
    $row->rid = $rid;
    foreach ($grants as $grant => $var) {
      $row->{$grant} = !empty($form_state['values']['roles'][$var][$rid]);
    }
    drupal_write_record('book_access_role', $row);
  }
  foreach ($form['#uids'] as $uid) {
    $bool = db_result(db_query_range("SELECT 1 FROM {book_access_user} WHERE nid = %d AND uid = %d", $bid, $uid, 0, 1));
    $row->uid = $uid;
    foreach ($grants as $grant => $var) {
      $row->{$grant} = !empty($form_state['values']['users'][$var][$uid]);
    }
    drupal_write_record('book_access_user', $row, $bool ? array(
      'nid',
      'uid',
    ) : array());
  }
  $batch = array(
    'title' => t('Rebuilding book access permissions'),
    'operations' => array(
      array(
        '_book_access_rebuild_batch_operation',
        array(
          $bid,
        ),
      ),
    ),
    'finished' => '_book_access_rebuild_batch_finished',
    'file' => drupal_get_path('module', 'book_access') . '/book_access.admin.inc',
  );
  batch_set($batch);
}