--- adsense.module.1.6	2007-06-22 03:25:06.000000000 +0800
+++ adsense.module	2007-12-05 21:15:07.000000000 +0800
@@ -58,6 +58,7 @@ define('ADSENSE_COLOR_URL',             
 define('ADSENSE_ALT',                         'adsense_alt_');
 define('ADSENSE_ALT_INFO',                    'adsense_alt_info_');
 define('ADSENSE_AD_CHANNEL',                  'adsense_ad_channel_');
+define('ADSENSE_AD_CHANNEL_NAME',             'adsense_ad_channel_name_');
 define('ADSENSE_REVENUE_ENABLE',              'adsense_revenue_enable');
 define('ADSENSE_PERCENTAGE_AUTHOR',           'adsense_percentage_author');
 define('ADSENSE_PERCENTAGE_REFER',            'adsense_percentage_refer');
@@ -134,6 +135,46 @@ function adsense_menu($may_cache) {
        'access' => user_access('administer site configuration'),
        'type' => MENU_NORMAL_ITEM,
      );
+     $items[] = array(
+       'path' => 'admin/settings/adsense/general',
+       'title' => t('General settings'),
+       'description' => t('Configure Google AdSense.'),
+       'callback' => 'drupal_get_form',
+       'callback arguments' => 'adsense_admin_settings',
+       'access' => user_access('administer site configuration'),
+       'type' => MENU_DEFAULT_LOCAL_TASK,
+       'weight' => 0,
+     );
+     $items[] = array(
+       'path' => 'admin/settings/adsense/channels',
+       'title' => t('Channels'),
+       'description' => t('Configure Google AdSense Channels.'),
+       'callback' => 'drupal_get_form',
+       'callback arguments' => 'adsense_admin_channels_settings',
+       'access' => user_access('administer site configuration'),
+       'type' => MENU_LOCAL_TASK,
+       'weight' => 1,
+     );
+      $items[] = array(
+       'path' => 'admin/settings/adsense/channels/list',
+       'title' => t('Edit'),
+       'description' => t('List Google AdSense Channels.'),
+       'callback' => 'drupal_get_form',
+       'callback arguments' => 'adsense_admin_channels_settings',
+       'access' => user_access('administer site configuration'),
+       'type' => MENU_DEFAULT_LOCAL_TASK,
+       'weight' => 1,
+     );
+    $items[] = array(
+       'path' => 'admin/settings/adsense/channels/add',
+       'title' => t('Add Channels'),
+       'description' => t('Add Google AdSense Channels.'),
+       'callback' => 'drupal_get_form',
+       'callback arguments' => 'adsense_admin_channels_add_settings',
+       'access' => user_access('administer site configuration'),
+       'type' => MENU_LOCAL_TASK,
+       'weight' => 3,
+     );
    }
    else {
      $items[] = array(
@@ -302,6 +343,7 @@ function adsense_admin_settings() {
     '#description' => t('Enter up to !channels custom channels that you have configured in Google AdSense. If you are not using custom channels, or you are only using URL channels, then leave this empty.', array('!channels' => ADSENSE_MAX_CHANNELS)),
   );
 
+
   for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
     $form['channels'][ADSENSE_AD_CHANNEL . $channel] = array(
       '#type' => 'textfield',
@@ -1206,3 +1248,102 @@ function _adsense_format_path($path, $wi
   return l($title, $path);
 }
 
+function adsense_admin_channels_settings() {
+  // table header
+  $form['header'] = array(
+    '#type' => 'value',
+    '#value' => array(),
+    '#value' => array(),
+  );
+  $form['header']['#value'][] = t('No.');
+  $form['header']['#value'][] = t('Channel ID');
+  $form['header']['#value'][] = t('Channel Name');
+
+  // table body
+  $form['channels'] = array();
+  for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
+    $form['channels'][$channel] = array();
+    $form['channels'][$channel]['no'] = array(
+      '#type' => 'markup',
+      '#value' => $channel,
+    );
+
+    $form['channels'][ADSENSE_AD_CHANNEL . $channel] = array(
+      '#type' => 'textfield',
+      '#default_value' => variable_get(ADSENSE_AD_CHANNEL . $channel, ''),
+      '#size' => 15,
+    );
+
+    $form['channels'][ADSENSE_AD_CHANNEL_NAME . $channel] = array(
+      '#type' => 'textfield',
+      '#default_value' => variable_get(ADSENSE_AD_CHANNEL_NAME . $channel, ''),
+      '#size' => 30,
+    );
+  }
+
+  $form['channels']['#theme'] = 'adsense_channels_settings';
+
+  return system_settings_form($form);
+}
+
+function adsense_admin_channels_add_settings() {
+  $form['channels'][ADSENSE_AD_CHANNEL . $channel] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom channel ID: ') . $channel,
+    '#default_value' => variable_get(ADSENSE_AD_CHANNEL . $channel, ''),
+    '#size' => 30,
+    '#maxlength' => 30,
+  );
+
+  $form['channels'][ADSENSE_AD_CHANNEL_NAME . $channel] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom channel Name: ') . $channel,
+    '#default_value' => variable_get(ADSENSE_AD_CHANNEL_NAME . $channel, ''),
+    '#size' => 30,
+    '#maxlength' => 30,
+  );
+
+  return system_settings_form($form);
+}
+
+function theme_adsense_channels_settings($form) {
+  $header = array(t('No.'), t('Channel ID'), t('Channel Name'));
+
+  $rows = array();
+  for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
+    $row = array();
+    $row[] = array('data' => drupal_render($form[$channel]['no']), 'align' => 'center');
+    $row[] = array('data' => drupal_render($form[ADSENSE_AD_CHANNEL . $channel]), 'align' => 'left');
+    $row[] = array('data' => drupal_render($form[ADSENSE_AD_CHANNEL_NAME . $channel]), 'align' => 'left');
+    $rows[] = $row;
+  }
+  $output = theme('table', $header, $rows);
+  $output .= drupal_render($form);
+
+  return $output;
+}
+
+function theme_adsense_channels_xsettings($form) {
+  // build table body
+  $rows = array();
+  foreach (element_children($form['channels']) as $channel) {
+    $row = array();
+    foreach (element_children($form['channels'][$channel]) as $key) {
+      $row[] = drupal_render($form['channels'][$channel][$key]);
+    }
+    $rows[] = $row;
+  }
+  // build table header
+  $header = array();
+  foreach ($form['header']['#value'] as $cell) {
+    if ($cell == t('Enabled')) {
+      // add JavaScript 'select all/select none' stuff
+      $header[] = array('data' => $cell) + theme('table_select_header_cell');
+    }
+    else {
+      $header[] = $cell;
+    }
+  }
+  // return themed table
+  return theme('table', $header, $rows);
+}
