Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.73
diff -u -F^f -r1.73 signup.module
--- signup.module	18 Aug 2006 08:20:56 -0000	1.73
+++ signup.module	9 Dec 2006 17:43:56 -0000
@@ -45,7 +45,7 @@ function signup_block($op = 'list', $del
 function signup_cron() {
 
   //only run this function if the event module is enabled
-  if (module_exist('event')) {
+  if (module_exists('event')) {
 
     //must include this here as event module doesn't include timezone support on all page requests
     include_once(drupal_get_path('module', 'event') .'/event_timezones.inc');
@@ -60,7 +60,6 @@ function signup_cron() {
     //grab each event, construct the email header and subject, and query the signup log to pull all users who are
     //signed up for this event
     $from = variable_get('site_mail', 'noadmin@noadmin.com');
-    $header = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
     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 FROM {signup_log} s_l INNER JOIN {users} u ON u.uid = s_l.uid
@@ -75,7 +74,7 @@ function signup_cron() {
         $trans = array("%event" => $event->title, "%time" => _event_date(variable_get('signup_date_string', 'D, M jS, g:i A'),
         $event->event_start, $offset), "%username" => $signup->name, "%useremail" => $mail_address);
         $message = strtr($event->reminder_email, $trans);
-        user_mail($mail_address, $subject, $message, $header);
+        drupal_mail('signup_reminder_mail', $mail_address, $subject, $message, $from);
         watchdog('signup', t('Reminder for %event sent to %useremail.', array('%event' => l($event->title, 'node/' . $event->nid), '%useremail' => $mail_address)));
       }
 
@@ -108,9 +107,6 @@ function signup_cron() {
  */
 function signup_help($section) {
   switch ($section) {
-    case 'admin/modules#description':
-      return t('Allow users to sign up for events.');
-      break;
     case 'admin/help#signup':
       return t('<p>Signup allows users to sign up for nodes of any type.  Includes options for sending a notification email to a selected email address upon a new user signup (good for notifying event coordinators, etc.) and a confirmation email to users who sign up--these options are per node.  When used on event nodes (with event.module installed and regular cron runs), it can also send out reminder emails to all signups X days before the start of the event (per node setting) and auto-close event signups 1 hour before their start (general setting). Settings exist for resticting signups to selected roles and content types.</p><br><p>To use signup, you must enable a node type for signups in administer->settings->content types, and you must also grant the \'allow signups\' permission to any user role for which you wish to allow signups in administer->access control. Each signup node will now have a place for users to sign up, and administrators with the \'admin signups\' privilege will be able to view signups for each signup node and see an overview of signups for all nodes (the overview is located in administer/signup)</p><br><p>Default settings for notification email address, reminder emails and confirmation emails are located in administer->settings->signup. These will be the default values used for a signup node unless otherwise specified (to configure these options per node, visit \'edit\' for that node and make the adjustments in the \'Sign up settings\' section)</p><br><p>Signups can be manually closed for any node at administer->signup.</p><br><p>The user signup form is fully themable--form fields may be added or deleted.  For more details see the instructions in signup.theme, where a sample user form is included</p>');
   }
@@ -131,15 +127,16 @@ function signup_menu($may_cache) {
     //admin/settings/signup menu item
 
     $items[] = array('path' => 'admin/settings/signup', 'access' => $access,
-      'callback' => 'signup_settings_page',
-      'title' => user_access('administer site configuration') ?
-                               t('signup') : t('signup settings'));
+      'description' => t('Configure relevant settings for signup.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('signup_settings_page'),
+      'title' => t('Signup settings'));
 
     //admin/signup menu item
-    $items[] = array('path' => 'admin/signup', 'access' => $access,
+    $items[] = array('path' => 'admin/content/signup', 'access' => $access,
       'callback' => 'signup_admin_page',
       'title' => user_access('administer site configuration') ?
-                               t('signup') : t('signup overview'));
+                               t('Signup') : t('signup overview'));
 
     $items[] = array('path' => 'admin/signup/overview', 'title' => t('overview'),
         'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
@@ -176,7 +173,7 @@ function signup_menu($may_cache) {
   	if (arg(0) == 'node' && is_numeric(arg(1)) && db_num_rows(db_query("SELECT nid FROM {signup} WHERE nid = %d", arg(1)))) {
   	  $node = node_load(array('nid'=>arg(1)));
   	  $access_own = user_access('admin own signups') && ($user->uid == $node->uid);
-      $items[] = array('path' => 'node/' . arg(1) . '/signups', 'title' => t('signups'),
+      $items[] = array('path' => 'node/' . arg(1) . '/signups', 'title' => t('Signups'),
           'callback' => 'signup_user_signups_form', 'callback arguments' => array($node),
           'access' => $access || $access_own, 'type' => MENU_LOCAL_TASK, 'weight' => 20);
 
@@ -219,8 +216,8 @@ function signup_user($op, &$edit, &$user
  * @ingroup signup_core
  */
 function signup_form_alter($form_id, &$form) {
-  if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
-    $type = $form['type']['#value'];
+  if ($form_id == 'node_type_form') {
+    $type = $form['#node_type']->type;
     $form['workflow']['signup_form_' . $type] = array(
       '#type' => 'checkbox',
       '#title' => t('Allow signups'),
@@ -273,7 +270,6 @@ function signup_form_alter($form_id, &$f
  * @param $form_values The constructed form values array of the submitted form.
  */
 function signup_form_cancel_submit($form_id, $form_values) {
-
   signup_cancel_signup($form_values['uid'], $form_values['nid'], $form_values['signup_anon_mail']);
 }
 
@@ -402,10 +398,6 @@ function signup_nodeapi(&$node, $op, $te
           }
         } else {
 
-          //build some initial form elements
-          $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
-          $form['uid'] = array('#type' => 'value', '#value' => $user->uid);
-
           //this is an anonymous user. if they have signup permissions, then build the anon portion
           //of the sigup form.  if not, then display the login link
           if ($user->uid == 0) {
@@ -438,18 +430,7 @@ function signup_nodeapi(&$node, $op, $te
             //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);
-
-              //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 (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'));
-              $output = drupal_get_form('signup_form', $form);
+              $output = drupal_get_form('signup_form', $node, $anon_signup_form);
             }
 
           //the user is already signed up, so print a table of their signup data, and give them the option to cancel
@@ -463,12 +444,11 @@ function signup_nodeapi(&$node, $op, $te
                 $rows[] = array($key . ':', check_plain($value));
               }
             }
-            $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel Signup'));
             $output = '';
             if (!empty($rows)) {
               $output .= theme('table', $header, $rows);
             }
-            $output .= drupal_get_form('signup_form_cancel', $form);
+            $output .= drupal_get_form('signup_form_cancel', $node);
           }
         }
 
@@ -478,7 +458,7 @@ function signup_nodeapi(&$node, $op, $te
           $registered_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 AND u.uid != 0", $node->nid);
           $anon_signups = db_num_rows(db_query("SELECT anon_mail FROM {signup_log} WHERE nid =%d AND uid = 0", $node->nid));
-          $header = array(array('data' => t('%users signed up', array('%users' => format_plural((db_num_rows($registered_signups) + $anon_signups), '1 individual', '%count individuals')))));
+          $header = array(array('data' => t('@users signed up', array('@users' => format_plural((db_num_rows($registered_signups) + $anon_signups), '1 individual', '@count individuals')))));
           $rows = array();
 
           //loop through the users
@@ -494,7 +474,10 @@ function signup_nodeapi(&$node, $op, $te
         }
         // Save output into a node property for retrieval from the theme layer.
         $node->signup_view = $output;
-        $node->body .= $output;
+        $node->content['signup'] = array(
+          '#value' => $output,
+          '#weight' => 10,
+        );
       }
       break;
   }
@@ -503,6 +486,48 @@ function signup_nodeapi(&$node, $op, $te
 /**
  * @defgroup signup_callback Functions which are the menu callbacks for this module
  */
+ 
+ /**
+  * Builder function for the signup form
+  * @ingroup signup_callback
+  */
+function signup_form($node, $anon_signup_form = NULL) {
+  global $user;
+  
+  //build some initial form elements
+  $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' => TRUE);
+
+  //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 (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'));
+  
+  return $form;
+}
+
+/**
+ * Builder function for the cancel signup form
+ * @ingroup signup_callback
+ */
+function signup_form_cancel($node) {
+  global $user;
+  
+  //build some initial form elements
+  $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
+  $form['uid'] = array('#type' => 'value', '#value' => $user->uid);
+  
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel Signup'));
+  
+  return $form;
+}
 
 /**
  * Prints the admin signup overview page located at admin/signup
@@ -510,10 +535,10 @@ function signup_nodeapi(&$node, $op, $te
  */
 function signup_admin_page() {
   $output = '';
-  drupal_set_title(t('signups'));
+  drupal_set_title(t('Signups'));
 
   // Add optional SQL to the query if the event module is enabled. 
-  $_EVENT = module_exist('event');
+  $_EVENT = module_exists('event');
   $event_select = $_EVENT ? ', e.event_start, e.timezone' : '';
   $event_join = $_EVENT ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
 
@@ -603,7 +628,7 @@ function signup_cancel_signup($uid, $nid
     $function = $module .'_signup_cancel';
     $function($node);
   }
-  drupal_set_message(t('Signup to %title cancelled.', array('%title' => l($node->title, "node/$node->nid"))));
+  drupal_set_message(t('Signup to !title cancelled.', array('!title' => l($node->title, "node/$node->nid"))));
 }
 
 /**
@@ -618,7 +643,7 @@ function signup_close_signup($nid, $cron
       $function = $module .'_signup_close';
       $function($node);
     }
-    watchdog('signup', t('Signups closed for %link.', array('%link'=>l($node->title, 'node/'.$nid))));
+    watchdog('signup', t('Signups closed for !link.', array('!link'=>l($node->title, 'node/'.$nid))));
   }
 }
   
@@ -668,9 +693,8 @@ function signup_settings_page() {
   $form['title'] = array('#type' => 'markup', '#value' => '<h2>' . t('Default signup information') . '</h2><br>' . t('New signup nodes will start with these settings'));
   $form['group'] = array('#type' => 'fieldset', '#title' => t('Sign up settings'));
   $form['group']['_signup_admin_form'] = _signup_admin_form($node);
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
-  return drupal_get_form('signup_settings_page', $form);
 
+  return system_settings_form($form);
 }
 
 /**
@@ -711,7 +735,7 @@ function signup_list_user_signups($uid) 
   //we don't want to return anything for anon users...
   if ($uid != 0) {
     //tests for optional support of event.module
-    $_EVENT = module_exist('event');
+    $_EVENT = module_exists('event');
     $event_join = $_EVENT ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
     $event_where = $_EVENT ? ' AND (e.event_start >= '. time() . ' OR e.event_start IS NULL)' : '';
     $order_by = $_EVENT ? 'e.event_start' : 'n.title';
@@ -777,7 +801,7 @@ function signup_sign_up_user($signup_for
         (%d, %d, '%s', %d, '%s')", $signup_form['uid'], $signup_form['nid'], $signup_form['signup_anon_mail'], $curtime, $signup_form_data);
 
     //must include this here as event module doesn't include timezone support on all page requests
-    if (module_exist('event')) {
+    if (module_exists('event')) {
       include_once(drupal_get_path('module', 'event') .'/event_timezones.inc');
     }
 
@@ -801,22 +825,21 @@ function signup_sign_up_user($signup_for
 
     //if a confirmation is to be sent, compose the mail message, translate the string substitutions, and send it
     if ($event->send_confirmation && $user_mail) {
-      $header = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
-      $subject = t('Signup confirmation for event: %event', array('%event' => $node->title));
+      $subject = t('Signup confirmation for event: @event', array('@event' => $node->title));
       $message = strtr($event->confirmation_email, $trans);
-      user_mail($user_mail, $subject, $message, $header);
+      drupal_mail('signup_confirmation_mail', $user_mail, $subject, $message, $from);
     }
 
     //if a forwarding email is to be sent, compose the mail message, translate the string substitutions, and send it
     if ($event->forwarding_email) {
-      $header = "From: " . t('New Event Signup') . "<$from>\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
+      $header = array('From' => t('New Event Signup') . "<$from>");
       $subject = t('Signup confirmation for event: %title', array('%title' => $node->title));
       $message = t('The following information was submitted as a signup for %title', array('%title' => $node->title)) .
       "\n\r" . t('Date/Time: %time', array('%time'=>$starttime)) . ":\n\r\n\r\n\r" . t('username:') . $user->name .
       "\n\r" . t('email:') . $user_mail . "\n\r\n\r" . $signup_data;
-      user_mail($event->forwarding_email, $subject, $message, $header);
+      drupal_mail('signup_forwarding_mail', $event->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 confirmed.', array('!title' => l($node->title, "node/$node->nid"))) . $confirmation_email . $reminder_email);
   } else {
     drupal_access_denied();
   }
@@ -851,16 +874,12 @@ function signup_user_signups_form($node)
   drupal_set_title(check_plain($node->title));
 
   // Display if signups are open/closed, and print a button to toggle
-  $form = array();
-  $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
   $ctrl_row = array();
   if ($node->signup_completed) {
-    $form['submit'] = array('#type' => 'submit', '#value' => t('Open Signups'));
-    $ctrl_row[] = array(t('Signups <b>closed</b> for this event'), drupal_get_form('signup_open_signups_form', $form));
+    $ctrl_row[] = array(t('Signups <b>closed</b> for this event'), drupal_get_form('signup_open_signups_form', $node->nid));
   }
   else {
-    $form['submit'] = array('#type' => 'submit', '#value' => t('Close Signups'));
-    $ctrl_row[] = array(t('Signups <b>open</b> for this event'), drupal_get_form('signup_close_signups_form', $form));
+    $ctrl_row[] = array(t('Signups <b>open</b> for this event'), drupal_get_form('signup_close_signups_form', $node->nid));
   }
   $output .= '<div class="signup-admin-row">';
   $output .= theme('table', NULL, $ctrl_row);
@@ -869,7 +888,7 @@ function signup_user_signups_form($node)
   //pull all user signed up for this event, and start table creation
   $result = db_query("SELECT u.uid, u.name, s.anon_mail, 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('%users signed up', array('%users' => format_plural(db_num_rows($result), '1 individual', '%count individuals'))), 'colspan' => 3));
+  $header = array(array('data' => t('@users signed up', array('@users' => format_plural(db_num_rows($result), '1 individual', '@count individuals'))), 'colspan' => 3));
 
   $rows = array();
 
@@ -886,13 +905,6 @@ function signup_user_signups_form($node)
       $table_data[] = $key . ': ' . check_plain($value);
     }
 
-    // build the form for this row
-    $form = array();
-    $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
-    $form['uid'] = array('#type' => 'value', '#value' => $signed_up_user->uid);
-    $form['signup_anon_mail'] = array('#type' => 'value', '#value' => $signed_up_user->anon_mail);
-    $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel Signup'));
-
     //the username and the unique form identifier are different for anon signups and registered user signups
     //for registered users, provide a link to the user profile, and use the uid as the identifier.  for anon,
     //use the site 'anonymous' setting, and the user's email address as the identifier.
@@ -907,20 +919,45 @@ function signup_user_signups_form($node)
     //build the row for this user
     $rows[] = array($username .'<br>'.
       gmdate(variable_get('signup_date_string', 'M jS, g:i A'), $signed_up_user->signup_time + $offset),
-      implode('<br>', $table_data), drupal_get_form('signup_user_signups_form_'. $id, $form, 'signup_form_cancel'));
+      implode('<br>', $table_data), drupal_get_form('signup_user_cancel_form', $node->nid, $signed_up_user->uid, $signed_up_user->anon_mail));
   }
   $output .= theme('table', $header, $rows);
   print theme('page', $output);
 }
 
+function signup_open_signups_form($nid) {
+  $form['nid'] = array('#type' => 'value', '#value' => $nid);
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Open Signups'));
+  
+  return $form;
+}
 function signup_open_signups_form_submit($form_id, $form_values) {
   signup_open_signup($form_values['nid']);
 }
 
+function signup_close_signups_form($nid) {
+  $form['nid'] = array('#type' => 'value', '#value' => $nid);
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Close Signups'));
+  
+  return $form;
+}
+
 function signup_close_signups_form_submit($form_id, $form_values) {
   signup_close_signup($form_values['nid']);
 }
 
+function signup_user_cancel_form($nid, $uid, $anon_mail) {
+  $form['#base'] = 'signup_form_cancel';
+  
+  // build the form for this row
+  $form['nid'] = array('#type' => 'value', '#value' => $nid);
+  $form['uid'] = array('#type' => 'value', '#value' => $uid);
+  $form['signup_anon_mail'] = array('#type' => 'value', '#value' => $anon_mail);
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel Signup'));
+  
+  return $form;
+}
+
 /**
  * Validates an anonymous signup email.
  *
