Index: getsatisfaction.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/getsatisfaction/getsatisfaction.module,v
retrieving revision 1.9
diff -u -r1.9 getsatisfaction.module
--- getsatisfaction.module	20 Dec 2010 13:17:21 -0000	1.9
+++ getsatisfaction.module	29 Dec 2010 22:41:55 -0000
@@ -3,10 +3,15 @@
 
 /**
  * @file
- * Adds GetSatisfaction javascript code to your site.
+ * Adds GetSatisfaction integration to your site.
  */
 
 /**
+ * Define constants.
+ */
+define('GETSATISFACTION_API_BASE', 'http://api.getsatisfaction.com');
+
+/**
  * Implementation of hook_help().
  */
 function getsatisfaction_help($path, $arg) {
@@ -20,7 +25,7 @@
  * Implementation of hook_perm().
  */
 function getsatisfaction_perm() {
-  return array('administer get satisfaction');
+  return array('administer get satisfaction', 'access get satisfaction feedback page');
 }
 
 /**
@@ -29,11 +34,68 @@
 function getsatisfaction_menu() {
   $items['admin/settings/getsatisfaction'] = array(
     'title' => 'Get Satisfaction',
-    'description' => 'Configure the settings used to generate your Get Satisfaction code.',
+    'description' => 'Configure the settings used to integrate your Get Satisfaction community.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('getsatisfaction_admin_settings_form'),
     'access arguments' => array('administer get satisfaction'),
     'type' => MENU_NORMAL_ITEM,
+    'file' => 'getsatisfaction.admin.inc',
+  );
+  $items['admin/settings/getsatisfaction/settings'] = array(
+    'title' => 'Settings',
+    'description' => 'Configure the general settings used to integrate your Get Satisfaction community.',
+    'access arguments' => array('administer get satisfaction'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  $items['admin/settings/getsatisfaction/widgets'] = array(
+    'title' => 'Widgets',
+    'description' => 'Configure your Get Satisfaction widgets.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('getsatisfaction_widget_feedback_tab_form'),
+    'access arguments' => array('administer get satisfaction'),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'getsatisfaction.admin.inc',
+  );
+  $items['admin/settings/getsatisfaction/widgets/feedback-tab'] = array(
+    'title' => 'Feedback Tab',
+    'description' => 'Configure your Get Satisfaction Feedback Tab.',
+    'access arguments' => array('administer get satisfaction'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -20,
+  );
+  $items['admin/settings/getsatisfaction/widgets/feedback-page'] = array(
+    'title' => 'Feedback Page',
+    'description' => 'Configure your Get Satisfaction widgets.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('getsatisfaction_widget_feedback_page_form'),
+    'access arguments' => array('administer get satisfaction'),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'getsatisfaction.admin.inc',
+    'weight' => -10,
+  );
+
+  // Create feedback page if a path was supplied in the configuration.
+  $feedback_page = _getsatisfaction_settings('getsatisfaction_widget_feedback_page');
+  if (!empty($feedback_page['page']['path'])) {
+    $items[trim($feedback_page['page']['path'])] = array(
+      'title' => check_plain($feedback_page['page']['title']),
+      'page callback' => 'getsatisfaction_feedback_page',
+      'access arguments' => array('access get satisfaction feedback page'),
+      'type' => MENU_NORMAL_ITEM,
+    );
+  }
+
+  return $items;
+}
+
+/**
+ * Implementation hook_theme().
+ */
+function getsatisfaction_theme() {
+  $items = array();
+
+  $items['getsatisfaction_feedback_widget'] = array(
+    'arguments' => array('type' => 'feedback_tab'),
   );
 
   return $items;
@@ -41,17 +103,49 @@
 
 /**
  * Implementation of hook_init().
- * 
+ *
  * It is necessary to call drupal_add_js() at least once before hook_footer to trigger inclusion of jQuery libs. It also makes
  * code cleaner than including GetSatisfaction original code.
  */
 function getsatisfaction_init() {
+  // General Settings.
   $conf = array();
-  $conf['display']   = "overlay";
-  $conf['company']   = check_plain(variable_get('getsatisfaction_name', ''));
-  $conf['placement'] = check_plain(variable_get('getsatisfaction_placement', 'left'));
-  $conf['color']     = check_plain(variable_get('getsatisfaction_color', '#222'));
-  $conf['style']     = check_plain(variable_get('getsatisfaction_type', 'idea'));
+
+  // Feedback Tab
+  $feedback_tab = _getsatisfaction_settings('getsatisfaction_widget_feedback_tab');
+  $conf['feedback_tab'] = $feedback_tab['widget'];
+  $conf['feedback_tab']['display']   = "overlay";
+  $conf['feedback_tab']['company']   = variable_get('getsatisfaction_name', '');
+  if (!empty($conf['feedback_tab']['custom_css'])) {
+    if (!menu_path_is_external($conf['feedback_tab']['custom_css'])) {
+      $conf['feedback_tab']['custom_css'] = url($conf['feedback_tab']['custom_css'], array('absolute' => TRUE));
+    }
+  }
+  if (!empty($conf['feedback_tab']['custom_ie_css'])) {
+    if (!menu_path_is_external($conf['feedback_tab']['custom_ie_css'])) {
+      $conf['feedback_tab']['custom_ie_css'] = url($conf['feedback_tab']['custom_ie_css'], array('absolute' => TRUE));
+    }
+  }
+
+  // Feedback Page
+  $feedback_page = _getsatisfaction_settings('getsatisfaction_widget_feedback_page');
+  $conf['feedback_page'] = $feedback_page['widget'];
+  $conf['feedback_page']['display']   = "inline";
+  $conf['feedback_page']['company']   = variable_get('getsatisfaction_name', '');
+  if (!empty($conf['feedback_page']['custom_css'])) {
+    if (!menu_path_is_external($conf['feedback_page']['custom_css'])) {
+      $conf['feedback_page']['custom_css'] = url($conf['feedback_page']['custom_css'], array('absolute' => TRUE));
+    }
+  }
+  if (!empty($conf['feedback_page']['custom_ie_css'])) {
+    if (!menu_path_is_external($conf['feedback_page']['custom_ie_css'])) {
+      $conf['feedback_page']['custom_ie_css'] = url($conf['feedback_page']['custom_ie_css'], array('absolute' => TRUE));
+    }
+  }
+
+  // Sanitize settings.
+  _getsatisfaction_sanitize($conf);
+
   drupal_add_js(array('getsatisfaction' => $conf), 'setting');
 }
 
@@ -60,19 +154,8 @@
  */
 function getsatisfaction_footer() {
   $company = check_plain(variable_get('getsatisfaction_name', ''));
-  if (!empty($company) && _getsatisfaction_visibility_pages()) {
-    $script  = 'var is_ssl = ("https:" == document.location.protocol);';
-    $script .= 'var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/";';
-    $script .= 'document.write(unescape("%3Cscript src=\'" + asset_host + "javascripts/feedback-v2.js\' type=\'text/javascript\'%3E%3C/script%3E"));';
-    drupal_add_js($script, 'inline', 'footer'); // Need to make 2 script tags in order to have the library loaded when the second is executed.
-    
-    $script  = '';
-    $script .= '$("body:not(.getsatisfaction-processed)").each(function() {';
-    $script .= '  $(this).addClass("getsatisfaction-processed");';
-    $script .= '  var feedback_widget = new GSFN.feedback_widget(Drupal.settings.getsatisfaction);';
-    $script .= '});';
-    
-    drupal_add_js($script, 'inline', 'footer');
+  if (!empty($company) && _getsatisfaction_feedback_tab_visibility_pages()) {
+    return theme('getsatisfaction_feedback_widget', 'feedback_tab');
   }
 }
 
@@ -88,8 +171,9 @@
     case 'process':
       $company = check_plain(variable_get('getsatisfaction_name', ''));
       if (!empty($company)) {
-        $getsatisfaction_page = '<iframe id="fdbk_iframe_inline" allowTransparency="true" width="100%" height="500" scrolling="no" frameborder="0" src="http://getsatisfaction.com/'. $company .'/feedback/topics/new?display=inline&amp;style=idea"></iframe>';
-       $text = preg_replace("@\[getsatisfaction-page\]@", $getsatisfaction_page, $text);
+        //$getsatisfaction_page = '<iframe id="fdbk_iframe_inline" allowTransparency="true" width="100%" height="500" scrolling="no" frameborder="0" src="http://getsatisfaction.com/'. $company .'/feedback/topics/new?display=inline&amp;style=idea"></iframe>';
+        $getsatisfaction_page = theme('getsatisfaction_feedback_widget', 'feedback_page');
+        $text = preg_replace("@\[getsatisfaction-page\]@", $getsatisfaction_page, $text);
       }
       return $text;
     default:
@@ -109,90 +193,170 @@
 }
 
 /**
- * Implementation of hook_admin_settings() for configuring the module
+ * Implementation of hook_block().
+ */
+function getsatisfaction_block($op = 'list', $delta = 0, $edit = array()) {
+  switch ($op) {
+    case 'list':
+      $blocks = array();
+      $blocks['feedback_page'] = array(
+        'info' => t('Get Satisfaction - Feedback Page'),
+        'cache' => BLOCK_NO_CACHE,
+      );
+      return $blocks;
+
+    case 'view':
+      $block = array();
+      switch ($delta) {
+        case 'feedback_page':
+          $company = check_plain(variable_get('getsatisfaction_name', ''));
+          if (!empty($company)) {
+            $block['subject'] = t('Feedback');
+            $block['content'] = theme('getsatisfaction_feedback_widget', 'feedback_page');
+          }
+          else {
+            $block['content'] = t('Get Satisfaction not configured.');
+          }
+      }
+      return $block;
+  }
+}
+
+/**
+ * Output the feedback page.
+ */
+function getsatisfaction_feedback_page() {
+  $company = check_plain(variable_get('getsatisfaction_name', ''));
+  if (!empty($company)) {
+    return theme('getsatisfaction_feedback_widget', 'feedback_page');
+  }
+  else {
+    return '';
+  }
+}
+
+/**
+ * Output the Get Satisfaction feedback widget.
+ */
+function theme_getsatisfaction_feedback_widget($type = 'feedback_tab') {
+  $output = '';
+
+  // Load the feedback library (only once per page).
+  $output .= <<<EOD
+<script type="text/javascript" charset="utf-8">
+  $("body:not(.getsatisfaction-processed)").each(function() {
+    $(this).addClass("getsatisfaction-processed");
+    var is_ssl = ("https:" == document.location.protocol);
+    var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/";
+    document.write(unescape('%3Cscript src="' + asset_host + 'javascripts/feedback-v2.js" type="text/javascript"%3E%3C/script%3E'));
+  });
+</script>
+
+EOD;
+
+  // Extra settings.
+  $extra = "\n";
+  // Domain alias.
+  $domain = variable_get('getsatisfaction_domain_alias', '');
+  if (_getsatisfaction_plan_can('use domain alias') && !empty($domain)) {
+    $extra .= '  GSFN.feedback_widget.prototype.local_base_url = "http://' . $domain . '";' . "\n";
+    $extra .= '  GSFN.feedback_widget.prototype.local_ssl_base_url = "http://' . $domain . '";' . "\n";
+  }
+
+  // Output the widget.
+  $output .= <<<EOD
+<script type="text/javascript" charset="utf-8">
+$extra
+  var feedback_widget = new GSFN.feedback_widget(Drupal.settings.getsatisfaction.{$type});
+</script>
+
+EOD;
+
+  return $output;
+}
+
+/**
+ * Helper function to fetch settings and defaults.
+ */
+function _getsatisfaction_settings($setting) {
+  switch ($setting) {
+    case 'getsatisfaction_widget_feedback_tab':
+      return variable_get($setting, array(
+        'widget' => array(
+          'product' => '',
+          'tag' => '',
+          'style' => 'idea',
+          'placement' => 'left',
+          'color' => '#222',
+          'limit' => 3,
+          'custom_css' => '',
+          'custom_ie_css' => '',
+        ),
+        'vis_settings' => array(
+          'visibility' => 0,
+          'pages' => '',
+        ),
+      ));
+
+    case 'getsatisfaction_widget_feedback_page':
+      return variable_get($setting, array(
+        'widget' => array(
+          'product' => '',
+          'tag' => '',
+          'style' => 'idea',
+          'limit' => 3,
+          'custom_css' => '',
+          'custom_ie_css' => '',
+        ),
+        'page' => array(
+          'path' => '',
+          'title' => t('Feedback'),
+        ),
+      ));
+
+    default:
+      return variable_get($setting, NULL);
+  }
+}
+
+/**
+ * Recursive helper function for sanitizing settings.
  */
-function getsatisfaction_admin_settings_form(&$form_state) {
-  $form['account'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('General settings'),
-    '#collapsible' => FALSE,
-  );
-
-  $form['account']['getsatisfaction_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Get Satisfaction company name'),
-    '#default_value' => variable_get('getsatisfaction_name', ''),
-    '#size' => 20,
-    '#maxlength' => 255,
-    '#required' => TRUE,
-    '#description' => t('The company name you have picked when you have created its profile at Get Satisfaction. See the list of all your companies on <a href="@url">Get Satisfaction</a> clicking the "You" menu and selecting "Your Products and Companies". You need to be logged in.', array('@url' => 'http://www.getsatisfaction.com/')),
-  );
-  
-  $form['account']['getsatisfaction_type'] = array(
-    '#type' => 'radios',
-    '#title' => t('Default type'),
-    '#default_value' => variable_get('getsatisfaction_type', 'idea'),
-    '#options' => array(
-      'idea' => t('Idea'),
-      'question' => t('Question'),
-      'problem' => t('Problem'),
-      'praise' => t('Praise'),
-    ),
-    '#attributes' => array('class' => 'container-inline')
-  );
-  
-  $form['account']['getsatisfaction_placement'] = array(
-    '#type' => 'radios',
-    '#title' => t('Placement'),
-    '#default_value' => variable_get('getsatisfaction_placement', 'left'),
-    '#options' => array(
-      'left' => t('Left'),
-      'right' => t('Right'),
-      'bottom' => t('Bottom'),
-      'hidden' => t('Hidden'),
-    ),
-    '#attributes' => array('class' => 'container-inline')
-  );
-  
-  $form['account']['getsatisfaction_color'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Tab color'),
-    '#default_value' => variable_get('getsatisfaction_color', '#222'),
-    '#size' => 8,
-    '#field_suffix' => t(' HEX or color'),
-    '#attributes' => array('class' => 'container-inline')
-  );
-  
-  $options = array(t('Add to every page except the listed pages.'), t('Add to the listed pages only.'));
-  $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
-  $pages = variable_get('getsatisfaction_pages', '');
-  $visibility = variable_get('getsatisfaction_visibility', 0);
-
-  $form['code_vis_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Page specific settings'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-  $form['code_vis_settings']['getsatisfaction_visibility'] = array(
-    '#type' => 'radios',
-    '#title' => t('Add code to specific pages'),
-    '#options' => $options,
-    '#default_value' => $visibility,
-  );
-  $form['code_vis_settings']['getsatisfaction_pages'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Pages'),
-    '#default_value' => $pages,
-    '#description' => $description,
-    '#wysiwyg' => FALSE,
-  );
-  return system_settings_form($form);
-}
-
-function _getsatisfaction_visibility_pages() {
-  $visibility = variable_get('getsatisfaction_visibility', 0);
-  $pages = variable_get('getsatisfaction_pages', '');
+function _getsatisfaction_sanitize(&$values) {
+  if (is_array($values)) {
+    foreach ($values as $key => $val) {
+      _getsatisfaction_sanitize($values[$key]);
+    }
+  }
+  else {
+    $values = check_plain($values);
+  }
+}
+
+/**
+ * Helper function to see if this site's plan has access to a feature.
+ */
+function _getsatisfaction_plan_can($feature) {
+  $plan = variable_get('getsatisfaction_plan', 'free');
+  switch ($feature) {
+    case 'use domain alias':
+      return in_array($plan, array('connect', 'integrate', 'enterprise'));
+
+    case 'use product widgets':
+      return in_array($plan, array('connect', 'integrate', 'enterprise'));
+
+    default:
+      return TRUE;
+  }
+}
+
+/**
+ * Helper function to check if the feedback tab is visible on the current page.
+ */
+function _getsatisfaction_feedback_tab_visibility_pages() {
+  $feedback_tab = _getsatisfaction_settings('getsatisfaction_widget_feedback_tab');
+  $visibility = $feedback_tab['vis_settings']['visibility'];
+  $pages = $feedback_tab['vis_settings']['pages'];
 
   // Match path if necessary.
   if (!empty($pages)) {
@@ -213,3 +377,36 @@
 
   return $page_match;
 }
+
+/**
+ * Make an API request and return the results.
+ *
+ * @param $method
+ *  The method to perform.  Example "companies/[company]"
+ *
+ * Certain tokens will be replaced:
+ *  [company] = The configured Get Satisfaction company for this site.
+ */
+function _getsatisfaction_api($method) {
+  $method = strtr($method, array(
+    '[company]' => variable_get('getsatisfaction_name', ''),
+  ));
+  $url = GETSATISFACTION_API_BASE . '/' . $method . '.json';
+  if ($result = drupal_http_request($url)) {
+    if ($result->code == '200') {
+      if ($data = json_decode($result->data)) {
+        return $data;
+      }
+      else {
+        drupal_set_message(t('Error decoding Get Satisfaction API request'), 'error');
+      }
+    }
+    else {
+      drupal_set_message(t('Error making Get Satisfaction API request.  Returned with code: %code', array('%code' => $result->code)), 'error');
+    }
+  }
+  return FALSE;
+}
+
+
+
Index: getsatisfaction.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/getsatisfaction/getsatisfaction.install,v
retrieving revision 1.1
diff -u -r1.1 getsatisfaction.install
--- getsatisfaction.install	11 Dec 2008 11:11:02 -0000	1.1
+++ getsatisfaction.install	29 Dec 2010 22:41:55 -0000
@@ -29,3 +29,56 @@
   variable_del('getsatisfaction_name');
   variable_del('getsatisfaction_visibility');
 }
+
+/**
+ * Update 6001.
+ * Migrate old settings variables to new structure.
+ */
+function getsatisfaction_update_6001() {
+  $ret = array();
+
+  // Set new feedback_tab settings variable.
+  $feedback_tab_settings = array(
+    'widget' => array(
+      'product' => '',
+      'tag' => '',
+      'style' => variable_get('getsatisfaction_type', 'idea'),
+      'placement' => variable_get('getsatisfaction_placement', 'left'),
+      'color' => variable_get('getsatisfaction_color', '#222'),
+      'limit' => 3,
+      'custom_css' => '',
+      'custom_ie_css' => '',
+    ),
+    'vis_settings' => array(
+      'visibility' => variable_get('getsatisfaction_visibility', 0),
+      'pages' => variable_get('getsatisfaction_pages', ''),
+    ),
+  );
+  variable_set('getsatisfaction_widget_feedback_tab', $feedback_tab_settings);
+
+  // Set new feedback_page settings variable.
+  $feedback_page_settings = array(
+    'widget' => array(
+      'product' => '',
+      'tag' => '',
+      'style' => variable_get('getsatisfaction_type', 'idea'),
+      'limit' => 3,
+      'custom_css' => '',
+      'custom_ie_css' => '',
+    ),
+    'page' => array(
+      'path' => '',
+      'title' => t('Feedback'),
+    ),
+  );
+  variable_set('getsatisfaction_widget_feedback_page', $feedback_page_settings);
+
+  // Delete old variables.
+  variable_del('getsatisfaction_type');
+  variable_del('getsatisfaction_placement');
+  variable_del('getsatisfaction_color');
+  variable_del('getsatisfaction_visibility');
+  variable_del('getsatisfaction_pages');
+
+  return $ret;
+}
\ No newline at end of file
Index: .cvsignore
===================================================================
RCS file: .cvsignore
diff -N .cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ .cvsignore	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,3 @@
+.buildpath
+.project
+.settings
\ No newline at end of file
Index: getsatisfaction.admin.inc
===================================================================
RCS file: getsatisfaction.admin.inc
diff -N getsatisfaction.admin.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ getsatisfaction.admin.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,288 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Admin settings forms for GetSatisfaction integration.
+ */
+
+/**
+ * Form callback for configuring the general settings.
+ */
+function getsatisfaction_admin_settings_form(&$form_state) {
+  $form['general'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('General Settings'),
+  );
+  $form['general']['getsatisfaction_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Get Satisfaction company name'),
+    '#default_value' => variable_get('getsatisfaction_name', ''),
+    '#size' => 20,
+    '#maxlength' => 255,
+    '#required' => TRUE,
+    '#description' => t('The company name you have picked when you have created its profile at Get Satisfaction. See the list of all your companies on <a href="@url">Get Satisfaction</a> clicking the "You" menu and selecting "Your Products and Companies". You need to be logged in.', array('@url' => 'http://www.getsatisfaction.com/')),
+  );
+  $form['general']['getsatisfaction_plan'] = array(
+    '#type' => 'radios',
+    '#title' => t('Get Satisfaction plan'),
+    '#description' => t('Some widgets and setting may depend on your plan.  Please select you plan.'),
+    '#options' => array(
+      'free' => t('Free'),
+      'start' => t('Start/Grow'),
+      'connect' => t('Connect'),
+      'integrate' => t('Integrate'),
+      'enterprise' => t('Enterprise'),
+    ),
+    '#required' => TRUE,
+    '#default_value' => variable_get('getsatisfaction_plan', 'free'),
+  );
+
+  $form['plan'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Plan-Specific Settings'),
+    '#description' => t('If there are any specific settings for your plan, they will appear here.'),
+  );
+
+  if (_getsatisfaction_plan_can('use domain alias')) {
+    $form['plan']['getsatisfaction_domain_alias'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Domain Alias'),
+      '#description' => t('If your company is using a Get Satisfaction domain alias, please enter it here.  Example: %example', array('%example' => 'community.mydomain.com')),
+      '#default_value' => variable_get('getsatisfaction_domain_alias', ''),
+    );
+  }
+
+  return system_settings_form($form);
+}
+
+/**
+ * Form callback for configuring the Feedback Tab widget.
+ */
+function getsatisfaction_widget_feedback_tab_form($form_state) {
+  // All settings for this widget will be stored in one variable.
+  $full['getsatisfaction_widget_feedback_tab'] = array(
+    '#tree' => TRUE
+  );
+  $form = &$full['getsatisfaction_widget_feedback_tab'];
+
+  // Get saved/defaults.
+  $defaults = _getsatisfaction_settings('getsatisfaction_widget_feedback_tab');
+
+  $form['widget'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Widget settings'),
+    '#collapsible' => FALSE,
+  );
+
+  if (_getsatisfaction_plan_can('use product widgets')) {
+    if (($products = _getsatisfaction_api('companies/[company]/products')) && ($company = variable_get('getsatisfaction_name', FALSE))) {
+      if (!empty($products->data)) {
+        $form['widget']['product'] = array(
+          '#type' => 'select',
+          '#title' => t('Product'),
+          '#default_value' => isset($defaults['widget']['product']) ? $defaults['widget']['product'] : '',
+          '#options' => array(
+            '' => '-- none --',
+          ),
+        );
+        foreach ($products->data as $product) {
+          $key = $company . '_' . strtolower(str_replace(' ', '_', $product->name));
+          $form['widget']['product']['#options'][$key] = $product->name;
+        }
+      }
+    }
+    $form['widget']['tag'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Tag'),
+      '#description' => t('Optional. No Spaces. Enter a tag to filter feedback to.'),
+      '#default_value' => $defaults['widget']['tag'],
+      '#size' => 16,
+    );
+  }
+
+  $form['widget']['style'] = array(
+    '#type' => 'radios',
+    '#title' => t('Default type'),
+    '#default_value' => $defaults['widget']['style'],
+    '#options' => array(
+      'idea' => t('Idea'),
+      'question' => t('Question'),
+      'problem' => t('Problem'),
+      'praise' => t('Praise'),
+    ),
+    '#attributes' => array('class' => 'container-inline')
+  );
+  $form['widget']['placement'] = array(
+    '#type' => 'radios',
+    '#title' => t('Placement'),
+    '#default_value' => $defaults['widget']['placement'],
+    '#options' => array(
+      'left' => t('Left'),
+      'right' => t('Right'),
+      'bottom' => t('Bottom'),
+      'hidden' => t('Hidden'),
+    ),
+    '#attributes' => array('class' => 'container-inline')
+  );
+  $form['widget']['color'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Tab color'),
+    '#default_value' => $defaults['widget']['color'],
+    '#size' => 8,
+    '#field_suffix' => t(' HEX or color'),
+    '#attributes' => array('class' => 'container-inline')
+  );
+  $form['widget']['limit'] = array(
+    '#type' => 'select',
+    '#title' => t('Limit'),
+    '#description' => t('Display at most this many topics.'),
+    '#default_value' => $defaults['widget']['limit'],
+    '#options' => array(
+      3 => t('3 topics'),
+      5 => t('5 topics'),
+      10 => t('10 topics'),
+    ),
+  );
+  $form['widget']['custom_css'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom CSS file'),
+    '#description' => t('Optional. Enter the url to a custom CSS file.  It should be either an external URL or one relative to your Drupal site base path.'),
+    '#default_value' => $defaults['widget']['custom_css'],
+  );
+  $form['widget']['custom_ie_css'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom IE CSS file'),
+    '#description' => t('Optional. Enter the url to a custom IE CSS file.  It should be either an external URL or one relative to your Drupal site base path.'),
+    '#default_value' => $defaults['widget']['custom_ie_css'],
+  );
+
+  $options = array(t('Add to every page except the listed pages.'), t('Add to the listed pages only.'));
+  $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
+  $form['vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Page specific settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['vis_settings']['visibility'] = array(
+    '#type' => 'radios',
+    '#title' => t('Add code to specific pages'),
+    '#options' => $options,
+    '#default_value' => $defaults['vis_settings']['visibility'],
+  );
+  $form['vis_settings']['pages'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Pages'),
+    '#description' => $description,
+    '#default_value' => $defaults['vis_settings']['pages'],
+    '#wysiwyg' => FALSE,
+  );
+
+  return system_settings_form($full);
+}
+
+/**
+ * Form callback for configuring the Feedback Page widget.
+ */
+function getsatisfaction_widget_feedback_page_form($form_state) {
+  // All settings for this widget will be stored in one variable.
+  $full['getsatisfaction_widget_feedback_page'] = array(
+    '#tree' => TRUE
+  );
+  $form = &$full['getsatisfaction_widget_feedback_page'];
+
+  // Get saved/defaults.
+  $defaults = _getsatisfaction_settings('getsatisfaction_widget_feedback_page');
+
+  $form['widget'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Widget settings'),
+    '#collapsible' => FALSE,
+  );
+
+  if (_getsatisfaction_plan_can('use product widgets')) {
+    if (($products = _getsatisfaction_api('companies/[company]/products')) && ($company = variable_get('getsatisfaction_name', FALSE))) {
+      if (!empty($products->data)) {
+        $form['widget']['product'] = array(
+          '#type' => 'select',
+          '#title' => t('Product'),
+          '#default_value' => isset($defaults['widget']['product']) ? $defaults['widget']['product'] : '',
+          '#options' => array(
+            '' => '-- none --',
+          ),
+        );
+        foreach ($products->data as $product) {
+          $key = $company . '_' . strtolower(str_replace(' ', '_', $product->name));
+          $form['widget']['product']['#options'][$key] = $product->name;
+        }
+      }
+    }
+    $form['widget']['tag'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Tag'),
+      '#description' => t('Optional. No Spaces. Enter a tag to filter feedback to.'),
+      '#default_value' => $defaults['widget']['tag'],
+      '#size' => 16,
+    );
+  }
+  $form['widget']['style'] = array(
+    '#type' => 'radios',
+    '#title' => t('Default type'),
+    '#default_value' => $defaults['widget']['style'],
+    '#options' => array(
+      'idea' => t('Idea'),
+      'question' => t('Question'),
+      'problem' => t('Problem'),
+      'praise' => t('Praise'),
+    ),
+    '#attributes' => array('class' => 'container-inline')
+  );
+  $form['widget']['limit'] = array(
+    '#type' => 'select',
+    '#title' => t('Limit'),
+    '#description' => t('Display at most this many topics.'),
+    '#default_value' => $defaults['widget']['limit'],
+    '#options' => array(
+      3 => t('3 topics'),
+      5 => t('5 topics'),
+      10 => t('10 topics'),
+    ),
+  );
+  $form['widget']['custom_css'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom CSS file'),
+    '#description' => t('Optional. Enter the url to a custom CSS file.  It should be either an external URL or one relative to your Drupal site base path.'),
+    '#default_value' => $defaults['widget']['custom_css'],
+  );
+  $form['widget']['custom_ie_css'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom IE CSS file'),
+    '#description' => t('Optional. Enter the url to a custom IE CSS file.  It should be either an external URL or one relative to your Drupal site base path.'),
+    '#default_value' => $defaults['widget']['custom_ie_css'],
+  );
+
+  $form['page'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Page Settings'),
+  );
+  $form['page']['path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Page Path'),
+    '#description' => t('If you provide a path, the Get Satisfaction feedback page will be created for your site.  Otherwise you can use the Get Satisfaction page filter to add this widget to any filtered content on your site.'),
+    '#default_value' => $defaults['page']['path'],
+  );
+  $form['page']['title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Page Title'),
+    '#description' => t('Provide a title for your feedback page.'),
+    '#default_value' => $defaults['page']['title'],
+  );
+
+  $full = system_settings_form($full);
+  $full['#submit'][] = 'menu_rebuild';
+  return $full;
+}
+
+
+
