--- sites/all/modules/signup_status/signup_status.module 2009-05-11 10:30:00.000000000 -0400 +++ sites/all/modules/signup_status/signup_status.module-NEW 2009-07-02 18:50:59.000000000 -0400 @@ -109,9 +109,7 @@ function signup_status_alter_action(&$si function signup_status_alter_action_form($context) { $options = array(); foreach (signup_status_codes() as $cid => $code) { - if ($code['show_on_form']) { - $options[$cid] = $code['name']; - } + $options[$cid] = $code['name']; } $form['signup_status'] = array( '#type' => 'select', @@ -177,8 +175,14 @@ function _signup_status_status_form_elem '#weight' => 1, '#required' => TRUE, ); + + // Current status if (isset($current_status)) { $element['#default_value'] = $current_status; + + // Default status + } else { + $element['#default_value'] = default_status(); } } return $element; @@ -189,11 +193,14 @@ function _signup_status_status_form_elem */ function signup_status_form_signup_form_alter(&$form, $form_state) { $status_element = _signup_status_status_form_element(); + + $form['collapse']['signup_status'] = $status_element; + $form['collapse']['submit']['#weight'] = 2; + $form['#submit'][] = 'signup_status_alter_signup_form_submit'; + + // Only validate if the form was submitted with the status value if (!empty($status_element)) { - $form['collapse']['signup_status'] = $status_element; - $form['collapse']['submit']['#weight'] = 2; $form['#validate'][] = 'signup_status_signup_form_validate_status'; - $form['#submit'][] = 'signup_status_alter_signup_form_submit'; } } @@ -210,8 +217,18 @@ function signup_status_signup_form_valid * Handles submission of the altered signup form. */ function signup_status_alter_signup_form_submit($form, &$form_state) { + + // Determine the status. If nothing is in the form, then use the default. $values = $form_state['values']; - if (isset($values['signup_status'])) { + + if (isset($values['signup_status'])) { + $signup_status = $values['signup_status']; + } + else { + $signup_status = default_status(); + } + + if ((int) $signup_status > 0) { $sql = "SELECT * FROM {signup_log} WHERE uid = %d AND nid = %d"; $args = array($values['uid'], $values['nid']); if (isset($values['signup_anon_mail'])) { @@ -219,11 +236,18 @@ function signup_status_alter_signup_form $args[] = $values['signup_anon_mail']; } if ($signup = db_fetch_object(db_query($sql, $args))) { - $signup->status = $values['signup_status']; + + if (!isset($values['signup_status'])) { + $signup->status = default_status(); + + } else { + $signup->status = $values['signup_status']; + } + db_query("UPDATE {signup_log} SET status = %d WHERE sid = %d", $signup->status, $signup->sid); _signup_status_change('add', $signup); } - } + } } /** @@ -363,3 +387,16 @@ function _signup_status_change($action, module_invoke_all('signup_status', $action, $signup); } +/** + * Retrieve the default status + */ +function default_status() { + $result = db_query("SELECT cid FROM {signup_status_codes} WHERE default_status = 1"); + $row = db_fetch_array($result); + + if (!$result) { + watchdog('signup_status', 'No default status could be selected.'); + } + + return $row['cid']; +}