--- feedback.module	Wed Dec 03 18:19:33 2008
+++ feedback.module	Fri Jan 16 12:05:17 2009
@@ -27,6 +27,14 @@
       'callback arguments' => 'feedback_admin_view_form',
       'access' => user_access('view feedback messages'),
     );
+	$items[] = array(
+      'path' => 'admin/settings/feedback',
+      'title' => t('Feedback'),
+      'description' => t('Configure Feedback module.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'feedback_settings',
+      'access' => user_access('administer site configuration'));
+
   }
   else if (user_access('access feedback form')) {
     drupal_add_css(drupal_get_path('module', 'feedback') . '/feedback.css');
@@ -36,6 +44,21 @@
 }
 
 /**
+ * Menu callback. Admin setting page for feedback.
+ */
+function feedback_settings() {
+  $form['feedback_emailaddress'] = array(
+    '#type' => 'textfield',
+    '#size' => 30,
+    '#title' => t('Email address to receive feedback messages'),
+    '#default_value' => variable_get('feedback_emailaddress', ''),
+    '#description' => t('The email address that you would like feedbacks sent to.  Leave blank to disable emailing.'),
+  );
+  return system_settings_form($form);
+}
+
+
+/**
  * Implementation of hook_block().
  */
 function feedback_block($op = 'list', $delta = 0, $edit = array()) {
@@ -208,6 +231,59 @@
 
   $fid = db_next_id("{feedback}_fid");
   db_query("INSERT INTO {feedback} (fid, uid, message, location, location_masked, timestamp, useragent) VALUES (%d, %d, '%s', '%s', '%s', %d, '%s')", $fid, $user->uid, trim($message), $location, feedback_mask_path($location), time(), $_SERVER['HTTP_USER_AGENT']);
+  $adminemail = variable_get('feedback_emailaddress', '');
+  if ($adminemail){
+	theme('feedback_email', $fid, $adminemail, t('Feedback received'));
+  }
+}
+
+/**
+ * Mail a feedback entry - rethemeable
+ *
+ * @param integer $fid
+ *   A feedback message id.
+ * @param string $email
+ *   The email to send the feedback to, optional (defaults to configured emailaddress, if not given).
+ * @param string $msg
+ *   Text for padding email subject.
+ */
+function theme_feedback_email($fid, $email, $msg = 'Feedback item') {
+  if ($email == "") {
+    $email = variable_get('feedback_emailaddress', '');
+    if ($email == "") { return; }    
+  }
+  $feedback = feedback_load(array('fid' => $fid));
+  if ($feedback[$fid]){
+    $entry = $feedback[$fid];
+	$body = array();
+	$msg = $msg . ": #" . $fid . ' on ' . variable_get('site_name', 'Drupal');
+	$body[] = $msg . "\n\n";
+    
+  foreach ((array)$entry as $entrykey => $entryitem){
+    switch ($entrykey) {
+      case 'status':
+        break;
+      case 'timestamp':
+      	$body[] = t('Date') . ": " . format_date($entry->timestamp, 'small');
+        break;        
+      case 'useragent':
+        if (module_exists('browscap')) {
+          $browserinfo = browscap_get_browser($entryitem);
+          $body[] = t('Browser') . ": " . ($browserinfo['parent'] ? $browserinfo['parent'] .' / '. $browserinfo['platform'] : $browserinfo['useragent']);
+        } else {
+          $body[] = t('Browser') . ": " . check_plain($entryitem);
+        }
+        break;        
+      default:  
+      $body[] = ucfirst($entrykey) . ": " . html_entity_decode(check_plain($entryitem), ENT_QUOTES);
+      break;
+    }
+  }
+  //$body[] = "Cut and Paste:\n" . implode("\t", (array)$entry);
+
+	$bodytext = implode("\n", $body);
+	drupal_mail("feedback", $email, $msg, $bodytext);
+  }
 }
 
 /**
@@ -327,8 +403,12 @@
       $update[$fid] = ($status == 0 ? 1 : 0);
     }
   }
+  $adminemail = variable_get('feedback_emailaddress', '');
   // Update status of entries in database.
   foreach ($update as $fid => $value) {
+    if ($adminemail && $value){
+      theme('feedback_email', $fid, $adminemail, t('Feedback Closed'));
+    }
     db_query("UPDATE {feedback} SET status = %d WHERE fid = %d", $value, $fid);
   }
 }
