You are here

function ad_channel_admin_channel_submit in Advertisement 6.3

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

Save the channel.

File

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

Code

function ad_channel_admin_channel_submit($form, &$form_state) {

  // remove extraneous white space from url list which can break matching
  $url_array = explode("\n", $form_state['values']['urls']);
  if (is_array($url_array)) {
    foreach ($url_array as $url) {
      $urls[] = trim($url);
    }
    $urls = implode("\n", $urls);
  }
  else {
    $urls = '';
  }
  switch ($form_state['values']['op']) {
    case t('Create'):
      db_query("INSERT INTO {ad_channel} (name, description, conid, weight, display, no_channel_percent, urls, groups, inventory) VALUES('%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d)", $form_state['values']['name'], $form_state['values']['description'], $form_state['values']['conid'], $form_state['values']['weight'], $form_state['values']['display'], $form_state['values']['no_channel_percent'], serialize($urls), serialize($form_state['values']['groups']), $form_state['values']['inventory']);
      drupal_set_message(t('The %name channel has been created.', array(
        '%name' => $form_state['values']['name'],
      )));
      break;
    case t('Update'):
      $groups = array();

      // Don't store information about groups that no longer exist.
      if (is_array($form_state['values']['groups'])) {
        $ad_groups = taxonomy_get_tree(_ad_get_vid());
        foreach ($ad_groups as $ad_group) {
          if (isset($form_state['values']['groups'][$ad_group->tid])) {
            $groups[$ad_group->tid] = $form_state['values']['groups'][$ad_group->tid];
          }
        }
      }
      db_query("UPDATE {ad_channel} SET name = '%s', description = '%s', conid = %d, weight = %d, display = %d, urls = '%s', groups = '%s', no_channel_percent = %d, inventory = %d WHERE chid = %d", $form_state['values']['name'], $form_state['values']['description'], $form_state['values']['conid'], $form_state['values']['weight'], $form_state['values']['display'], serialize($urls), serialize($groups), $form_state['values']['no_channel_percent'], $form_state['values']['inventory'], $form_state['values']['chid']);
      drupal_set_message(t('The %name channel has been updated.', array(
        '%name' => $form_state['values']['name'],
      )));
      break;
    case t('Delete'):
      drupal_goto('admin/content/ad/channel/channel/' . $form_state['values']['chid'] . '/delete');
  }
  drupal_goto('admin/content/ad/channel');
}