? .dayhour.inc.swp
? test.patch
? archive/_________station_archive.install
? archive/____station_archive.module
? catalog/The Database.mdb
? catalog/fixit.php
? catalog/import.php
Index: schedule/station_schedule.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.install,v
retrieving revision 1.18
diff -u -p -u -p -r1.18 station_schedule.install
--- schedule/station_schedule.install	21 Nov 2007 18:12:16 -0000	1.18
+++ schedule/station_schedule.install	27 Nov 2007 02:07:55 -0000
@@ -13,6 +13,8 @@ function station_schedule_install() {
         CREATE TABLE {station_schedule} (
           `nid` int unsigned NOT NULL default '0',
           `increment` int unsigned NOT NULL default '0',
+          `start` int unsigned NOT NULL default '0', 
+          `finish` int unsigned NOT NULL default '1440',          
           `streams` longtext,
           `unscheduled_message` VARCHAR(255) NOT NULL default '',
           PRIMARY KEY(`nid`)
@@ -381,3 +383,22 @@ function station_schedule_update_5203() 
   }
   return $ret;
 }
+
+/**
+ * Add start and end times to schedules.
+ */
+function station_schedule_update_5204() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {station_schedule} ADD COLUMN `start` int unsigned AFTER `increment`");      
+      $ret[] = update_sql("ALTER TABLE {station_schedule} ADD COLUMN `finish` int unsigned AFTER `start`");      
+
+      db_query("UPDATE {station_schedule} SET start = '0'");
+      db_query("UPDATE {station_schedule} SET finish = '1440'");
+      
+      break;
+  }
+  return $ret;
+}
Index: schedule/station_schedule.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.module,v
retrieving revision 1.68
diff -u -p -u -p -r1.68 station_schedule.module
--- schedule/station_schedule.module	27 Nov 2007 01:19:58 -0000	1.68
+++ schedule/station_schedule.module	27 Nov 2007 02:22:39 -0000
@@ -206,6 +206,25 @@ function station_schedule_form($node) {
     '#options' => array(15 => t('15 Minutes'), 30 => t('30 Minutes'), 60 => t('1 Hour'), 120 => t('2 Hours')),
     '#description' => t("This is the minimum increment that programs can be scheduled in. <strong>Caution:</strong> Increasing this value on an existing schedule will probably cause wierdness."),
   );
