Index: station.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/station.module,v
retrieving revision 1.56
diff -u -p -r1.56 station.module
--- station.module	12 Sep 2009 17:13:39 -0000	1.56
+++ station.module	17 Sep 2009 22:20:08 -0000
@@ -46,6 +46,9 @@ function station_menu() {
  */
 function station_theme() {
   return array(
+    'station_block_next_program' => array(
+      'arguments' => array('schedule' => NULL, 'program' => NULL),
+    ),
     'station_block_current_program' => array(
       'arguments' => array('schedule' => NULL, 'program' => NULL),
     ),
@@ -88,6 +91,11 @@ function station_block($op = 'list', $de
             'subject' => t('On Air'),
             'content' => station_block_current_program(),
           );
+        case 1:
+          return array(
+            'subject' => t('Next Up'),
+            'content' => station_block_next_program(),
+          );
       }
     }
     return;
@@ -99,6 +107,12 @@ function station_block($op = 'list', $de
       'region' => 'left',
       'cache'  => BLOCK_NO_CACHE,
     );
+    $blocks[1] = array(
+      'info'   => t('Station: Next Program'),
+      'status' => TRUE,
+      'region' => 'left',
+      'cache'  => BLOCK_NO_CACHE,
+    );
     return $blocks;
   }
 }
@@ -293,6 +307,43 @@ function station_get_program_at($timesta
 }
 
 /**
+ * Return HTML body of the block listing the next program.
+ *
+ * @return string
+ */
+function station_block_next_program() {
+  $schedule = station_default_schedule();
+  if (module_exists('station_schedule')) {
+    $program = station_schedule_program_get_next(time(), $schedule['nid']);
+  }
+  return theme('station_block_next_program', $schedule, $program);
+}
+
+/**
+ * Theme the next program block.
+ *
+ * @param $schedule
+ *   Schedule array returned by station_default_schedule().
+ * @param $program
+ *   Program node object.
+ * @return string
+ */
+function theme_station_block_next_program($schedule, $program) {
+  // Program or unscheduled...
+  if ($program) {
+    $output = l($program->title, $program->node_url) .'<br />';
+  }
+  else {
+    $output = check_plain($schedule['unscheduled_message']) .'<br />';
+  }
+
+  // Streams
+  $output .= theme('station_streams', $schedule['streams']);
+
+  return $output;
+}
+
+/**
  * Return HTML body of the block listing the current program.
  *
  * @return string
Index: schedule/station_schedule.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.module,v
retrieving revision 1.90
diff -u -p -r1.90 station_schedule.module
--- schedule/station_schedule.module	29 Aug 2009 08:01:43 -0000	1.90
+++ schedule/station_schedule.module	17 Sep 2009 22:20:09 -0000
@@ -824,6 +824,43 @@ function station_schedule_get_program_li
 
   return $schedules;
 }
+
+/**
+ * Get the program playing at a certain time. If no time is provide, use the
+ * current time.
+ *
+ * @param $gmt_timestamp
+ *   a timestamp used to determine the day of the week an hour.
+ * @param $schedule_nid
+ *   Schedule node id.
+ * @return
+ *   program node object if one is scheduled, an empty object if nothing is
+ *   scheduled.
+ */
+function station_schedule_program_get_next($gmt_timestamp, $schedule_nid) {
+  // Load the schedule item based on the time.
+  $ts = station_local_ts($gmt_timestamp);
+  $minute = station_minute_from_day_hour(date('w', $ts), date('G', $ts));
+
+  $schedule_item = db_fetch_object(db_query('SELECT * FROM {station_schedule_item} s WHERE s.schedule_nid = %d AND s.start > %d ORDER BY s.start LIMIT 1', $schedule_nid, $minute));
+
+  if (!isset($schedule_item->program_nid)) {
+    $schedule_item = db_fetch_object(db_query('SELECT * FROM {station_schedule_item} s WHERE s.schedule_nid = %d ORDER BY s.start LIMIT 1', $schedule_nid));
+  }
+  // If there's an associated program, load it
+  if (isset($schedule_item->program_nid)) {
+    if ($node = node_load($schedule_item->program_nid)) {
+      // set this so that if the show is scheduled for multiple times the caller
+      // can easily figure out which one.
+      $node->may_archive = $schedule_item->may_archive;
+      // put this in so they can use a pretty url
+      $node->node_url = url('node/'. $node->nid, array('absolute' => TRUE));
+      return $node;
+    }
+  }
+  return new stdClass();
+}
+
 /**
  * Get the program playing at a certain time. If no time is provide, use the
  * current time.
Index: schedule/views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/views.inc,v
retrieving revision 1.20
diff -u -p -r1.20 views.inc
--- schedule/views.inc	29 Aug 2009 08:01:43 -0000	1.20
+++ schedule/views.inc	17 Sep 2009 22:20:09 -0000
@@ -47,6 +47,31 @@ function station_schedule_views_tables()
       ),
     ),
   );
+  $tables['station_schedule_item_next'] = array(
+    'name' => 'station_schedule_item',
+    'join' => array(
+      'left' => array(
+        'table' => 'station_schedule',
+        'field' => 'nid',
+      ),
+      'right' => array(
+        'field' => 'schedule_nid'
+      ),
+      'extra' => array(
+        'start <= ***CURRENT_STATION_MINUTE***' => NULL,
+        'finish > ***CURRENT_STATION_MINUTE***' => NULL,
+      ),
+    ),
+    'fields' => array(
+      'program_nid' => array(
+        'name' => t('Station Schedule: Next program'),
+        'help' => t("The next scheduled program."),
+        'sortable' => TRUE,
+        'handler' => 'station_handler_field_schedule_next_program',
+        'addlfields' => array('iid', 'start', 'finish'),
+      ),
+    ),
+  );
   $tables['station_schedule_item_current'] = array(
     'name' => 'station_schedule_item',
     'join' => array(
@@ -316,6 +341,17 @@ function station_schedule_argument_sched
   }
 }
 
+function station_handler_field_schedule_next_program($fieldinfo, $fielddata, $value, $data) {
+  if (isset($data->station_schedule_item_next_program_nid)) {
+    if ($program = node_load($data->station_schedule_item_next_program_nid)) {
+      return l($program->title, "node/$program->nid");
+    }
+  }
+  else {
+    return check_plain(variable_get('station_block_unschedule',  t("We're on autopilot.")));
+  }
+}
+
 function station_handler_field_schedule_current_program($fieldinfo, $fielddata, $value, $data) {
   if (isset($data->station_schedule_item_current_program_nid)) {
     if ($program = node_load($data->station_schedule_item_current_program_nid)) {
