You are here

function ad_channel_form_alter in Advertisement 6.3

Same name and namespace in other branches
  1. 5.2 channel/ad_channel.module \ad_channel_form_alter()
  2. 6.2 channel/ad_channel.module \ad_channel_form_alter()
  3. 7 channel/ad_channel.module \ad_channel_form_alter()

Implementation of hook_form_alter(). Generate a form for selecting channels to associate with an advertisement.

1 string reference to 'ad_channel_form_alter'
ad_weight_probability_form_alter in weight/probability/ad_weight_probability.module
Implementation of hook_form_alter(). Generate a form for assigning a weight to an advertisement.

File

channel/ad_channel.module, line 123
Ad Channel module.

Code

function ad_channel_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['type']) && $form_id == 'ad_node_form') {
    $fieldset = FALSE;
    $containers = _ad_channel_get_containers();
    foreach ($containers as $container) {
      $channels = _ad_channel_get_container_channels($container->conid);
      if (!empty($channels)) {
        if ($container->conid) {
          $fieldset = TRUE;
        }
        if ($fieldset) {
          $form['channel'][$container->conid] = array(
            '#type' => 'fieldset',
            '#title' => $container->name,
            '#collapsible' => FALSE,
            '#collapsed' => FALSE,
          );
        }
        foreach ($channels as $channel) {
          if (is_object($form['#node'])) {
            $node = $form['#node'];
            $default_value = isset($node->channel[$channel->chid]);
          }
          else {
            $default_value = 0;
          }
          $form['channel'][$container->conid]["channel-{$channel->chid}"] = array(
            '#type' => 'checkbox',
            '#title' => $channel->name,
            '#description' => $channel->description,
            '#default_value' => $default_value,
            '#disabled' => isset($disabled) ? $disabled : FALSE,
          );
        }
      }
    }
    $node = node_load($form['nid']['#value']);
    if (isset($form['channel']) && is_array($form['channel']) && !empty($form['channel'])) {
      $form['channel'] += array(
        '#type' => 'fieldset',
        '#title' => t('Channels'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
      );
      $form['channel']['#weight'] = -2;
      $form['channel']['#tree'] = TRUE;
    }
    $form['priority'] = array(
      '#type' => 'fieldset',
      '#access' => user_access('configure ad premier status'),
      '#title' => t('Priority'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['priority']['premiere'] = array(
      '#type' => 'checkbox',
      '#access' => user_access('configure ad premier status'),
      '#title' => t('Premiere'),
      '#description' => t('An active premiere advertisement will override all other non-premiere advertisements in the same channel.  As long as one or more premiere advertisements are active in a channel, non-premiere advertisements will not be displayed in that channel.'),
      '#default_value' => isset($node->premiere) ? $node->premiere : FALSE,
    );
    $form['priority']['#weight'] = -1;
    $form['inventory'] = array(
      '#type' => 'fieldset',
      '#title' => t('Inventory'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['inventory']['remnant'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remnant'),
      '#description' => t('An advertisement marked as a remnant is eligible for display in any channel where the number of assigned advertisements for the channel is less than the inventory level specified.'),
      '#default_value' => isset($node->remnant) ? $node->remnant : FALSE,
    );
  }
  else {
    if ($form_id == 'ad_filter_form') {
      $session =& $_SESSION['ad_overview_filter'];
      $session = is_array($session) ? $session : array();
      $display_channel = TRUE;
      $display_premiere = TRUE;
      foreach ($session as $filter) {
        list($type, $value) = $filter;
        if ($type == 'channel') {
          $display_channel = FALSE;
        }
        else {
          if ($type == 'premiere') {
            $display_premiere = FALSE;
          }
        }
      }
      if ($display_channel) {
        $channels = _ad_channel_get_channels();
        $options = array();
        $options['channel-0'] = t('<none>');
        foreach ($channels as $channel) {
          $key = 'channel-' . $channel->chid;
          $options[$key] = $channel->name;
        }
        $form['filters']['status']['channel'] = array(
          '#type' => 'select',
          '#options' => $options,
        );
        $form['filters']['filter']['#options']['channel'] = 'channel';
      }
      else {
        unset($form['filters']['status']['channel']);
        unset($form['filters']['filter']['#options']['channel']);
      }
      if ($display_premiere) {
        $options = array(
          '0' => t('false'),
          '1' => t('true'),
        );
        $form['filters']['status']['premiere'] = array(
          '#type' => 'select',
          '#options' => $options,
        );
        $form['filters']['filter']['#options']['premiere'] = 'premiere';
      }
      else {
        unset($form['filters']['status']['premiere']);
        unset($form['filters']['filter']['#options']['premiere']);
      }
    }
    else {
      if ($form_id == 'ad_report_admin') {
        $channels = _ad_channel_get_channels();
        if (is_array($channels) && !empty($channels)) {
          $channel = isset($_SESSION['ad_report_channel']) && is_array($_SESSION['ad_report_channel']) && !empty($_SESSION['ad_report_channel']) ? $_SESSION['ad_report_channel'] : array(
            'any',
          );
          $form['channels'] = array(
            '#type' => 'fieldset',
            '#title' => t('Channels'),
          );
          $options = array();
          $options['any'] = t('<any>');
          $options['none'] = t('<none>');
          foreach ($channels as $chan) {
            $options[$chan->chid] = $chan->name;
          }
          $form['channels']['channel'] = array(
            '#type' => 'select',
            '#title' => t('Ad channels'),
            '#options' => $options,
            '#multiple' => TRUE,
            '#required' => TRUE,
            '#default_value' => $channel,
          );
          $form['#submit'] = array_merge(array(
            'ad_channel_admin_report_submit',
          ), $form['#submit']);
        }
      }
      else {
        if ($form_id == 'ad_admin_ads' && is_array($form['group'])) {
          foreach ($form['group'] as $aid => $value) {
            $result = db_query('SELECT chid FROM {ad_channel_node} WHERE nid = %d', $aid);
            $names = array();
            while ($channel = db_fetch_object($result)) {
              $names[] = _ad_channel_get_name($channel->chid);
            }
            if (empty($names)) {
              $names[] = t('none');
            }
            $list = variable_get('ad_channel_admin_list', AD_CHANNEL_LIST_CHANNEL);
            switch ($list) {
              case AD_CHANNEL_LIST_CHANNEL:
                unset($form['group']);
                $form['channel'][$aid]['#value'] = implode(', ', $names);
                break;
              case AD_CHANNEL_LIST_BOTH:
                $form['channel'][$aid]['#value'] = implode(', ', $names);
                break;
              case AD_CHANNEL_LIST_GROUP:

                // do nothing
                break;
            }
          }
        }
      }
    }
  }
}