+  $minute_options = array();
+  for ($minute = 0; $minute <= MINUTES_IN_DAY; $minute += 60) {
+    $time = station_time_from_minute($minute);
+    $minute_options[$minute] = $time['time'] . $time['a'];
+  }
+  $form['settings']['start'] = array(
+    '#type' => 'select',
+    '#title' => t('Schedule start'),
+    '#default_value' => isset($node->settings['start']) ? $node->settings['start'] / 60 : 0,
+    '#options' => $minute_options,
+    '#description' => t("The hour of the day at which the schedule begins."),
+  );
+  $form['settings']['finish'] = array(
+    '#type' => 'select',
+    '#title' => t('Schedule finish'),
+    '#default_value' => isset($node->settings['finish']) ? $node->settings['finish'] / 60 : 24,
+    '#options' => $minute_options,
+    '#description' => t("The hour of the day at which the schedule ends. May be earlier than or equal to the start to wrap around to the next morning."),
+  );
   $form['settings']['unscheduled_message'] = array(
     '#type' => 'textfield',
     '#title' => t('No scheduled programming message'),
@@ -324,15 +343,36 @@ function station_schedule_submit(&$node)
  * Implementation of hook_load().
  */
 function station_schedule_load($node) {
+
+  // Load the settings.
+  $settings = db_fetch_array(db_query('SELECT increment, start, finish, streams, unscheduled_message FROM {station_schedule} WHERE nid = %d', $node->nid));
+  if (isset($settings['streams']) && $streams = unserialize($settings['streams'])) {
+    $settings['streams'] = $streams;
+  }
+  else {
+    $settings['streams'] = array();
+  }
+
+  // Load the schedule.
   $schedule = array();
+  // get the start and end times of the schedule
+  $schedule_start   = $settings['start'];
+  $schedule_finish  = $settings['finish'];
+  // if the schedule finish time comes before start, the schedule day goes on into the next morning
+  if ($schedule_finish <= $schedule_start) {
+      $schedule_finish += 1440;
+  }
+
   // Use station_day_name() for the day ordering in case Sunday isn't the
   // first day of the week.
   foreach (station_day_name() as $day => $name) {
     $schedule[$day] = array();
 
-    $start = $day * MINUTES_IN_DAY;
-    $finish = $start + MINUTES_IN_DAY;
+    $start = $day * MINUTES_IN_DAY + $schedule_start;
+    $finish = $day * MINUTES_IN_DAY + $schedule_finish;
+
     $result = db_query('SELECT * FROM {station_schedule_item} i WHERE i.schedule_nid = %d AND i.finish > %d AND i.start < %d ORDER BY i.start', $node->nid, $start, $finish);
+
     while ($s = db_fetch_object($result)) {
       // If a show spans a day, limit its start and finish times to be with-in
       // the day.
@@ -344,15 +384,23 @@ function station_schedule_load($node) {
       }
       $schedule[$day][] = $s;
     }
-  }
 
-  // Load the settings.
-  $settings = db_fetch_array(db_query('SELECT increment, streams, unscheduled_message FROM {station_schedule} WHERE nid = %d', $node->nid));
-  if (isset($settings['streams']) && $streams = unserialize($settings['streams'])) {
-    $settings['streams'] = $streams;
-  }
-  else {
-    $settings['streams'] = array();
+    // load Sunday morning to show on the end of Saturday night, if the schedule display goes beyond midnight
+    if ($day == 6 and $finish > 7 * MINUTES_IN_DAY) {
+      $result = db_query('SELECT * FROM {station_schedule_item} i WHERE i.schedule_nid = %d AND i.finish > %d AND i.start < %d ORDER BY i.start', $node->nid, 0, $finish - 7 * MINUTES_IN_DAY);
+
+      while ($s = db_fetch_object($result)) {
+        // spoof the times to appear beyond the end of the week for the schedule layout
+        $s->finish += 7 * MINUTES_IN_DAY;
+        $s->start  += 7 * MINUTES_IN_DAY;
+
+        // only need to trim the end of the show: a show starting before 0 has already been loaded above
+        if ($s->finish > $finish) {
+          $s->finish = $finish;
+        }
+        $schedule[$day][] = $s;
+      }
+    }
   }
 
   return array(
@@ -365,7 +413,7 @@ function station_schedule_load($node) {
  * Implementation of hook_insert().
  */
 function station_schedule_insert($node) {
-  db_query("INSERT INTO {station_schedule} (nid, increment, streams, unscheduled_message) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
+  db_query("INSERT INTO {station_schedule} (nid, increment, start, finish, streams, unscheduled_message) VALUES (%d, %d, %d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], $node->settings['start'], $node->settings['finish'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
 }
 
 /**
@@ -381,7 +429,7 @@ function station_schedule_delete($node) 
  */
 function station_schedule_update($node) {
   db_query("DELETE FROM {station_schedule} WHERE nid = %d", $node->nid);
-  db_query("INSERT INTO {station_schedule} (nid, increment, streams, unscheduled_message) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
+  db_query("INSERT INTO {station_schedule} (nid, increment, start, finish, streams, unscheduled_message) VALUES (%d, %d, %d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], $node->settings['start'], $node->settings['finish'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
 }
 
 function station_schedule_admin_settings() {
@@ -933,6 +981,14 @@ function station_schedule_item_list($nod
   drupal_add_css(drupal_get_path('module', 'station_schedule') .'/station_schedule.css');
   drupal_set_title(check_plain($node->title));
 
+  // get the start and end times of the schedule  
+  $schedule_start = $node->settings['start'];
+  $schedule_finish = $node->settings['finish'];
+  
+  if ($schedule_finish <= $schedule_start) {
+    $schedule_finish += 1440;
+  } // for wrapping: to come later
+
   $header = array();
   $row = array();
   foreach ($node->schedule as $day => $items) {
@@ -940,8 +996,9 @@ function station_schedule_item_list($nod
     $row[$day] = '';
 
     // The last finish pointer starts at the beginning of the day.
-    $last_finish = $day * MINUTES_IN_DAY;
-    $day_finish = ($day + 1) * MINUTES_IN_DAY;
+    $last_finish = $day * MINUTES_IN_DAY + $schedule_start;
+    $day_finish = $day * MINUTES_IN_DAY + $schedule_finish;
+
     foreach ($items as $item) {
       // Display blocks for unscheduled time periods
       if ($last_finish != $item->start) {
@@ -1039,7 +1096,7 @@ function station_schedule_item_edit_form
   $minute_options = array();
   // Make sure the increment will advance the counter.
   $increment = ($node->settings['increment'] < 1) ? 1 : $node->settings['increment'];
-  for ($minute = 0; $minute <= 24 * 60; $minute += $increment) {
+  for ($minute = 0; $minute <= MINUTES_IN_DAY; $minute += $increment) {
     $time = station_time_from_minute($minute);
     $minute_options[$minute] = $time['time'] . $time['a'];
   }
@@ -1226,10 +1283,17 @@ function station_schedule_view($node, $t
     $header[0] = array('data' => t('Time'));
     $row = array();
 
+    // get the start and end times of the schedule
+    $schedule_start   = $node->settings['start'];
+    $schedule_finish  = $node->settings['finish'];
+    if ($schedule_finish <= $schedule_start) {
+      $schedule_finish += 1440; 
+    } // for wrapping: to come later
+
     // First column is hours.
     $row[0]['id'] = 'station-sch-hours';
-    for ($hour = 0; $hour < 24; $hour++) {
-      $row[0]['data'] .= theme('station_schedule_hour', $hour);
+    for ($hour = $schedule_start / 60; $hour < $schedule_finish / 60; $hour++) {
+      $row[0]['data'] .= theme('station_schedule_hour', $hour % 24);
     }
 
     // Then a column for each day of the week.
@@ -1238,8 +1302,8 @@ function station_schedule_view($node, $t
       $row[$day + 1]['data'] = '';
 
       // The last finish pointer starts at the beginning of the day.
-      $last_finish = $day * MINUTES_IN_DAY;
-      $day_finish = ($day + 1) * MINUTES_IN_DAY;
+      $last_finish = $day * MINUTES_IN_DAY + $schedule_start;
+      $day_finish  = $day * MINUTES_IN_DAY + $schedule_finish;
       foreach ($items as $item) {
         // Display blocks for unscheduled time periods
         if ($last_finish != $item->start) {
