Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.113
diff -u -p -r1.113 signup.module
--- signup.module	31 Jul 2007 00:08:30 -0000	1.113
+++ signup.module	31 Jul 2007 21:51:52 -0000
@@ -90,7 +90,7 @@ function signup_cron() {
   $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.
@@ -108,6 +108,7 @@ function signup_cron() {
         '%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);
@@ -211,7 +212,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(
@@ -622,7 +662,7 @@ function signup_nodeapi(&$node, $op, $te
             $output = '<h3>'. t('Signups closed for this event') .'</h3>';
             // If they're already signed up, show their current signup
             // info and give them the option to cancel.
-            $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
+            $result = db_query("SELECT s_l.signup_time, s_l.form_data, s_s.state_name FROM {signup_log} s_l INNER JOIN {signup_states} s_s ON s_s.ssid = s_l.ssid WHERE s_l.uid = %d AND s_l.nid = %d", $user->uid, $node->nid);
             if (db_num_rows($result)) {
               $signup_info = db_fetch_object($result);
               $output .= _signup_print_current_signup($node, $signup_info);
@@ -1784,3 +1824,137 @@ 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'), array('data' => t('Operations'), 'colspan' => 2));
+  foreach (signup_state_load() as $ssid => $name) {
+    $rows[] = array(check_plain($name),
+      l(t('edit'), 'admin/settings/signup/state_edit/'. $ssid),
+      l(t('delete'), 'admin/settings/signup/state_delete/'. $ssid));
+  }
+
+  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 names.
+ *   If a $ssid is passed, we'll the name.
+ */
+function signup_state_load($ssid = NULL) {
+  static $states_lookup = array();
+
+  if (!$states_lookup) {
+    $results = db_query("SELECT ssid, state_name FROM {signup_states}");
+    while ($result = db_fetch_object($results)) {
+      $states_lookup[$result->ssid] = $result->state_name;
+    }
+  }
+
+  if ($ssid) {
+    return $states_lookup[$ssid];
+  }
+  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' WHERE ssid = %d", $signup_state['name'], $signup_state['ssid'])
+    : db_query("INSERT INTO {signup_states} (state_name) VALUES ('%s')", $signup_state['name']);
+}
+
+/**
+ * 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;
+
+  $form = array();
+  $form['name'] = array(
+    '#type'              => 'textfield',
+    '#title'             => t('State name'),
+    '#required'          => TRUE,
+    '#default_value'     => isset($signup_state) ? $signup_state : NULL,
+    '#description'       => t('The name for this signup state. Example: "maybe attending".'),
+  );
+
+  if ($signup_state) {
+    $form['ssid'] = array('#type' => 'hidden', '#default_value' => $ssid);
+  }
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+
+  return $form;
+}
+
+/**
+ * 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_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);
+  return confirm_form($form,
+                      t('Are you sure you want to delete the signup state %name?', array('%name' => $signup_state)),
+                      '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';
+}
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	31 Jul 2007 21:51:53 -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,6 +35,7 @@ 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,
@@ -44,7 +45,15 @@ function signup_install() {
 
       $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,
+        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;
@@ -245,6 +254,30 @@ 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");
+      break;
+
+    case 'pgsql':// TODO
+      break;
+  }
+  return $ret;
+}
+
 function _signup_db_column_exists($table, $column) {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
