You are here

function workflow_access_form_submit in Workflow 5.2

Same name and namespace in other branches
  1. 5 workflow_access.module \workflow_access_form_submit()
  2. 6.2 workflow_access/workflow_access.module \workflow_access_form_submit()
  3. 6 workflow_access/workflow_access.module \workflow_access_form_submit()
  4. 7.2 workflow_access/workflow_access.pages.inc \workflow_access_form_submit()
  5. 7 workflow_access/workflow_access.module \workflow_access_form_submit()

Store permission settings for workflow states.

File

./workflow_access.module, line 177
Provides node access permissions based on workflow states.

Code

function workflow_access_form_submit($form_id, $form_values) {
  foreach ($form_values['workflow_access'] as $sid => $access) {

    // Ignore irrelevant keys.
    if (!is_numeric($sid)) {
      continue;
    }
    $grants = array();
    db_query("DELETE FROM {workflow_access} WHERE sid = %d", $sid);
    foreach ($access['view'] as $rid => $checked) {
      $grants[] = array(
        'realm' => $rid == -1 ? 'workflow_access_owner' : 'workflow_access',
        'gid' => $rid == -1 ? $node->uid : $rid,
        'grant_view' => (bool) $checked,
        'grant_update' => (bool) $access['update'][$rid],
        'grant_delete' => (bool) $access['delete'][$rid],
      );
      db_query("INSERT INTO {workflow_access} (sid, rid, grant_view, grant_update, grant_delete) VALUES (%d, %d, %d, %d, %d)", $sid, $rid, (bool) $checked, (bool) $access['update'][$rid], (bool) $access['delete'][$rid]);
    }

    // Update all nodes having some workflow state to reflect new settings.
    $result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {workflow_node} wn ON wn.nid = n.nid WHERE wn.sid = %d", $sid);
    while ($node = db_fetch_object($result)) {

      // TODO: this only works with workflow_access realm, not the workflow_access_owner realm?!
      node_access_write_grants($node, $grants, 'workflow_access');
    }
  }
  drupal_set_message(t('Workflow access permissions updated.'));
}