$value) { $roles_options[$key] = $value; } // Add the form element to toggle if signups are allowed. $form['signup']['signup_restrict'] = array( '#type' => 'fieldset', '#title' => t('Restrict access to certain Roles'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#tree' => TRUE, ); $form['signup']['signup_restrict']['options'] = array( '#type' => 'checkboxes', '#options' => $roles_options, '#default_value' => $default_options, ); } } /** * Implementation of hook_nodeapi * * @param unknown_type $node * @param unknown_type $op * @param unknown_type $a3 * @param unknown_type $a4 */ function signup_restrict_by_role_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { global $user; if ($node->type == 'event' && $node->signup) { switch($op) { case 'load': // Check if signups should be enabled for the current user $roles = $user->roles; $matches = implode(', ', array_keys($roles)); $result = db_query("SELECT rid FROM {signup_restrict_by_role} WHERE nid = %d AND rid IN (%s)", $node->nid, $matches); if (db_num_rows($result) == 0) { // Hrm. Are there any settings for this node? If not, default to signups enabled $result = db_query("SELECT rid FROM {signup_restrict_by_role} WHERE nid = %d", $node->nid); if (db_num_rows($result) != 0) { // This is a bit hacky, is there a better way to tell we're being loaded for editing? if (arg(2) != 'edit') { $node->signup = FALSE; } } } break; case 'insert': case 'update': db_query("DELETE FROM {signup_restrict_by_role} WHERE nid = %d", $node->nid); foreach ($node->signup_restrict[options] as $key => $value) { if ($value) { db_query("INSERT INTO {signup_restrict_by_role} (nid, rid) VALUES (%d, %d)", $node->nid, $key); } } break; } } }