--- signup.module.bak	2006-02-02 17:06:24.000000000 -0800
+++ signup.module	2006-02-04 08:45:45.311413464 -0800
@@ -329,97 +329,83 @@
 
       //load signup data for both new nodes w/ enabled node types, and any existing nodes that are already signup enabled
       if ((!$node->nid && variable_get('signup_form_' . $node->type, 0)) || ($node->nid && db_num_rows($result))) {                     $signup = db_fetch_object($result);
-        $node->signup = 1;
-        $node->signup_forwarding_email = $signup->forwarding_email;
-        $node->signup_send_confirmation = $signup->send_confirmation;
-        $node->signup_confirmation_email = $signup->confirmation_email;
-        $node->signup_send_reminder  = $signup->send_reminder ;
-        $node->signup_reminder_days_before = $signup->reminder_days_before;
-        $node->signup_reminder_email = $signup->reminder_email;
-        $node->signup_completed = $signup->completed;
+        $extra['signup']->enabled = 1;
+        $extra['signup']->forwarding_email = $signup->forwarding_email;
+        $extra['signup']->send_confirmation = $signup->send_confirmation;
+        $extra['signup']->confirmation_email = $signup->confirmation_email;
+        $extra['signup']->send_reminder  = $signup->send_reminder ;
+        $extra['signup']->reminder_days_before = $signup->reminder_days_before;
+        $extra['signup']->reminder_email = $signup->reminder_email;
+        $extra['signup']->completed = $signup->completed;
+      }
+      //if user has signup perm, and signup_user_view is enabled, then display the current signups
+      if (user_access('allow signups') && variable_get('signup_user_view', 0)) {
+        $extra['signup']->display_signups = 1;
+      }
+      // can this user sign up?
+      if (user_access('allow signups')) {
+        $extra['signup']->allowed = 1;
+      }
+      // is the user already signed up?
+      global $user;
+      $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid =%d", $user->uid, $node->nid);
+      if (db_num_rows($result)) {
+        $extra['signup']->signed_up = 1;
       }
 
-      break;
+      return $extra;
     case 'view':
 
       $suppress = module_invoke_all('signup_suppress', $node);
-
       //if this is a signup node, start checks for what's to be printed
-      if ($node->signup && !isset($node->preview) && !in_array(TRUE, $suppress)) {
+      if ($node->signup && !isset($node->preview) && !in_array(TRUE, $suppress) && $node->signup->allowed) {
         global $user;
-
-        //the node has been closed for signups, and the user has signup permissions.  let them know it's closed
-        if ($node->signup_completed) {
-          if (user_access('allow signups')) {
-            $output = '<h3>' . t('Signups closed for this event') . '</h3>';
-          }
-        } else {
-
-          //this is an anonymous user. if they have signup permissions, then display a login link
-          if ($user->uid == 0) {
-            $node->body .= user_access('allow signups') ? '<div class="signup_anonymous">'. t('<p>Please %login to sign up for this event.</p>',
-            array("%login"=> l(t('login/register'), 'user/login', array(), drupal_get_destination()))) .'</div>' : '';
-            break;
-          }
-
-          //check here to 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);
-          $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
-          $form['uid'] = array('#type' => 'hidden', '#value' => $user->uid);
-          $form['#action'] = url('signup', drupal_get_destination());
-
-          if(db_num_rows($result) == 0) {
-
-            //user isn't signed up, so check to make sure they have signup
-            //permissions.  if this is the case, then print the themed signup form
-            if (user_access('allow signups')) {
-              $form['collapse'] = array('#type' => 'fieldset', '#title' => t('Sign up for %title', array('%title' => check_plain($node->title))), '#collapsible' => TRUE, '#collapsed' => TRUE);
-
-              $form['collapse']['signup_user_form'] = signup_user_form();
-              $form['collapse']['submit'] = array('#type' => 'submit', '#value' => t('Sign up'));
-              $output = drupal_get_form('signup_form_view', $form);
-            }
-
-          //the user is already signed up, so print a table of their signup data, and give them the option to cancel
-          } else {
-            $result = db_fetch_object($result);
-            $form_data = unserialize($result->form_data);
-            $header = array(array('data' => t('Your signup information'), 'colspan' => 2));
-            $rows = array();
-            if(is_array($form_data)) {
-              foreach ($form_data as $key => $value) {
-                $rows[] = array($key . ':', check_plain($value));
-              }
-            }
-            $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel Signup'));
-            $output = theme('table', $header, $rows) . drupal_get_form('signup_form_view', $form);
-          }
-        }
-
-        //if user has signup perm, and signup_user_view is enabled, then display the current signups
-        //pull all user signed up for this event, and start table creation
-        if (user_access('allow signups') && variable_get('signup_user_view', 0)) {
-          $signups = db_query("SELECT u.uid, u.name, s.signup_time, s.form_data FROM {signup_log} s INNER JOIN {users} u ON
-    u.uid = s.uid WHERE s.nid =%d", $node->nid);
-          $header = array(array('data' => t('%d individual(s) signed up', array('%d' => db_num_rows($signups)))));
-          $rows = array();
-
-          //loop through the users
-          while ($signed_up_user = db_fetch_object($signups)) {
-
-            //build the row for this user
-            $rows[] = array(l(check_plain($signed_up_user->name), "user/$signed_up_user->uid"));
-          }
-          $output .= theme('table', $header, $rows);
-        }
-        $node->body .= $output;
+        // Add the signup form
+        $node->body .= theme('signup_form', $node, $user);
+        // Add the signup list
+        $node->body .= theme('signup_list', $node);
       }
       break;
   }
 }
 
 /**
+ * Hook to expose signup data to views module
+ * @ingroup signup_views_api
+ */
+function signup_views_tables() {
+  $tables['signup_log'] = array(
+    'name' => 'signup_log',
+    "join" => array(
+      "left" => array(
+        "table" => "node",
+        "field" => "nid"
+      ), 
+      "right" => array(
+        "field" => "nid"
+      ), 
+    ),
+    "fields" => array(
+      "uid" => array(
+        'name' => "Signup: Users",
+        'handler' => 'views_handler_field_signupname',
+        'sortable' => false,
+      ),
+    ),
+  );
+  return $tables;
+}
+
+/**
+ * Handler to return pretty usernames instead of fairly useless uid info
+ * @ingroup signup_views_api
+ */
+function views_handler_field_signupname($fieldinfo, $fielddata, $value, $data) {
+  // Don't return 'Anomyous' if no users have signed up
+  return $value ? theme('username', user_load(array('uid' => $value))):'';
+}
+
+/**
  * @defgroup signup_callback Functions which are the menu callbacks for this module
  */
 
