Index: signup.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.install,v
retrieving revision 1.16
diff -u -r1.16 signup.install
--- signup.install 22 Dec 2007 09:07:18 -0000 1.16
+++ signup.install 27 Feb 2008 17:51:25 -0000
@@ -249,7 +249,7 @@
* Add "cancel own signups" permission to all roles that have "sign up
* for content" permission.
*/
-function signup_update_5202() {
+function signup_update_5204() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
@@ -283,6 +283,22 @@
return array();
}
+/**
+ * Add an "access" column.
+ */
+function signup_update_5205() {
+ $ret = array();
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql("ALTER TABLE {signup} ADD access varchar(255) default NULL");
+ break;
+ case 'pgsql':
+ db_add_column($ret, 'signup', 'access', 'varchar(255)', array('not null' => FALSE, 'default' => NULL));
+ break;
+ }
+ return $ret;
+}
function _signup_db_column_exists($table, $column) {
switch ($GLOBALS['db_type']) {
Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.129
diff -u -r1.129 signup.module
--- signup.module 26 Jan 2008 03:02:39 -0000 1.129
+++ signup.module 27 Feb 2008 17:51:27 -0000
@@ -315,6 +315,39 @@
}
/**
+ * Returns TRUE if user has access to this node. Checks the role-specific permissions for the node.
+ */
+function _signup_access(&$node, $account = NULL) {
+ // All signups with an empty access setting are available to all roles.
+ if (!user_access('sign up for content', $account)) {
+ return FALSE;
+ }
+
+ if (!$node->signup_access) {
+ return TRUE;
+ }
+
+ if (is_null($account)) {
+ global $user;
+ $account = $user;
+ }
+
+ // Admin can always sign up.
+ if ($account->uid == 1) {
+ return TRUE;
+ }
+
+ // Otherwise, check roles
+ static $roles = array();
+ if (!isset($roles[$account->uid])) {
+ $roles[$account->uid] = array_keys($account->roles);
+ $roles[$account->uid][] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
+ }
+
+ return array_intersect($node->signup_access, $roles[$account->uid]);
+}
+
+/**
* Implementation of hook_perm().
* @ingroup signup_core
*/
@@ -362,6 +395,18 @@
'#default_value' => variable_get('signup_node_default_state_'. $type, 'disabled'),
'#description' => t('If %disabled is selected, signups will not be possible for this content type. If %allowed_off is selected, signups will be off by default, but users with the %admin_all_signups permission will be able to allow signups for specific posts of this content type. If %enabled_on is selected, users will be allowed to signup for this content type unless an administrator disbles signups on specific posts.', array('%disabled' => t('Disabled'), '%allowed_off' => t('Allowed (off by default)'), '%enabled_on' => t('Enabled (on by default)'), '%admin_all_signups' => t('administer all signups'))),
);
+ $default_signup_access = variable_get('signup_access_' . $type, NULL);
+ if (is_null($default_signup_access)) {
+ $defaults = db_fetch_array(db_query("SELECT access from {signup} WHERE nid = 0"));
+ $default_signup_access = explode(',', $defaults['access']);
+ }
+ $form['workflow']['signup_access'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Signup access'),
+ '#default_value' => $default_signup_access,
+ '#options' => user_roles(),
+ '#description' => t('Only the checked roles will be allowed to signup for this node type by default. If no roles are checked, access will not be restricted. Users with %admin_all_signups permission will be able to toggle this setting on a per-node basis.', array('%admin_all_signups' => t('administer all signups'))),
+ );
}
/**
@@ -369,13 +414,12 @@
*/
function signup_alter_node_form($form_id, &$form) {
global $user;
-
// Load the node if it already exists.
if (!empty($form['nid']['#value'])) {
$node = node_load($form['nid']['#value']);
}
else {
- $node = NULL;
+ $node = new stdClass();
}
$signup_type_default = variable_get('signup_node_default_state_'. $form['type']['#value'], 'disabled');
@@ -445,6 +489,13 @@
'#prefix' => '
',
'#suffix' => '
',
);
+
+ // Set node type (needed to set default role-specific signup access).
+ if (!$node->type) {
+ $node->type = $form['type']['#value'];
+ }
+
+ // Include the signup options to the form.
$form['signup']['node_settings']['settings'] = _signup_admin_form($node);
}
}
@@ -521,8 +572,10 @@
*/
function signup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
global $form_values;
+ if (is_array($form_values['signup_access'])) {
+ $form_values['signup_access'] = implode(',', array_keys(array_filter($form_values['signup_access'])));
+ }
$signup_type_default = variable_get('signup_node_default_state_'. $node->type, 'disabled');
-
switch ($op) {
case 'insert':
if (isset($form_values['signup_enabled'])) {
@@ -536,6 +589,7 @@
$form_values['signup_reminder_days_before'],
$form_values['signup_reminder_email'],
$form_values['signup_close_signup_limit'],
+ $form_values['signup_access'],
);
}
}
@@ -555,10 +609,11 @@
$defaults['reminder_days_before'],
$defaults['reminder_email'],
$defaults['close_signup_limit'],
+ $defaults['access'],
);
}
if (isset($values)) {
- db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email, close_signup_limit) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', %d)", $values);
+ db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email, close_signup_limit, access) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', %d, '%s')", $values);
}
break;
@@ -573,7 +628,7 @@
// we might have to change the status, too.
$cur_limit = db_result(db_query("SELECT close_signup_limit FROM {signup} WHERE nid = %d", $node->nid));
$limit_changed = $cur_limit != $node->signup_close_signup_limit;
- db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', send_reminder = %d, reminder_days_before = %d, reminder_email = '%s', close_signup_limit = %d WHERE nid = %d",
+ db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', send_reminder = %d, reminder_days_before = %d, reminder_email = '%s', close_signup_limit = %d, access = '%s' WHERE nid = %d",
$node->signup_forwarding_email,
$node->signup_send_confirmation,
$node->signup_confirmation_email,
@@ -581,18 +636,20 @@
$node->signup_reminder_days_before,
$node->signup_reminder_email,
$node->signup_close_signup_limit,
+ $node->signup_access,
$node->nid
);
}
else {
- db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email, close_signup_limit) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', %d)", $node->nid,
+ db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email, close_signup_limit, access) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', %d)", $node->nid,
$node->signup_forwarding_email,
$node->signup_send_confirmation,
$node->signup_confirmation_email,
$node->signup_send_reminder,
$node->signup_reminder_days_before,
$node->signup_reminder_email,
- $node->signup_close_signup_limit
+ $node->signup_close_signup_limit,
+ $node->signup_access
);
}
if (_signup_event_completed($node) && $node->signup_status) {
@@ -645,6 +702,7 @@
$node->signup_reminder_days_before = $signup->reminder_days_before;
$node->signup_reminder_email = $signup->reminder_email;
$node->signup_close_signup_limit = $signup->close_signup_limit;
+ $node->signup_access = explode(',', $signup->access);
$node->signup_status = $signup->status;
if ($node->nid) {
$node->signup_total = db_result(db_query("SELECT COUNT(*) FROM {signup_log} WHERE nid = %d", $node->nid));
@@ -703,7 +761,7 @@
// The node has been closed for signups, and the user has
// signup permissions. Let them know it's closed.
if (!$node->signup_status) {
- if (user_access('sign up for content')) {
+ if (_signup_access($node)) {
$output = ''. t('Signups closed for this event') .'
';
// If they're logged in and already signed up, show their current
// signup info and give them the option to cancel.
@@ -726,7 +784,7 @@
'!login' => l(t('login'), 'user/login', array(), drupal_get_destination()),
'!register' => l(t('register'), 'user/register', array(), drupal_get_destination()),
);
- if (user_access('sign up for content')) {
+ if (_signup_access($node)) {
$needs_signup_form = TRUE;
$signup_type = 'anon';
}
@@ -744,7 +802,7 @@
if ($needs_signup_form) {
// User isn't signed up, so check to make sure they have signup
// permissions, and if so, print the themed signup form.
- if (user_access('sign up for content')) {
+ if (_signup_access($node)) {
$fieldset = $type == 'node' ? TRUE : FALSE;
$output = drupal_get_form('signup_form', $node, $signup_type, $fieldset);
}
@@ -1202,7 +1260,7 @@
'#description' => t('New signup-enabled nodes will start with these settings.'),
'#collapsible' => true,
);
- $form['node_defaults']['_signup_admin_form'] = _signup_admin_form($node);
+ $form['node_defaults']['_signup_admin_form'] = _signup_admin_form(NULL);
$form['adv_settings'] = array(
'#type' => 'fieldset',
@@ -1243,15 +1301,17 @@
*/
function signup_settings_page_submit($form_id, $form_values) {
$op = isset($form_values['op']) ? $form_values['op'] : '';
+ $form_values['signup_access'] = implode(',', array_keys(array_filter($form_values['signup_access'])));
if ($op == t('Save configuration') && db_num_rows(db_query('SELECT nid FROM {signup} WHERE nid = 0'))) {
- db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', send_reminder = %d, reminder_days_before = %d, reminder_email = '%s', close_signup_limit = %d WHERE nid = 0",
+ db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', send_reminder = %d, reminder_days_before = %d, reminder_email = '%s', close_signup_limit = %d, access = '%s' WHERE nid = 0",
$form_values['signup_forwarding_email'],
$form_values['signup_send_confirmation'],
$form_values['signup_confirmation_email'],
$form_values['signup_send_reminder'],
$form_values['signup_reminder_days_before'],
$form_values['signup_reminder_email'],
- $form_values['signup_close_signup_limit']
+ $form_values['signup_close_signup_limit'],
+ $form_values['signup_access']
);
}
else {
@@ -1270,6 +1330,7 @@
'signup_reminder_days_before',
'signup_reminder_email',
'signup_close_signup_limit',
+ 'signup_access',
);
foreach ($settings as $setting) {
unset($form_values[$setting]);
@@ -1351,7 +1412,7 @@
// If we made it this far, we're going to need the full $user object.
$user = user_load(array('uid' => $signup_form['uid']));
- if (user_access('sign up for content') && $node->signup_status) {
+ if (_signup_access($node) && $node->signup_status) {
// Grab the current time once, since we need it in a few places.
$curtime = time();
@@ -1701,7 +1762,9 @@
$signup_token_description = t('Supported string substitutions: %event, %time, %username, %useremail, %info (user signup information).');
// Load the default admin form data for new nodes.
- if (!$node || !$node->signup) {
+ if (!$node)
+ $node = new stdClass;
+ if (!$node->signup) {
$result = db_fetch_object(db_query("SELECT * FROM {signup} WHERE nid = 0"));
$node->signup_forwarding_email = $result->forwarding_email;
$node->signup_send_confirmation = $result->send_confirmation;
@@ -1710,6 +1773,8 @@
$node->signup_reminder_days_before = $result->reminder_days_before;
$node->signup_reminder_email = $result->reminder_email;
$node->signup_close_signup_limit = $result->close_signup_limit;
+ $type_access = variable_get('signup_access_' . $node->type, NULL);
+ $node->signup_access = (!is_null($type_access) ? $type_access : explode(',', $result->access));
}
$form['signup_forwarding_email'] = array(
@@ -1766,6 +1831,13 @@
'#size' => 4, '#maxlength' => 8,
'#description' => t('Maximum number of users who can sign up before signups are automatically closed. If set to 0, there is no limit.'),
);
+ $form['signup_access'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Access'),
+ '#default_value' => $node->signup_access,
+ '#options' => user_roles(),
+ '#description' => t('Only the checked roles will be allowed to signup for this node. If no roles are checked, access will not be restricted.'),
+ );
$form['signup'] = array('#type' => 'hidden', '#value' => 1);
return $form;