From e7748582ae0459e842c67972382699edb18b7289 Mon Sep 17 00:00:00 2001
From: Pieter Frenssen <pfrenssen@382067.no-reply.drupal.org>
Date: Thu, 29 Dec 2011 04:38:42 +0100
Subject: [PATCH] Issue #1191464 by pfrenssen: Allow to enable the personal contact form by default for existing users.

---
 modules/contact/contact.install |    1 +
 modules/contact/contact.module  |   26 +++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/modules/contact/contact.install b/modules/contact/contact.install
index f601558..ca5cdc7 100644
--- a/modules/contact/contact.install
+++ b/modules/contact/contact.install
@@ -84,6 +84,7 @@ function contact_install() {
  */
 function contact_uninstall() {
   variable_del('contact_default_status');
+  variable_del('contact_default_scope');
   variable_del('contact_threshold_limit');
   variable_del('contact_threshold_window');
 }
diff --git a/modules/contact/contact.module b/modules/contact/contact.module
index a870182..89e6809 100644
--- a/modules/contact/contact.module
+++ b/modules/contact/contact.module
@@ -130,9 +130,15 @@ function _contact_personal_tab_access($account) {
     return FALSE;
   }
 
-  // If the requested user has disabled their contact form, or this preference
-  // has not yet been saved, do not allow users to contact them.
-  if (empty($account->data['contact'])) {
+  // If the requested user has disabled their contact form, do not allow users
+  // to contact them.
+  if (isset($account->data['contact']) && !($account->data['contact'])) {
+    return FALSE;
+  }
+
+  // If the requested user did not yet save this preference, do not allow to
+  // contact them unless this has been enabled by default for all users.
+  if (empty($account->data['contact']) && !(variable_get('contact_default_status', 1) && variable_get('contact_default_scope', 0))) {
     return FALSE;
   }
 
@@ -252,8 +258,18 @@ function contact_form_user_admin_settings_alter(&$form, &$form_state) {
   );
   $form['contact']['contact_default_status'] = array(
     '#type' => 'checkbox',
-    '#title' => t('Enable the personal contact form by default for new users.'),
-    '#description' => t('Changing this setting will not affect existing users.'),
+    '#title' => t('Enable the personal contact form by default.'),
     '#default_value' => variable_get('contact_default_status', 1),
   );
+  $form['contact']['contact_default_scope'] = array(
+    '#type' => 'radios',
+    '#title' => '',
+    '#default_value' => variable_get('contact_default_scope', 0),
+    '#options' => array(t('For new users only.'), t('For new and existing users.')),
+    '#states' => array(
+      'visible' => array(
+        ':input[name="contact_default_status"]' => array('checked' => TRUE),
+      ),
+    ),
+  );
 }
-- 
1.7.1

