You are here

function ad_channel_admin_channel in Advertisement 5.2

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

Administrative page for creating or editing channels.

1 string reference to 'ad_channel_admin_channel'
ad_channel_menu in channel/ad_channel.module
Implementation of hook_menu.

File

channel/ad_channel.module, line 599
Ad Channel

Code

function ad_channel_admin_channel($chid = 0) {
  $form = array();
  if ($chid) {
    $channel = _ad_channel_get_channels($chid);
    if (empty($channel)) {
      drupal_goto('admin/content/ad/channel');
    }
    $form['chid'] = array(
      '#type' => 'hidden',
      '#value' => $chid,
    );
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Channel name'),
    '#description' => t('Enter a short, descriptive name for your channel.'),
    '#default_value' => $chid ? $channel->name : '',
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Enter a full description of your channel.'),
    '#default_value' => $chid ? $channel->description : '',
  );
  $result = db_query('SELECT conid, name FROM {ad_channel_container} ORDER BY weight ASC');
  $containers = array(
    t('<none>'),
  );
  while ($container = db_fetch_object($result)) {
    $containers[$container->conid] = $container->name;
  }
  if (sizeof($containers) == 1) {
    $containers = array(
      t('No containers have been created.'),
    );
  }
  $form['conid'] = array(
    '#type' => 'select',
    '#title' => t('Container'),
    '#options' => $containers,
    '#description' => t('Optionally assign your channel to a container.  Containers can be used to help organize your channels, but they are not required.'),
    '#default_value' => $chid ? $channel->conid : 0,
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#description' => t('When listing channels, those with the lighter (smaller) weights get listed before channels with heavier (larger) weights.  Channels with equal weights are sorted alphabetically.'),
    '#default_value' => $chid ? $channel->weight : 0,
  );

  // URL rules
  $form['URL_rules'] = array(
    '#type' => 'fieldset',
    '#title' => t('URL rules'),
    '#collapsible' => TRUE,
    '#collasped' => FALSE,
  );
  $form['URL_rules']['display'] = array(
    '#type' => 'radios',
    '#title' => t('Display advertisements from this channel on specific URLs'),
    '#options' => array(
      t('Display advertisements on every URL except the listed URLs.'),
      t('Display advertisements only on the listed URLs.'),
    ),
    '#default_value' => $chid ? $channel->display : 0,
  );
  $form['URL_rules']['urls'] = array(
    '#type' => 'textarea',
    '#title' => t('Paths'),
    '#description' => t("Enter one URL per line, including the 'http://' or 'https:/'.  The '*' character is a wildcard.  Example URLs are <em>http://www.example.com/blog</em> for the blog page and <em>http://www.example.com/blog/*</em> for every personal blog."),
    '#default_value' => $chid ? unserialize($channel->urls) : '',
  );

  // Group rules
  $groups = taxonomy_get_tree(_ad_get_vid());
  $collapsed = is_array($groups) && !empty($groups) ? FALSE : TRUE;
  $form['group_rules'] = array(
    '#type' => 'fieldset',
    '#title' => t('Ad group rules'),
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
  );
  if (!$collapsed) {
    foreach ($groups as $group) {
      $options[$group->tid] = $group->name;
    }
    $form['group_rules']['groups'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Allow advertisements from specific ad groups'),
      '#options' => $options,
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#description' => t('By selecting one or more groups, only advertisements from the selected group(s) will be allowed to be added to this channel.  If no groups are selected, any advertisement can be added to this channel regardless of its group.'),
      '#default_value' => $chid ? unserialize($channel->groups) : '',
    );
  }
  else {
    $form['group_rules']['none'] = array(
      '#type' => 'markup',
      '#value' => t('No ad groups have been created.'),
      '#prefix' => '<div>',
      '#suffix' => '</div>',
    );
  }
  if ($chid) {
    $form['update'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
    );
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  else {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Create'),
    );
  }
  $form['cancel'] = array(
    '#type' => 'markup',
    '#value' => l(t('Cancel'), 'admin/content/ad/channel'),
  );
  return $form;
}