$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' => FALSE, '#tree' => TRUE, ); $form['signup']['signup_restrict']['options'] = array( '#type' => 'checkboxes', '#options' => $roles_options, '#default_value' => $default_options, ); } } /** * Implementation of hook_nodeapi */ function signup_restrict_by_role_nodeapi(&$node, $op, $teaser=NULL, $page=NULL) { global $user; if ($node->type == 'event' && $node->signup) { switch($op) { case 'load': // Check if signups should be enabled for the current user $matches = implode(', ', array_keys($user->roles)); $result = db_result(db_query("SELECT COUNT(rid) FROM {signup_restrict_by_role} WHERE nid = %d AND rid IN (%s)", $node->nid, $matches)); if ($result == 0) { // Hrm. Are there any settings for this node? If not, default to signups enabled $result = db_result(db_query("SELECT COUNT(rid) FROM {signup_restrict_by_role} WHERE nid = %d", $node->nid)); if($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; } } }