[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/station/schedule/ -> station_schedule.edit.inc (source)

   1  <?php
   2  // $Id: station_schedule.edit.inc,v 1.4 2009/09/17 23:13:43 drewish Exp $
   3  
   4  function station_schedule_item_list($node) {
   5    drupal_add_css(drupal_get_path('module', 'station_schedule') .'/station_schedule.css');
   6    drupal_set_title(check_plain($node->title));
   7  
   8    $header = array();
   9    $row = array();
  10    foreach ($node->schedule as $day => $items) {
  11      $header[$day] = station_day_name($day);
  12      $row[$day] = '';
  13  
  14      // The last finish pointer starts at the beginning of the day.
  15      $last_finish = $day * MINUTES_IN_DAY;
  16      $day_finish = ($day + 1) * MINUTES_IN_DAY;
  17      foreach ($items as $item) {
  18        // Display blocks for unscheduled time periods
  19        if ($last_finish != $item->start) {
  20          $row[$day] .= theme('station_schedule_admin_nonitem', $node, $last_finish, $item->start);
  21        }
  22        $last_finish = $item->finish;
  23  
  24        // Display the schedule item
  25        $item->program = node_load($item->program_nid);
  26        $row[$day] .= theme('station_schedule_admin_item', $node, $item);
  27      }
  28      // Display a block for any remaining time during the day.
  29      if ($last_finish < $day_finish) {
  30        $row[$day] .= theme('station_schedule_admin_nonitem', $node, $last_finish, $day_finish);
  31      }
  32    }
  33  
  34    // Render the table
  35    return theme('table', $header, array($row), array('id' => 'station-sch', 'class' => 'station-sch-admin'));
  36  }
  37  
  38  function theme_station_schedule_admin_nonitem($node, $start, $finish) {
  39    $class = 'station-sch-box station-sch-unscheduled';
  40    $height = ($finish - $start);
  41    $link = url("node/{$node->nid}/schedule/add/0/{$start}/{$finish}");
  42  
  43    $output = "<div class='{$class}'><a id='schedule-{$start}' href='{$link}' style='height: {$height}px;'>";
  44    $output .= '<span class="station-sch-time">'. theme('station_hour_range', $start, $finish) .'</span>';
  45    $output .= '<span class="station-sch-title">'. t('<em>Unscheduled</em>') .'</span>';
  46    $output .= "</a></div>\n";
  47  
  48    return $output;
  49  }
  50  
  51  function theme_station_schedule_admin_item($node, $item) {
  52    $class = 'station-sch-box station-sch-scheduled';
  53    $height = ($item->finish - $item->start);
  54    $link = url("node/{$node->nid}/schedule/{$item->iid}/edit");
  55  
  56    $output = "<div class='{$class}'><a id='schedule-{$item->start}' href='{$link}' style='height: {$height}px;'>";
  57    $output .= '<span class="station-sch-time">'. theme('station_hour_range', $item->start, $item->finish) .'</span>';
  58    $output .= '<span class="station-sch-title">'. check_plain($item->program->title) .'</span>';
  59    $output .= "</a></div>\n";
  60  
  61    return $output;
  62  }
  63  
  64  function station_schedule_item_add($schedule, $program_id = NULL, $start = 0, $finish = 60) {
  65    drupal_set_title(t('Add item to %title', array('%title' => $schedule->title)));
  66  
  67    $schedule_item = new stdClass;
  68    $schedule_item->schedule_nid = $schedule->nid;
  69    $schedule_item->iid = NULL;
  70    $schedule_item->program_nid = $program_id;
  71    $schedule_item->start = (int) $start;
  72    $schedule_item->finish = (int) $finish;
  73    $schedule_item->may_archive = TRUE;
  74  
  75    return drupal_get_form('station_schedule_item_edit_form', $schedule, $schedule_item, $start, $finish);
  76  }
  77  
  78  function station_schedule_item_edit($schedule, $schedule_item = NULL, $start = 0, $finish = 60) {
  79    drupal_set_title(t('Edit %title item', array('%title' => $schedule->title)));
  80  
  81    return drupal_get_form('station_schedule_item_edit_form', $schedule, $schedule_item, $start, $finish);
  82  }
  83  
  84  function station_schedule_item_edit_form(&$form_state, $schedule, $schedule_item = NULL, $start = 0, $finish = 60) {
  85    if (isset($form_state['post']['op']) && $form_state['post']['op'] == t('Cancel')) {
  86      drupal_goto("node/{$schedule->nid}/schedule", NULL, "schedule-{$start}");
  87    }
  88    $program_title = '';
  89    if (!empty($schedule_item->program_nid) && $program = node_load($schedule_item->program_nid)) {
  90      $program_title = $program->title;
  91    }
  92  
  93    $form['old_schedule_item'] = array(
  94      '#type' => 'value',
  95      '#value' => $schedule_item,
  96    );
  97    $form['schedule_nid'] = array(
  98      '#type' => 'value',
  99      '#value' => $schedule->nid,
 100    );
 101    $form['iid'] = array(
 102      '#type' => 'value',
 103      '#value' => $schedule_item->iid,
 104    );
 105    $form['range'] = array(
 106      '#type' => 'station_schedule_daytime_range',
 107      '#default_value' => array(
 108        'start' => $schedule_item->start,
 109        'finish' => $schedule_item->finish
 110      ),
 111      '#increment' => $schedule->settings['increment'],
 112    );
 113    $form['program_title'] = array(
 114      '#type' => 'textfield',
 115      '#title' => t('Program'),
 116      '#description' => t("Enter the name of the program."),
 117      '#default_value' => $program_title,
 118      '#maxlength' => 128,
 119      '#autocomplete_path' => 'station/autocomplete/program',
 120    );
 121    $form['may_archive'] = array(
 122      '#type' => 'checkbox',
 123      '#title' => t('Can be saved in Station Archive'),
 124      '#default_value' => $schedule_item->may_archive,
 125      '#description' => t('Checking this indicates that the Station Archive module can save audio recordings of the program at this timeslot to the archive.'),
 126    );
 127  
 128    $form['buttons']['submit'] = array(
 129      '#type' => 'submit',
 130      '#value' => t('Save'),
 131    );
 132    if ($schedule_item->iid) {
 133      $form['buttons']['remove'] = array(
 134        '#type' => 'submit',
 135        '#value' => t('Remove'),
 136        '#submit' => array('station_schedule_item_edit_remove_submit'),
 137      );
 138    }
 139    $form['buttons']['cancel'] = array(
 140      '#type' => 'submit',
 141      '#value' => t('Cancel'),
 142    );
 143  
 144    return $form;
 145  }
 146  
 147  /**
 148   * Button sumit function: handle the 'Remove' button on the item edit form.
 149   */
 150  function station_schedule_item_edit_remove_submit($form, &$form_state) {
 151    $destination = '';
 152    if (isset($_REQUEST['destination'])) {
 153      $destination = drupal_get_destination();
 154      unset($_REQUEST['destination']);
 155    }
 156    $form_state['redirect'] = array('node/'. $form_state['values']['schedule_nid'] .'/schedule/'. $form_state['values']['iid'] .'/remove', $destination);
 157  }
 158  
 159  function station_schedule_item_edit_form_validate($form, &$form_state) {
 160    $start = $form_state['values']['range']['start'];
 161    $finish = $form_state['values']['range']['finish'];
 162  
 163    $result = db_query('SELECT count(*) AS count, min(s.start) AS start, max(s.finish) AS finish FROM {station_schedule_item} s WHERE s.schedule_nid = %d AND s.iid <> %d AND s.finish > %d AND s.start < %d', $form_state['values']['schedule_nid'], $form_state['values']['iid'], $start, $finish);
 164    if ($overlap = db_fetch_object($result)) {
 165      if ($overlap->count == 1) {
 166        form_set_error('', t("The program overlaps another scheduled item at %time.", array('%time' => theme('station_dayhour_range', $overlap->start, $overlap->finish))));
 167      }
 168      elseif ($overlap->count > 1) {
 169        form_set_error('', t("The program overlaps %number scheduled items from %time.", array('%time' => theme('station_dayhour_range', $overlap->start, $overlap->finish), '%number' => $overlap->count)));
 170      }
 171    }
 172  
 173    // check for a valid program title
 174    if (!$prog = node_load(array('title' => $form_state['values']['program_title'], 'type' => 'station_program'))) {
 175      form_set_error('program_title', t('You need to specify a valid program name.'));
 176    }
 177  }
 178  
 179  function station_schedule_item_edit_form_submit($form, &$form_state) {
 180    $program = node_load(array('type' => 'station_program', 'title' => $form_state['values']['program_title']));
 181    $schedule = node_load($form_state['values']['schedule_nid']);
 182  
 183    $record = array(
 184      'iid' => $form_state['values']['iid'],
 185      'schedule_nid' => $form_state['values']['schedule_nid'],
 186      'program_nid' => $program->nid,
 187      'start' => $form_state['values']['range']['start'],
 188      'finish' => $form_state['values']['range']['finish'],
 189      'may_archive' => $form_state['values']['may_archive'],
 190    );
 191  
 192    if ($form_state['values']['iid']) {
 193      drupal_write_record('station_schedule_item', $record, array('iid'));
 194      $old_record = (array) $form_state['values']['old_schedule_item'];
 195      if ($old_record['program_nid'] != $record['program_nid']) {
 196        _station_send_notice('schedule', 'remove', $old_record);
 197        _station_send_notice('schedule', 'add', $record);
 198      }
 199      elseif ($old_record['start'] != $record['start'] || $old_record['finish'] != $record['finish']) {
 200        _station_send_notice('schedule', 'change', $record);
 201      }
 202      drupal_set_message(t('%program was updated on the %schedule schedule.', array('%program' => $program->title, '%schedule' => $schedule->title)));
 203    }
 204    else {
 205      drupal_write_record('station_schedule_item', $record);
 206      _station_send_notice('schedule', 'add', $record);
 207      drupal_set_message(t('%program was added to the %schedule schedule.', array('%program' => $program->title, '%schedule' => $schedule->title)));
 208    }
 209    $form_state['redirect'] = array('node/'. $record['schedule_nid'] .'/schedule', NULL, 'schedule-'. $record['start']);
 210  }
 211  
 212  /**
 213   * Page to confirm the removal of a schedule item.
 214   */
 215  function station_schedule_item_remove_form(&$form_state, $schedule, $schedule_item) {
 216    $program = node_load($schedule_item->program_nid);
 217  
 218    $form['schedule_nid'] = array('#type' => 'value', '#value' => $schedule->nid);
 219    $form['program_nid'] = array('#type' => 'value', '#value' => $schedule_item->program_nid);
 220    $form['iid'] = array('#type' => 'value', '#value' => $schedule_item->iid);
 221    return confirm_form(
 222      $form,
 223      t('Are you sure you want to unschedule %title from %schedule at %time?', array('%title' => $program->title, '%schedule' => $schedule->title, '%time' => theme('station_dayhour_range', $schedule_item->start, $schedule_item->finish))),
 224      isset($_GET['destination']) ? $_GET['destination'] : "node/{$schedule->nid}/schedule/{$schedule_item->iid}/edit",
 225      t('This action cannot be undone, but you can always re-add the program to the schedule.'),
 226      t('Remove'),
 227      t('Cancel')
 228    );
 229  }
 230  
 231  /**
 232   * Delete a schedule item.
 233   */
 234  function station_schedule_item_remove_form_submit($form, &$form_state) {
 235    if ($form_state['values']['confirm']) {
 236      db_query("DELETE FROM {station_schedule_item} WHERE iid = %d", $form_state['values']['iid']);
 237      _station_send_notice('schedule', 'remove', array('schedule_nid' => $form_state['values']['schedule_nid'], 'program_nid' => $form_state['values']['program_nid'], 'iid' => $form_state['values']['iid']));
 238      $form_state['redirect'] = 'node/'. $form_state['values']['schedule_nid'] .'/schedule';
 239    }
 240  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7