? signup_date.inc
Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.120
diff -u -r1.120 signup.module
--- signup.module	16 Oct 2007 19:39:30 -0000	1.120
+++ signup.module	13 Nov 2007 16:17:08 -0000
@@ -25,6 +25,15 @@
   _signup_cron_autoclose();
 }
 
+function signup_types() {
+  $types = array();
+  $result = db_query("SELECT DISTINCT type FROM {signup} s LEFT JOIN {node} n ON s.nid = n.nid");
+  while ($type = db_fetch_array($result)) {
+    $types[] = $type['type'];
+  }
+  return $types;
+}
+
 /**
  * Helper function that sends cron-based reminder e-mails.
  *
@@ -38,10 +47,13 @@
  * @see _signup_build_query()
  */
 function _signup_cron_send_reminders() {
+  $reminder_sql = array();
   if (function_exists('signup_reminder_sql')) {
-    $reminder_sql = signup_reminder_sql();
+    foreach (signup_types() as $type) {
+      $reminder_sql[] = signup_reminder_sql($type);
+    }
   }
-  if (empty($reminder_sql)) {
+  if (empty($reminder_sql[0])) {
     // The backend doesn't support reminder emails, so bail out now.
     return;
   }
@@ -49,7 +61,7 @@
   $reminder_common_sql = array(
     'primary' => '{signup} s',
     'fields' => array('n.title', 'n.nid', 's.reminder_email', 's.forwarding_email'),
-    'where' => array('s.send_reminder = 1'),
+    'where' => array('s.send_reminder = 1 AND n.type = \'type\''),
     'joins' => array('INNER JOIN {node} n ON n.nid = s.nid'),
   );
 
@@ -95,7 +107,7 @@
  * Helper function that handles auto-closing events during cron.
  *
  * Invokes the method for the installed event/date backend module to get the
- * right query fragments, and builds a query to find all events where signups 
+ * right query fragments, and builds a query to find all events where signups
  * should be closed (e.g. events that already started, etc).
  *
  * @see signup_cron()
@@ -104,9 +116,11 @@
  */
 function _signup_cron_autoclose() {
   if (function_exists('signup_autoclose_sql')) {
-    $autoclose_sql = signup_autoclose_sql();
+    foreach (signup_types() as $type) {
+      $autoclose_sql[] = signup_autoclose_sql($type);
+    }
   }
-  if (empty($autoclose_sql)) {
+  if (empty($autoclose_sql[0])) {
     // The backend doesn't support auto-closing events, so bail out now.
     return;
   }
@@ -152,31 +166,50 @@
  *   Complete SQL statement based on the given query fragments.
  */
 function _signup_build_query($common_sql, $backend_sql) {
+  // Combine all the backend_sql values into a single array.
+  $fields = array();
+  $joins = array();
+  $where = array();
+  $group_by = array();
+  foreach ($backend_sql as $sql) {
+    $fields = array_merge($fields, (!empty($sql['fields']) ? $sql['fields'] : array()));
+    $joins = array_merge($joins, (!empty($sql['joins']) ? $sql['joins'] : array()));
+    $where = array_merge($where, (!empty($sql['where']) ? $sql['where'] : array()));
+    $group_by = array_merge($group_by, (!empty($sql['group_by']) ? $sql['group_by'] : array()));
+  }
 
+  // Combine backend sql with common_sql.
   $fields = array_merge(
     (!empty($common_sql['fields']) ? $common_sql['fields'] : array()),
-    (!empty($backend_sql['fields']) ? $backend_sql['fields'] : array())
+    (!empty($fields) ? $fields : array())
   );
   $joins = array_merge(
     (!empty($common_sql['joins']) ? $common_sql['joins'] : array()),
-    (!empty($backend_sql['joins']) ? $backend_sql['joins'] : array())
-  );
-  $where = array_merge(
-    (!empty($common_sql['where']) ? $common_sql['where'] : array()),
-    (!empty($backend_sql['where']) ? $backend_sql['where'] : array())
+    (!empty($joins) ? $joins : array())
   );
   $group_by = array_merge(
     (!empty($common_sql['group_by']) ? $common_sql['group_by'] : array()),
-    (!empty($backend_sql['group_by']) ? $backend_sql['group_by'] : array())
+    (!empty($group_by) ? $group_by : array())
   );
 
+  // Combine each of the backend_sql content type 'where' criteria with the common 'where'
+  // criteria to create the OR where clause.
+  if (!empty($where)) {
+    foreach ($where as $criteria) {
+      $where_or[] = implode(' AND ', array($common_sql['where'], $criteria));
+    }
+  }
+  elseif(!empty($common_sql['where'])) {
+    $where_or[] = $common_sql['where'];
+  }
+
   $sql = 'SELECT '. implode(', ', $fields);
   $sql .= ' FROM '. $common_sql['primary'] .' ';
   if (!empty($joins)) {
     $sql .= implode(' ', $joins);
   }
-  if (!empty($where)) {
-    $sql .= ' WHERE '. implode(' AND ', $where);
+  if (!empty($where_or)) {
+    $sql .= ' WHERE '. implode(' OR ', $where_or);
   }
   if (!empty($group_by)) {
     $sql .= ' GROUP BY '. implode(', ', $group_by);
@@ -344,6 +377,20 @@
     '#default_value' => variable_get('signup_form_'. $type, FALSE) == 1,
     '#description' => t('If selected, users will be allowed to signup for this node type by default. Users with %admin_all_signups permission will be able to toggle this setting on a per-node basis.', array('%admin_all_signups' => t('administer all signups'))),
   );
+  $form['workflow']['signup_form_date'] = array(
+    '#type' => 'select',
+    '#options' => signup_event_fields($type),
+    '#title' => t('Event date field'),
+    '#default_value' => variable_get('signup_form_field_'. $type, ''),
+    '#description' => t('The field to use as the event date when computing timing for reminder notices and reports.'),
+  );
+}
+
+function signup_event_fields($type) {
+  if (function_exists('signup_reminder_sql')) {
+    $options = signup_field_names($type);
+  }
+  return (array) $options;
 }
 
 /**
@@ -837,7 +884,7 @@
   $form['header']['#value'] = $header;
 
   $sql .= tablesort_sql($header);
-  
+
   $result = pager_query($sql, 25, 0, $sql_count);
 
   // Loop through the signup nodes, and generate our form elements
@@ -854,7 +901,7 @@
     $row['title'] = array(
       '#type' => 'markup',
       '#value' => l($signup_event->title, "node/$signup_event->nid"),
-    );     
+    );
     $row['status'] = $node_admin_form['status'];
     $row['total'] = array(
       '#type' => 'markup',
@@ -869,7 +916,7 @@
     $row['operations'] = array(
       '#type' => 'markup',
       '#value' => $op_links,
-    );     
+    );
     $form['nids'][$signup_event->nid] = $row;
   }
   $form['#tree'] = true;
@@ -914,11 +961,11 @@
   }
 
   // Get the right query elements from the currently installed backend
+  $admin_sql = array();
   if (function_exists('signup_admin_sql')) {
-    $admin_sql = signup_admin_sql();
-  }
-  else {
-    $admin_sql = array();
+    foreach (signup_content_types() as $type) {
+      $admin_sql[] = signup_admin_sql($type);
+    }
   }
 
   // Build the main query.
@@ -1069,7 +1116,7 @@
   $form['adv_settings']['signup_fieldset_collapsed'] = array(
     '#title' => t('Default fieldset behavior for per-node signup form'),
     '#type' => 'radios',
-    '#options' => array(1 => t('Collapsed'), 0 => t('Expanded')), 
+    '#options' => array(1 => t('Collapsed'), 0 => t('Expanded')),
     '#default_value' => variable_get('signup_fieldset_collapsed', 1),
     '#description' => t('On every signup-enabled node, users with permission to sign up will be presented with a form which is encapsulated in a collapsible fieldset. This setting controls if that fieldset is expanded or collapsed by default.'),
   );
@@ -1160,9 +1207,9 @@
  *   automatically be set to 0 if this element is passed in. NOTE: It's
  *   highly recommended to call the signup_validate_anon_email
  *   function in the external module's validation cycle or perform
- *   that function's validation logic prior to passing in this element! 
+ *   that function's validation logic prior to passing in this element!
  * $signup_form['signup_form_data'] : an array of key/value pairs --
- *   key is the data category, value is the user input 
+ *   key is the data category, value is the user input
  */
 function signup_sign_up_user($signup_form) {
   $node = node_load($signup_form['nid']);
@@ -1174,7 +1221,7 @@
   // 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;  
+    $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'));
@@ -1711,7 +1758,7 @@
     '#type' => 'value',
     '#value' => $node->nid,
   );
-  
+
   global $user;
   if (user_access('administer site configuration')) {
     $form['from'] = array(
@@ -1739,15 +1786,15 @@
  * @return An array of objects containing signup data
  */
 function signup_get_email_addresses($nid) {
-  $signups = db_query("SELECT u.uid, u.name, u.mail, s_l.anon_mail FROM {signup_log} s_l INNER JOIN {users} u ON u.uid = s_l.uid WHERE s_l.nid = %d", $nid);  
+  $signups = db_query("SELECT u.uid, u.name, u.mail, s_l.anon_mail FROM {signup_log} s_l INNER JOIN {users} u ON u.uid = s_l.uid WHERE s_l.nid = %d", $nid);
   while ($signup_entry = db_fetch_object($signups)) {
     $signup_data[] = $signup_entry;
-  } 
+  }
   return $signup_data;
-} 
+}
 
 /**
- * Send an email message to all those signed up to an event. 
+ * Send an email message to all those signed up to an event.
  *
  * @param $form_id
  * @param $form_values
@@ -1758,7 +1805,7 @@
     $from = $form_values['from'];
     $subject = $form_values['subject'];
     $event = node_load($form_values['nid']);
-    foreach ($addresses as $signup) { 
+    foreach ($addresses as $signup) {
       $mail_address = $signup->anon_mail ? $signup->anon_mail : $signup->mail;
       $trans = array(
         '%event' => $event->title,
Index: signup_event_5.x-1.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup_event_5.x-1.inc,v
retrieving revision 1.2
diff -u -r1.2 signup_event_5.x-1.inc
--- signup_event_5.x-1.inc	14 Aug 2007 07:17:54 -0000	1.2
+++ signup_event_5.x-1.inc	13 Nov 2007 18:03:16 -0000
@@ -4,7 +4,7 @@
 /**
  * @return Array of SQL clauses for cron reminder email query builder.
  */
-function signup_reminder_sql() {
+function signup_reminder_sql($content_type = NULL) {
   // We must manually include this here as the event module doesn't
   // include timezone support on all page requests.
   include_once(drupal_get_path('module', 'event') .'/event_timezones.inc');
@@ -18,7 +18,7 @@
 /**
  * @return Array of SQL clauses for cron auto-close query builder.
  */
-function signup_autoclose_sql() {
+function signup_autoclose_sql($content_type = NULL) {
   // We must manually include this here as the event module doesn't
   // include timezone support on all page requests.
   include_once(drupal_get_path('module', 'event') .'/event_timezones.inc');
@@ -32,7 +32,7 @@
 /**
  * @return Array of SQL clauses for admin overview page query builder.
  */
-function signup_admin_sql() {
+function signup_admin_sql($content_type = NULL) {
   return array(
     'fields' => array('e.event_start', 'e.timezone'),
     // All of the fields should go directly into GROUP BY.
@@ -52,7 +52,7 @@
   );
 }
 
-function signup_list_user_signups_sql() {
+function signup_list_user_signups_sql($content_type = NULL) {
   return "SELECT n.nid, n.title, e.event_start FROM {node} n INNER JOIN {signup_log} s_l ON n.nid = s_l.nid LEFT JOIN {event} e ON e.nid = n.nid WHERE s_l.uid = %d AND (e.event_start >= ". time() ." OR e.event_start IS NULL) ORDER BY e.event_start";
 }
 
@@ -83,6 +83,10 @@
   return $node->event_start ? _event_date(variable_get('signup_date_string', 'D, M jS, g:i A'), $node->event_start, $offset) : t('[Untimed]');
 }
 
+function signup_field_names($content_type = NULL) {
+  return array('event_' => t('Event date'));
+}
+
 /**
  * Theme function for displaying the start and end times for a given node on
  * the signup schedule page.
Index: signup_event_5.x-2.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup_event_5.x-2.inc,v
retrieving revision 1.2
diff -u -r1.2 signup_event_5.x-2.inc
--- signup_event_5.x-2.inc	18 Aug 2007 23:46:30 -0000	1.2
+++ signup_event_5.x-2.inc	13 Nov 2007 16:21:04 -0000
@@ -4,7 +4,7 @@
 /**
  * @return Array of SQL clauses for cron reminder email query builder.
  */
-function signup_reminder_sql() {
+function signup_reminder_sql($content_type = NULL) {
   global $db_type;
   switch ($db_type) {
     case 'mysql':
@@ -24,7 +24,7 @@
 /**
  * @return Array of SQL clauses for cron auto-close query builder.
  */
-function signup_autoclose_sql() {
+function signup_autoclose_sql($content_type = NULL) {
   return array(
     'fields' => array(event_select(), 'e.timezone'),
     'joins' => array(event_join('s')),
@@ -35,7 +35,7 @@
 /**
  * @return Array of SQL clauses for admin overview page query builder.
  */
-function signup_admin_sql() {
+function signup_admin_sql($content_type = NULL) {
   return array(
     'fields' => array(event_select(), 'e.timezone'),
     'group_by' => array('event_start', 'e.timezone'),
@@ -54,10 +54,14 @@
   );
 }
 
-function signup_list_user_signups_sql() {
+function signup_list_user_signups_sql($content_type = NULL) {
   return 'SELECT n.nid, n.title, '. event_select() .' FROM {node} n INNER JOIN {signup_log} s_l ON n.nid = s_l.nid '. event_join('n', 'LEFT') .' WHERE s_l.uid = %d AND ('. event_where() ." >= '". event_implode_date(_event_user_time()) ."' OR e.event_start IS NULL) ORDER BY event_start";
 }
 
+function signup_field_names($content_type = NULL) {
+  return array('event_start' => t('Event date'));
+}
+
 /**
  * Returns true if the given node is event-enabled, and the start time
  * has already passed the "Close x hours before" setting.
Index: signup_event_none.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup_event_none.inc,v
retrieving revision 1.1
diff -u -r1.1 signup_event_none.inc
--- signup_event_none.inc	31 Jul 2007 00:08:31 -0000	1.1
+++ signup_event_none.inc	13 Nov 2007 15:28:44 -0000
@@ -12,7 +12,7 @@
  *
  * The call site assumes the one and only %d in this query is the user's uid.
  */
-function signup_list_user_signups_sql() {
+function signup_list_user_signups_sql($content_type = NULL) {
   return "SELECT n.nid, n.title FROM {node} n INNER JOIN {signup_log} s_l ON n.nid = s_l.nid WHERE s_l.uid = %d ORDER BY n.nid";
 }
 
