From 53f5859af2dfe08da6a7b4c98674d57484133a06 Mon Sep 17 00:00:00 2001
From: widukind <stefan.widukind@gmail.com>
Date: Thu, 23 Jun 2011 16:36:05 -0700
Subject: [PATCH] Issue 1198378: added config settings to control reuse of anonymously submitted user info

---
 contact.admin.inc |   16 ++++++++++++++++
 contact.module    |   13 ++++++++++++-
 contact.pages.inc |    8 ++++----
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/contact.admin.inc b/contact.admin.inc
index eb96574..0646a04 100644
--- a/contact.admin.inc
+++ b/contact.admin.inc
@@ -180,3 +180,19 @@ function contact_category_delete_form_submit($form, &$form_state) {
 
   $form_state['redirect'] = 'admin/build/contact';
 }
+
+/**
+ * Module settings form.
+ * @see system_settings_form
+ */
+function contact_admin_settings() {
+  
+  $form = array();
+  $form['contact_reuse_anon_user_info'] = array(
+  	'#type' => 'checkbox',
+    '#title' => t('Reuse submitted user information for the anonymous user.'),
+    '#default_value' => variable_get('contact_reuse_anon_user_info', 1),
+    '#description' => t('Check this box to track submitted user information for the anonymous user via cookies for later reuse.')
+  );
+  return system_settings_form($form);
+}
\ No newline at end of file
diff --git a/contact.module b/contact.module
index 079d16c..b50864f 100644
--- a/contact.module
+++ b/contact.module
@@ -60,6 +60,17 @@ function contact_menu() {
     'title' => 'List',
     'type' => MENU_DEFAULT_LOCAL_TASK,
   );
+  
+   $items['admin/build/contact/settings'] = array(
+    'title' => 'Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('contact_admin_settings'),
+    'access arguments' => array('administer contact forms'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2,
+    'file' => 'contact.admin.inc',
+  );
+     
   $items['admin/build/contact/add'] = array(
     'title' => 'Add category',
     'page callback' => 'drupal_get_form',
@@ -285,4 +296,4 @@ function contact_views_api() {
     'api' => 2,
     'path' => drupal_get_path('module', 'contact'),
   );
-}
+}
\ No newline at end of file
diff --git a/contact.pages.inc b/contact.pages.inc
index 4634534..4132fe4 100644
--- a/contact.pages.inc
+++ b/contact.pages.inc
@@ -56,7 +56,7 @@ function contact_mail_page($form_state) {
     }
   }
 
-  if (!$user->uid) {
+  if (!$user->uid && variable_get('contact_reuse_anon_user_info', 1)) {
     drupal_add_js(drupal_get_path('module', 'contact') . '/jquery.cookie.js');
     drupal_add_js(drupal_get_path('module', 'contact') . '/contact.js');
     $form['#attributes']['class'] = 'user-info-from-cookie';
@@ -138,8 +138,8 @@ function contact_mail_page_submit($form, &$form_state) {
   $values['sender']->mail = $values['mail'];
   $values['category'] = contact_load($values['cid']);
 
-  // Save the anonymous user information to a cookie for reuse.
-  if (!$user->uid) {
+  // If configured, save the anonymous user information to a cookie for reuse.
+  if (!$user->uid && variable_get('contact_reuse_anon_user_info', 1)) {
     contact_cookie_save($values);
   }
 
@@ -189,7 +189,7 @@ function contact_mail_user($form_state, stdClass $recipient) {
 
   drupal_set_title(t('Contact @username', array('@username' => $recipient->name)));
 
-  if (!$user->uid) {
+  if (!$user->uid && variable_get('contact_reuse_anon_user_info', 1)) {
     drupal_add_js(drupal_get_path('module', 'contact') . '/jquery.cookie.js');
     drupal_add_js(drupal_get_path('module', 'contact') . '/contact.js');
     $form['#attributes']['class'] = 'user-info-from-cookie';
-- 
1.7.3.1

