function nodeaccess_grants_form_submit in Nodeaccess 5
Same name and namespace in other branches
- 6.2 nodeaccess.module \nodeaccess_grants_form_submit()
- 6 nodeaccess.module \nodeaccess_grants_form_submit()
- 7 nodeaccess.module \nodeaccess_grants_form_submit()
Submit function for nodeaccess_grants_form.
File
- ./
nodeaccess.module, line 434
Code
function nodeaccess_grants_form_submit($form_id, $form_values) {
global $form_values;
global $user;
$grants = array();
$nid = $form_values['nid'];
$node->nid = $nid;
foreach (array(
'uid',
'rid',
) as $type) {
$realm = 'nodeaccess_' . $type;
if (is_array($form_values[$type])) {
foreach ($form_values[$type] as $gid => $line) {
$grant = array(
'gid' => $gid,
'realm' => $realm,
'grant_view' => $line['grant_view'],
'grant_update' => $line['grant_update'],
'grant_delete' => $line['grant_delete'],
);
if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
$grants[] = $grant;
}
}
}
node_access_write_grants($node, $grants, $realm);
}
// Save role and user grants to our own table.
db_query("DELETE FROM {nodeaccess} WHERE nid = %d", $nid);
foreach ($grants as $grant) {
db_query("INSERT INTO {nodeaccess} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, '%s', %d, %d, %d)", $nid, $grant['gid'], $grant['realm'], $grant['grant_view'], $grant['grant_update'], $grant['grant_delete']);
}
drupal_set_message(t('Grants saved.'));
}