Index: modules/signup/signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.96
diff -u -p -r1.96 signup.module
--- modules/signup/signup.module 28 Mar 2007 20:14:09 -0000 1.96
+++ modules/signup/signup.module 28 Mar 2007 23:05:27 -0000
@@ -298,16 +298,13 @@ function signup_alter_node_form($form_id
$node = NULL;
}
- if (variable_get('signup_form_' . $form['type']['#value'], 0)) {
- $form['signup'] = array(
- '#type' => 'fieldset',
- '#title' => t('Signup settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['signup']['_signup_admin_form'] = _signup_admin_form($node);
- }
- else if (user_access('administer all signups')) {
+ $signup_enabled = variable_get('signup_form_' . $form['type']['#value'], 0);
+ $signup_admin = user_access('administer all signups');
+
+ // If the current user should be able to control signup settings
+ // (either because the node type is signup-enabled, or they're a
+ // signup administrator) add a fieldset for signup-related settings.
+ if ($signup_enabled || $signup_admin) {
$form['signup'] = array(
'#type' => 'fieldset',
'#title' => t('Signup settings'),
@@ -315,11 +312,43 @@ function signup_alter_node_form($form_id
'#collapsed' => TRUE,
'#weight' => 30,
);
- $form['signup']['signup_enable'] = array(
- '#type' => 'checkbox',
- '#default_value' => $node->signup,
- '#title' => t('Enable signups for this !node_type', array('!node_type' => node_get_types('name', $form['type']['#value']))),
+
+ // Figure out what the options should be. If there are already
+ // people signed-up for this node, we need a 3rd choice: disable
+ // signups and remove all signup data.
+ $has_signups = !empty($node) && db_result(db_query("SELECT COUNT(*) from {signup_log} WHERE nid = %d", $node->nid));
+ $radio_options[1] = t('Enabled');
+ if ($has_signups) {
+ $radio_options[0] = t('Disabled, but save existing signup information');
+ $radio_options[2] = t('Disabled, and remove all signup information') . ' ('. t('This can not be undone, use with extreme caution!') .')';
+ }
+ else {
+ $radio_options[0] = t('Disabled');
+ }
+
+ // Figure out what the default selection for signups should be.
+ if (isset($node->signup)) {
+ $default_option = $node->signup;
+ }
+ else {
+ $default_option = $signup_enabled;
+ }
+
+ // Add the form element to toggle if signups are allowed.
+ $form['signup']['signup_enabled'] = array(
+ '#type' => 'radios',
+ '#title' => t('Allow signups'),
+ '#default_value' => $default_option,
+ '#options' => $radio_options,
+ );
+
+ // Add the actual settings. We wrap this in a div to make it easy
+ // to use jQuery to hide these settings when signups are disabled.
+ $form['signup']['node_settings'] = array(
+ '#prefix' => '
',
+ '#suffix' => '
',
);
+ $form['signup']['node_settings']['settings'] = _signup_admin_form($node);
}
}
@@ -373,8 +402,7 @@ function signup_nodeapi(&$node, $op, $te
global $form_values;
switch ($op) {
case 'insert':
- // If it's a signup enabled node, then insert a new row for this node.
- if (variable_get('signup_form_' . $node->type, 0)) {
+ if ($form_values['signup_enabled'] == 1) {
db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email) VALUES (%d, '%s', %d, '%s', %d, %d, '%s')",
$node->nid, $form_values['signup_forwarding_email'],
$form_values['signup_send_confirmation'],
@@ -384,53 +412,45 @@ function signup_nodeapi(&$node, $op, $te
$form_values['signup_reminder_email']
);
}
- else if ($form_values['signup_enable']) {
- $defaults = db_fetch_array(db_query('SELECT * FROM {signup} WHERE nid = 0'));
- db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email) VALUES (%d, '%s', %d, '%s', %d, %d, '%s')",
- $node->nid, $defaults['forwarding_email'],
- $defaults['send_confirmation'],
- $defaults['confirmation_email'],
- $defaults['send_reminder'],
- $defaults['reminder_days_before'],
- $defaults['reminder_email']
- );
- }
break;
case 'update':
- // If this is a signup enabled node, then update the signup info
- // for the node.
- if (db_num_rows(db_query('SELECT * FROM {signup} WHERE nid = %d', $node->nid))) {
- db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', send_reminder = %d, reminder_days_before = %d, reminder_email = '%s' WHERE nid = %d",
- $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->nid
- );
- }
- else if ($form_values['signup_enable']) {
- $defaults = db_fetch_array(db_query('SELECT * FROM {signup} WHERE nid = 0'));
- db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email) VALUES (%d, '%s', %d, '%s', %d, %d, '%s')",
- $node->nid, $defaults['forwarding_email'],
- $defaults['send_confirmation'],
- $defaults['confirmation_email'],
- $defaults['send_reminder'],
- $defaults['reminder_days_before'],
- $defaults['reminder_email']
- );
- }
- else if (variable_get('signup_form_' . $node->type, 0)) {
- db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email) VALUES (%d, '%s', %d, '%s', %d, %d, '%s')",
- $node->nid, $form_values['forwarding_email'],
- $form_values['send_confirmation'],
- $form_values['confirmation_email'],
- $form_values['send_reminder'],
- $form_values['reminder_days_before'],
- $form_values['reminder_email']
- );
- }
+ $has_signup_record = db_result(db_query('SELECT COUNT(*) FROM {signup} WHERE nid = %d', $node->nid));
+ switch ($form_values['signup_enabled']) {
+ case 1: // Enabled
+ if ($has_signup_record) {
+ db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', send_reminder = %d, reminder_days_before = %d, reminder_email = '%s' WHERE nid = %d",
+ $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->nid
+ );
+ }
+ else {
+ db_query("INSERT INTO {signup} (nid, forwarding_email, send_confirmation, confirmation_email, send_reminder, reminder_days_before, reminder_email) VALUES (%d, '%s', %d, '%s', %d, %d, '%s')", $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
+ );
+ }
+ break;
+
+ case 2: // Disabled, and delete {signup_log}, too
+ db_query("DELETE FROM {signup_log} WHERE nid = %d", $node->nid);
+ // No break, fall through and remove from {signup} too.
+
+ case 0: // Disabled, but leave {signup_log} alone
+ if ($has_signup_record) {
+ db_query("DELETE FROM {signup} WHERE nid = %d", $node->nid);
+ }
+ break;
+
+ } // switch ($form_values['signup_enabled'])
break;
case 'delete':
@@ -457,6 +477,9 @@ function signup_nodeapi(&$node, $op, $te
$node->signup_reminder_email = $signup->reminder_email;
$node->signup_completed = $signup->completed;
}
+ else {
+ $node->signup = 0;
+ }
break;
case 'view':
@@ -1173,7 +1196,7 @@ function signup_validate_anon_email($nid
function _signup_admin_form($node) {
// Load the default admin form data for new nodes.
- if(!$node) {
+ if(!$node || !$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;