@@ -613,9 +599,9 @@
 //user be the same as the name of the data field, but it's not required. see below for examples:
 function signup_user_form() {
   $form['signup_form_data']['#tree'] = TRUE;
-  $form['signup_form_data']['Name'] = array('#type' => 'textfield', '#title' => t('Name'), '#size' => 40, '#maxlength' => 64);
-  $form['signup_form_data']['Email'] = array('#type' => 'textfield', '#title' => t('Email'), '#size' => 40, '#maxlength' => 64);
-  $form['signup_form_data']['Phone'] = array('#type' => 'textfield', '#title' => t('Phone'), '#size' => 40, '#maxlength' => 64);
+  $form['signup_form_data']['Name'] = array('#type' => 'textfield', '#title' => t('Name'), '#size' => 25, '#maxlength' => 64);
+  $form['signup_form_data']['Email'] = array('#type' => 'textfield', '#title' => t('Email'), '#size' => 25, '#maxlength' => 64);
+  $form['signup_form_data']['Phone'] = array('#type' => 'textfield', '#title' => t('Phone'), '#size' => 25, '#maxlength' => 64);
 
   return $form;
 }
@@ -935,4 +921,66 @@
   }
   return $return;
 }
+
+/**
+ * Returns the signup form depending on whether or not the user can/has signed up
+ * @ingroup signup_themes
+ */
+function theme_signup_form($node, $user) {
+  // If it's closed, return a notice saying as much
+  if ($node->signup->completed && $node->signup->allowed) {
+    $output = '<h3>' . t('Signups closed for this event') . '</h3>';
+  }
+
+  // If it's an anonymous user, send them a link to login
+  elseif ($user->uid == 0) {
+    $output .= user_access('allow signups') ? '<div class="signup_anonymous">'. t('<p>Please %login to sign up for this event.</p>', array("%login"=> l(t('login/register'), 'user/login', array(), drupal_get_destination()))) .'</div>' : '';
+  }
+
+  // If the user is already signed up to the node, allow them to cancel
+  elseif ($node->signup->signed_up) {
+    $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid =%d", $user->uid, $node->nid);
+    $result = db_fetch_object($result);
+    $form_data = unserialize($result->form_data);
+    $header = array(array('data' => t('Your signup information'), 'colspan' => 2));
+    $rows = array();
+    if(is_array($form_data)) {
+      foreach ($form_data as $key => $value) {
+        $rows[] = array($key . ':', check_plain($value));
+      }
+    }
+    $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel Signup'));
+    $output = theme('table', $header, $rows) . drupal_get_form('signup_form_view', $form);
+  }
+
+  // OK, give them the signup form
+  else {
+    $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
+    $form['uid'] = array('#type' => 'hidden', '#value' => $user->uid);
+    $form['#action'] = url('signup', drupal_get_destination());
+    $form['collapse'] = array('#type' => 'fieldset', '#title' => t('Sign up for %title', array('%title' => check_plain($node->title))), '#collapsible' => TRUE, '#collapsed' => TRUE);
+    $form['collapse']['signup_user_form'] = signup_user_form();
+    $form['collapse']['submit'] = array('#type' => 'submit', '#value' => t('Sign up'));
+    $output = drupal_get_form('signup_form_view', $form);
+  }
+  return $output;
+}
+
+/**
+ * Returns the signup list
+ * @ingroup signup_themes
+ */
+function theme_signup_list($node) {
+  $signups = db_query("SELECT u.uid, u.name, s.signup_time, s.form_data FROM {signup_log} s INNER JOIN {users} u ON u.uid = s.uid WHERE s.nid =%d", $node->nid);
+  $header = array(array('data' => t('%d individual(s) signed up', array('%d' => db_num_rows($signups)))));
+  $rows = array();
+
+  //loop through the users
+  while ($signed_up_user = db_fetch_object($signups)) {
+    //build the row for this user
+    $rows[] = array(l(check_plain($signed_up_user->name), "user/$signed_up_user->uid"));
+  }
+  $output = theme('table', $header, $rows);
+  return $output;
+}
 ?>
\ No newline at end of file
