? .svn
? TODO.txt
? signup.patch
? signup_event_5.x-2.inc
? contrib/.svn
? contrib/signup_conflicts/.svn
? po/.svn
? po/da.po
? po/es.po
? po/general.pot
? po/signup-module.pot
? po/signup_signup_conflicts-module.pot
Index: signup.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.install,v
retrieving revision 1.12
diff -u -p -r1.12 signup.install
--- signup.install	21 Apr 2007 01:31:37 -0000	1.12
+++ signup.install	15 Aug 2007 00:47:03 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: signup.install,v 1.12 2007/04/21 01:31:37 dww Exp $
+// $Id: signup.install,v 1.6.2.3 2007/03/20 07:27:21 dww Exp $
 
 /**
  * Implementation of hook_install()
@@ -35,16 +35,27 @@ function signup_install() {
       $q2 = db_query("CREATE TABLE IF NOT EXISTS {signup_log} (
                 uid int(10) unsigned NOT NULL default '0',
                 nid int(10) unsigned NOT NULL default '0',
+                ssid int unsigned NOT NULL default '0',
                 anon_mail varchar(255) NOT NULL default '',
                 signup_time int(10) unsigned NOT NULL default '0',
                 form_data longtext NOT NULL,
                 KEY uid (uid),
-                KEY nid (nid)
+                KEY nid (nid),
+                KEY ssid (ssid)
             ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
 
       $q3 = signup_insert_default_signup_info();
 
-      if ($q1 && $q2 && $q3) {
+      $q4 = db_query("CREATE TABLE {signup_states} (
+        ssid int NOT NULL auto_increment,
+        state_name varchar(255) NOT NULL,
+        level int unsigned NOT NULL default '0',
+        PRIMARY KEY (ssid)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+
+      $q5 = db_query("INSERT INTO {signup_states} (state_name) VALUES ('Attending')");
+
+      if ($q1 && $q2 && $q3 && $q4 && $q5) {
         $created = TRUE;
       }
       break;
@@ -67,6 +78,7 @@ function signup_install() {
       $q2 = db_query("CREATE TABLE {signup_log} (
                 uid integer NOT NULL default '0',
                 nid integer NOT NULL default '0',
+                ssid integer NOT NULL default '0',
                 anon_mail text NOT NULL default '',
                 signup_time integer NOT NULL default '0',
                 form_data text NOT NULL default ''
@@ -76,9 +88,11 @@ function signup_install() {
 
       $q4 = db_query("CREATE INDEX {signup_log}_nid_idx ON {signup_log}(nid);");
 
-      $q5 = signup_insert_default_signup_info();
+      $q5 = db_query("CREATE INDEX {signup_log}_ssid_idx ON {signup_log}(ssid);");
 
-      if ($q1 && $q2 && $q3 && $q4 && $q5) {
+      $q6 = signup_insert_default_signup_info();
+
+      if ($q1 && $q2 && $q3 && $q4 && $q5 && $q6) {
         $created = TRUE;
       }
       break;
@@ -245,6 +259,47 @@ function signup_update_5201() {
   return $ret;
 }
 
+/**
+ * Add signup_state table
+ */
+function signup_update_5202() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {signup_states} (
+        ssid int NOT NULL auto_increment,
+        state_name varchar(255) NOT NULL,
+        PRIMARY KEY (ssid)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+
+      $ret[] = update_sql("INSERT INTO {signup_states} (state_name) VALUES ('Attending')");
+      $ret[] = update_sql("ALTER TABLE {signup_log} ADD ssid int NOT NULL default 1");
+      $ret[] = update_sql("ALTER TABLE {signup_log} ADD KEY ssid (ssid)");
+      break;
+
+    case 'pgsql':// TODO
+      break;
+  }
+  return $ret;
+}
+
+/**
+ * Add level to signup_states table
+ */
+function signup_update_5203() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {signup_states} ADD level int NOT NULL default 1");
+      break;
+    case 'pgsql':// TODO
+      break;
+  }
+  return $ret;
+}
+
 function _signup_db_column_exists($table, $column) {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.115
diff -u -p -r1.115 signup.module
--- signup.module	14 Aug 2007 07:17:54 -0000	1.115
+++ signup.module	15 Aug 2007 00:47:04 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: signup.module,v 1.115 2007/08/14 07:17:54 dww Exp $
+// $Id: signup.module,v 1.114 2007/08/01 02:08:54 dww Exp $
 
 /**
  * @defgroup signup_core Core drupal hooks
@@ -101,7 +101,7 @@ function _signup_cron_send_reminders() {
   $from = variable_get('site_mail', 'noadmin@noadmin.com');
   while ($event = db_fetch_object($result)) {
     $subject = t('Event reminder: !event', array('!event' => $event->title));
-    $signups = db_query("SELECT u.name, u.mail, s_l.anon_mail, s_l.form_data FROM {signup_log} s_l INNER JOIN {users} u ON u.uid = s_l.uid WHERE s_l.nid = %d", $event->nid);
+    $signups = db_query("SELECT u.name, u.mail, s_l.anon_mail, s_l.form_data, s.ssid, s_s.state_name FROM {signup_log} s_l INNER JOIN {users} u ON u.uid = s_l.uid INNER JOIN {signup_states} s_s ON s.ssid = s_s.ssid WHERE s_l.nid = %d", $event->nid);
 
     // Loop through the users, composing their customized message
     // and sending the email.
@@ -119,6 +119,7 @@ function _signup_cron_send_reminders() {
         '%username' => $signup->name,
         '%useremail' => $mail_address,
         '%info' => $signup_info,
+        '%state' => $signup->state_name,
         );
       $message = strtr($event->reminder_email, $trans);
       drupal_mail('signup_reminder_mail', $mail_address, $subject, $message, $from);
@@ -269,7 +270,46 @@ function signup_menu($may_cache) {
       'access' => $access,
       'callback' => 'drupal_get_form',
       'callback arguments' => array('signup_settings_page'),
-      'title' => user_access('access administration pages') ? t('Signup') : t('Signup settings'),
+    );
+    $items[] = array(
+      'access'             => $access,
+      'path'               => 'admin/settings/signup/settings',
+      'type'               => MENU_DEFAULT_LOCAL_TASK,
+      'title'              => t('Signup settings'),
+      'weight'             => -10,
+    );
+    $items[] = array(
+      'access'             => $access,
+      'callback'           => 'signup_state_overview',
+      'description'        => t('Create, edit, and delete signup states.'),
+      'path'               => 'admin/settings/signup/states',
+      'title'              => t('Signup states'),
+      'type'               => MENU_LOCAL_TASK,
+    );
+    $items[] = array(
+      'access'             => $access,
+      'callback'           => 'drupal_get_form',
+      'callback arguments' => array('signup_state_edit'),
+      'path'               => 'admin/settings/signup/state_add',
+      'title'              => t('Add signup state'),
+      'type'               => MENU_LOCAL_TASK,
+      'weight'             => 10,
+    );
+    $items[] = array(
+      'access'             => $access,
+      'callback'           => 'drupal_get_form',
+      'callback arguments' => array('signup_state_edit'),
+      'path'               => 'admin/settings/signup/state_edit',
+      'title'              => t('Edit signup state'),
+      'type'               => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'access'             => $access,
+      'callback'           => 'drupal_get_form',
+      'callback arguments' => array('signup_state_confirm_delete'),
+      'path'               => 'admin/settings/signup/state_delete',
+      'title'              => t('Delete signup state'),
+      'type'               => MENU_CALLBACK,
     );
 
     $items[] = array(
@@ -702,8 +742,9 @@ function signup_nodeapi(&$node, $op, $te
               '!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')) {
-              $needs_signup_form = TRUE;
+              $needs_signup_form = 1;
               $anon_signup_form['signup_anon_mail'] = array(
                 '#type' => 'textfield',
                 '#title' => t('Email'),
@@ -723,16 +764,27 @@ function signup_nodeapi(&$node, $op, $te
           }
           else {
             // See if the user is already signed up for this node.
-            $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
-            $needs_signup_form = db_num_rows($result) == 0;
-          }
-
-          if ($needs_signup_form) {
+            $result = db_query("SELECT sl.signup_time, sl.form_data, ss.level, ss.state_name FROM {signup_log} sl INNER JOIN {signup_states} ss ON sl.ssid = ss.ssid WHERE sl.uid = %d AND sl.nid = %d", $user->uid, $node->nid);
+            if(db_num_rows($result)!=0){
+              $needs_signup_form = 2;
+              $signup_info = db_fetch_object($result);
+            }
+            else {
+              $needs_signup_form = 1;
+            };
+          };
+          if (isset($needs_signup_form) && ($needs_signup_form!= 2)) {
             // 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')) {
               $output = drupal_get_form('signup_form', $node, $anon_signup_form);
+            };
+          }
+          elseif ($needs_signup_form == 2) {
+            if (user_access('sign up for content')) {
+              $output = drupal_get_form('signup_form', $node, $anon_signup_form, $signup_info);
             }
+            $output .= _signup_print_current_signup($node, $signup_info);
           }
           else {
             // The user is already signed up, so print a table of their
@@ -741,7 +793,6 @@ function signup_nodeapi(&$node, $op, $te
             $output .= _signup_print_current_signup($node, $signup_info);
           }
         }
-
         // If the user has the view signups perm, display the current signups.
         // Pull all users signed up for this event, and start table creation.
         if (user_access('view all signups')) {
@@ -771,8 +822,10 @@ function signup_nodeapi(&$node, $op, $te
 
 function _signup_print_current_signup($node, $signup_info) {
   $form_data = unserialize($signup_info->form_data);
+
   $header = array(array('data' => t('Your signup information'), 'colspan' => 2));
   $rows = array();
+  $form_data['Status']= $signup_info->state_name;
   if (is_array($form_data)) {
     $rows += signup_build_signup_data($form_data, 'table');
   }
@@ -793,31 +846,80 @@ function _signup_print_current_signup($n
  * Builder function for the signup form
  * @ingroup signup_callback
  */
-function signup_form($node, $anon_signup_form = NULL) {
+function signup_form($node, $anon_signup_form = NULL, $signup_info = FALSE) {
   global $user;
-  include(SIGNUP_PATH .'/signup.theme');
+  include_once(SIGNUP_PATH .'/signup.theme');
 
   $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
   $form['uid'] = array('#type' => 'value', '#value' => $user->uid);
 
-  $form['collapse'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Sign up for @title', array('@title' => $node->title)),
-    '#collapsible' => TRUE,
-    '#collapsed' => variable_get('signup_fieldset_collapsed', 1),
-  );
-
   // Build the themed signup form.  If the anon signup form is
   // present, merge it in at the end of the form.
   $signup_themed_form = theme('signup_user_form');
+
+  if($signup_info){
+    $form['collapse'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Update sign up info for @title', array('@title' => $node->title)),
+      '#collapsible' => TRUE,
+      '#collapsed' => variable_get('signup_fieldset_collapsed', 1),
+      );
+    $update_form_data = unserialize($signup_info->form_data);
+    $signup_themed_form['signup_form_data']['Name']['#default_value'] = $update_form_data['Name'];
+    $signup_themed_form['signup_form_data']['Phone']['#default_value'] = $update_form_data['Phone'];
+    $button_text = t('Update');
+  }
+  else {
+    $form['collapse'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Sign up for @title', array('@title' => $node->title)),
+      '#collapsible' => TRUE,
+      '#collapsed' => variable_get('signup_fieldset_collapsed', 1),
+      );
+    $button_text = t('Sign up');
+  }
+  // Merge in the form the choice of commitment.
+  $signup_themed_form = array_merge($signup_themed_form, signup_choice_form($signup_info));
   if (isset($anon_signup_form)) {
     $signup_themed_form = array_merge($signup_themed_form, $anon_signup_form);
   }
   $form['collapse']['signup_user_form'] = $signup_themed_form;
   $form['collapse']['submit'] = array(
     '#type' => 'submit',
-    '#value' => t('Sign up'),
+    '#value' => $button_text,
   );
+
+  return $form;
+}
+
+/**
+ * 
+ */
+function signup_choice_form($info) {
+  $states = signup_state_load_by_level();
+
+  if(count($states) == 1){
+  foreach ($states as $key => $state) {
+    
+  
+  $form['level'] = array(
+    '#title' => '',
+    '#type' => 'hidden',
+    '#value' => $key,
+    );
+  }
+  } else {
+  foreach ($states as $key => $state) {
+    $options[$key] = $state['state_name'];
+  }
+  
+  $form['level'] = array(
+    '#title' => '',
+    '#type' => 'radios',
+    '#options' => $options,
+    '#default_value' => (isset($info->level)&& !empty($info->level)) ? $info->level : min(array_flip($options)),
+    );
+  }
   return $form;
 }
 
@@ -1223,31 +1325,13 @@ function signup_list_user_signups($uid) 
 function signup_sign_up_user($signup_form) {
   $node = node_load($signup_form['nid']);
 
+
   // Since this is an API call, we need to validate that there are no
   // duplicate signups being generated, even though through the usual
   // UI, there's no way to reach this function if it's a duplicate.
   // How to find duplicates is different for anonymous and
   // authenticated signups.
-  if (!empty($signup_form['signup_anon_mail'])) {
-    // Ensure the uid is 0 for anonymous signups, even if it's not duplicate.
-    $signup_form['uid'] = 0;  
-    // Now, see if this email is already signed-up.
-    if (db_num_rows(db_query("SELECT anon_mail FROM {signup_log} WHERE anon_mail = '%s' AND nid = %d", $signup_form['signup_anon_mail'], $node->nid))) {
-      drupal_set_message(t('Anonymous user %email is already signed up for %title', array('%email' => $signup_form['signup_anon_mail'], '%title' => $node->title), 'error'));
-      return FALSE;
-    }
-  }
-  else {
-    // This query does the JOIN on {users} so we can avoid a full
-    // user_load() just so theme('username') can have the data it
-    // needs for the error message we might print out.
-    $query = db_query("SELECT sl.uid, u.name FROM {signup_log} sl INNER JOIN {users} u ON sl.uid = u.uid WHERE sl.uid = %d AND sl.nid = %d", $signup_form['uid'], $signup_form['nid']);
-    if (db_num_rows($query)) {
-      $user = db_fetch_object($query);
-      drupal_set_message(t('User !user is already signed up for %title', array('!user' => theme('username', $user), '%title' => $node->title)), 'error');
-      return FALSE;
-    }
-  }
+  
 
   // If we made it this far, we're going to need the full $user object.
   $user = user_load(array('uid' => $signup_form['uid']));
@@ -1265,8 +1349,38 @@ function signup_sign_up_user($signup_for
     $confirmation_email = $node->signup_send_confirmation ? '  '. t('You will receive a confirmation email shortly which contains further event information.') : '';
     $reminder_email = $node->signup_send_reminder ? '  '. t('You will receive a reminder email !number !days before the event.', array('!number' => $node->signup_reminder_days_before, '!days' => format_plural($node->signup_reminder_days_before, 'day', 'days'))) : '';
 
-    // Insert the user into the signup_log.
-    db_query("INSERT INTO {signup_log} (uid, nid, anon_mail, signup_time, form_data) VALUES (%d, %d, '%s', %d, '%s')", $signup_form['uid'], $signup_form['nid'], $signup_form['signup_anon_mail'], $curtime, $signup_form_data);
+    $states = signup_state_load_by_level($signup_form['level']);
+
+    if (!empty($signup_form['signup_anon_mail'])) {
+      // Ensure the uid is 0 for anonymous signups, even if it's not duplicate.
+      $signup_form['uid'] = 0;  
+      // Now, see if this email is already signed-up.
+      if (db_num_rows(db_query("SELECT anon_mail FROM {signup_log} WHERE anon_mail = '%s' AND nid = %d", $signup_form['signup_anon_mail'], $node->nid))) {
+        drupal_set_message(t('Anonymous user %email is already signed up for %title', array('%email' => $signup_form['signup_anon_mail'], '%title' => $node->title), 'error'));
+        return FALSE;
+      }
+      else {
+        db_query("INSERT INTO {signup_log} (uid, nid, ssid, anon_mail, signup_time, form_data) VALUES (%d, %d, %d, '%s', %d, '%s')", $signup_form['uid'], $signup_form['nid'], $states['ssid'], $signup_form['signup_anon_mail'], $curtime, $signup_form_data);
+        $update ="confirmed.";
+      }
+    }
+    else {
+      // This query does the JOIN on {users} so we can avoid a full
+      // user_load() just so theme('username') can have the data it
+      // needs for the error message we might print out.
+      // TODO: How do we determine that a user is signed up?
+      $query = db_query("SELECT sl.uid, u.name FROM {signup_log} sl INNER JOIN {users} u ON sl.uid = u.uid INNER JOIN {signup_states} ss ON ss.ssid = sl.ssid WHERE sl.uid = %d AND sl.nid = %d", $signup_form['uid'], $signup_form['nid']);
+      if (db_num_rows($query)) {
+        db_query("UPDATE {signup_log}  set nid = %d, ssid= %d, anon_mail = '%s', signup_time= %d, form_data = '%s' where uid = %d",  $signup_form['nid'], $states['ssid'], $signup_form['signup_anon_mail'], $curtime, $signup_form_data, $signup_form['uid']);
+        $update ="updated.";
+      }
+      else {
+        db_query("INSERT INTO {signup_log} (uid, nid, ssid, anon_mail, signup_time, form_data) VALUES (%d, %d, %d, '%s', %d, '%s')", $signup_form['uid'], $signup_form['nid'], $states['ssid'], $signup_form['signup_anon_mail'], $curtime, $signup_form_data);
+        $update ="confirmed.";
+      }
+    }
+    //die();
+    //    db_query("INSERT INTO {signup_log} (uid, nid, ssid, anon_mail, signup_time, form_data) VALUES (%d, %d, %d, '%s', %d, '%s')", $signup_form['uid'], $signup_form['nid'], $states['ssid'], $signup_form['signup_anon_mail'], $curtime, $signup_form_data);
 
     // Format the start time, and compose the user's signup data for
     // later use in the emails.
@@ -1287,7 +1401,8 @@ function signup_sign_up_user($signup_for
       "%time" => $starttime,
       "%username" => $user->name,
       "%useremail" => $user_mail,
-      "%info" => $signup_data
+      "%info" => $signup_data,
+      "%state" => $states[$form_values['ssid']]['state_name'],
     );
     $from = variable_get('site_mail', 'noadmin@noadmin.com');
 
@@ -1311,7 +1426,7 @@ function signup_sign_up_user($signup_for
       drupal_mail('signup_forwarding_mail', $node->signup_forwarding_email, $subject, $message, $from, $header);
     }
 
-    drupal_set_message(t('Signup to !title confirmed.', array('!title' => l($node->title, "node/$node->nid"))) . $confirmation_email . $reminder_email);
+    drupal_set_message(t('Signup to !title '.$update, array('!title' => l($node->title, "node/$node->nid")), $update) . $confirmation_email . $reminder_email);
 
     $node->signup_total++;
     if ($node->signup_close_signup_limit) {
@@ -1616,7 +1731,7 @@ function signup_validate_anon_email($nid
  * @ingroup signup_internal
  */
 function _signup_admin_form($node) {
-  $signup_token_description = t('Supported string substitutions: %event, %time, %username, %useremail, %info (user signup information).');
+  $signup_token_description = t('Supported string substitutions: %event, %time, %username, %useremail, %info (user signup information), %state (user chosen status of the subcription).');
 
   // Load the default admin form data for new nodes.
   if (!$node || !$node->signup) {
@@ -1853,3 +1968,193 @@ function signup_broadcast_form_submit($f
   }
   drupal_set_message(t('Message sent to all users who have signed up'));
 }
+
+/**
+ * Displays an administrative overview of all signup states available.
+ */
+function signup_state_overview() {
+  $rows = array();
+  $headers = array(t('Name'), t('Level'), array('data' => t('Operations'), 'colspan' => 2));
+  foreach (signup_state_load() as $ssid => $signup_state) {
+    $rows[$signup_state['level']] = array(
+      check_plain($signup_state['state_name']),
+      $signup_state['level'],
+      l(t('edit'), 'admin/settings/signup/state_edit/'. $ssid),
+      l(t('delete'), 'admin/settings/signup/state_delete/'. $ssid));
+  }
+  krsort($rows);
+  return theme('table', $headers, $rows);
+}
+
+/**
+ * Deletes a signup state.
+ *
+ * @todo There is currently no attempt to do anything with signups
+ * which have been assigned the $ssid that is about to be deleted. We
+ * should reset them to the default per our settings (and warn the
+ * user on our confirmation page), or something else entirely.
+ * 
+ * @param $ssid
+ *   The signup state ID to delete.
+ */
+function signup_state_delete($ssid = NULL) {
+  db_query('DELETE FROM {signup_states} WHERE ssid = %d', $ssid);
+}
+
+/**
+ * Returns information about the various signup states and their options.
+ * The number of parameters passed will determine the return value.
+ *
+ * @param $ssid
+ *   Optional; the state ID to return.
+ * @return $values
+ *   If $ssid is NULL, you'll receive an array with the keys
+ *   being the state ID and the values being their properties.
+ *   If a $ssid is passed, we'll return the properties of 
+ *   a single state.
+ */
+function signup_state_load($ssid = NULL) {
+  static $states_lookup = array();
+
+  if (!$states_lookup) {
+    $results = db_query("SELECT ssid, state_name, level FROM {signup_states}");
+    while ($result = db_fetch_array($results)) {
+      $states_lookup[$result['ssid']] = $result;
+    }
+  }
+
+  if ($ssid) {
+    return $states_lookup[$ssid];
+  }
+  else {
+    return $states_lookup;
+  }
+}
+
+
+/**
+ * Returns information about the various signup states and their options.
+ * The number of parameters passed will determine the return value.
+ *
+ * @param $level
+ *   Optional; the level to return.
+ * @return $values
+ *   If $level is NULL, you'll receive an array with the keys
+ *   being the levels and the values being their names.
+ *   If a $level is passed, we'll return the name.
+ */
+function signup_state_load_by_level($level = NULL) {
+  static $states_lookup = array();
+
+  if (!$states_lookup) {
+    $results = db_query("SELECT ssid, state_name, level FROM {signup_states}");
+    while ($result = db_fetch_array($results)) {
+      $states_lookup[$result['level']] = $result;
+    }
+  }
+
+  if ($level) {
+    return $states_lookup[$level];
+  }
+  else {
+    return $states_lookup;
+  }
+}
+
+/**
+ * Saves a signup state.
+ *
+ * @param $signup_state
+ *   An array containing 'name'. If no 'ssid'
+ *   is passed, a new state is created, otherwise, we'll update
+ *   the record that corresponds to that ID.
+ */
+function signup_state_save($signup_state = NULL) {
+  $result = isset($signup_state['ssid']) // @todo we should probably do some error checking on the result and return it.
+    ? db_query("UPDATE {signup_states} SET state_name = '%s', level = %d WHERE ssid = %d", $signup_state['name'], $signup_state['level'], $signup_state['ssid'])
+  : db_query("INSERT INTO {signup_states} (state_name, level) VALUES ('%s', %d)", $signup_state['name'], $signup_state['level']);
+}
+
+/**
+ * Displays a form for adding or editing a signup state.
+ */
+function signup_state_edit($ssid = NULL) {
+  $signup_state = isset($ssid) ? signup_state_load($ssid) : NULL;
+
+  $options = drupal_map_assoc(range(1, 10));
+  $result = db_query('SELECT level FROM {signup_states} WHERE ssid != %d', (int) $ssid);
+  while ($id = db_fetch_object($result)) {
+    unset($options[$id->level]);
+  }
+
+  $form = array();
+  $form['name'] = array(
+    '#type'              => 'textfield',
+    '#title'             => t('State name'),
+    '#required'          => TRUE,
+    '#default_value'     => isset($signup_state) ? $signup_state['state_name'] : NULL,
+    '#description'       => t('The name for this signup state. Example: "maybe attending".'),
+  );
+  $form['level'] = array(
+    '#type'              => 'select',
+    '#title'             => t('Confidence level'),
+    '#options'           => $options,
+    '#default_value'     => isset($signup_state) ? $signup_state['level'] : 0,
+    '#description'       => t("Rank you signup states by the confidence they represent that the user will actually come to the event. Example: 'will not attend' should be 0, 'will definitly attend' 10 and 'I want to come but I am not sure if I get off at the job' could be 7. Shown are the available levels."),
+  );
+
+  if ($signup_state) {
+    $form['ssid'] = array('#type' => 'hidden', '#default_value' => $ssid);
+  }
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+
+  return $form;
+}
+
+/**
+ * Validate the submitted results of our case state addition or editing.
+ */
+function signup_state_edit_validate($form_id, $form_values) {
+  if (db_result(db_query('SELECT ssid FROM {signup_states} WHERE level = %d AND ssid != %d', $form_values['level'], (int) $form_values['ssid']))) {
+    form_set_error('level', t('This level is already taken.'));
+  }
+}
+
+/**
+ * Processes the submitted results of our case state addition or editing.
+ */
+function signup_state_edit_submit($form_id, $form_values) {
+  $signup_state = array('name' => $form_values['name']);
+  if ($form_values['ssid']) {
+    drupal_set_message(t('The signup state %name has been updated.', array('%name' =>  $form_values['name'])));
+    $signup_state['ssid'] = $form_values['ssid'];
+  }
+  else {
+    drupal_set_message(t('The signup state %name has been created.', array('%name' =>  $form_values['name'])));
+    $signup_state['ssid'] = NULL;
+  }
+  $signup_state['level'] = $form_values['level'];
+  signup_state_save($signup_state);
+  return 'admin/settings/signup/states';
+}
+
+/**
+ * If the user has asked to delete a case state, we'll double-check.
+ */
+function signup_state_confirm_delete($ssid = NULL) {
+  $signup_state = signup_state_load($ssid);
+  $form['ssid'] = array('#type' => 'hidden', '#default_value' => $ssid);
+  $form['name'] = array('#type' => 'hidden', '#default_value' => $signup_state['state_name']);
+  return confirm_form($form,
+                      t('Are you sure you want to delete the signup state %name?', array('%name' => $signup_state['state_name'])),
+                      'admin/settings/signup/states', t('This action can not be undone.'), t('Delete'), t('Cancel'));
+}
+
+/**
+ * The user definitely wants to delete this case state.
+ */
+function signup_state_confirm_delete_submit($form_id, $form_values) {
+  drupal_set_message(t('Deleted signup state %name.', array('%name' =>  $form_values['name'])));
+  signup_state_delete($form_values['ssid']);
+  return 'admin/settings/signup/states';
+}
