You are here

function node_privacy_byrole_quick_grant_admin_content_submit in node privacy byrole 5

File

./node_privacy_byrole_quick_grant.module, line 80
Addon to Node Privacy By Role to mass grant access to a specific node type where Rebuild Permissions isn't available or appropriate.

Code

function node_privacy_byrole_quick_grant_admin_content_submit($form_id, &$form_values) {
  $nodes = array();
  $result = db_query("SELECT nid FROM {node} WHERE type = '%s'", $form_values['node_type']);
  $grant_view = empty($form_values['grant']['view']) ? 0 : 1;
  $grant_update = empty($form_values['grant']['update']) ? 0 : 1;
  $grant_delete = empty($form_values['grant']['delete']) ? 0 : 1;
  while ($node = db_fetch_object($result)) {
    reset($form_values['roles']);
    while (list(, $rid) = each($form_values['roles'])) {
      db_query("REPLACE INTO {node_privacy_byrole} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, 'node_privacy_byrole_role', {$grant_view}, {$grant_update}, {$grant_delete})", $node->nid, $rid);
    }
  }
  drupal_set_message(t('Updated node access permissions on node type !type', array(
    '!type' => $form_values['node_type'],
  )), 'status');
}