CRM-11316 Fix online contrib, event reg, PCP account, petition signature and mailing...
authorDave Greenberg <dave@civicrm.org>
Wed, 17 Jul 2013 20:12:18 +0000 (13:12 -0700)
committerDave Greenberg <dave@civicrm.org>
Wed, 17 Jul 2013 20:12:18 +0000 (13:12 -0700)
----------------------------------------
* CRM-11316:
  http://issues.civicrm.org/jira/browse/CRM-11316

CRM/Campaign/Form/Petition/Signature.php
CRM/Contribute/Form/ContributionBase.php
CRM/Event/Form/Registration.php
CRM/Mailing/Form/Subscribe.php
CRM/PCP/Form/PCPAccount.php
templates/CRM/Campaign/Form/Petition/Signature.tpl
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Event/Form/Registration/Register.tpl
templates/CRM/Mailing/Form/Subscribe.tpl

index b00282c63e182807aec630b59fc391e0b7d46cb1..b93b04526af47edfe7b2d5b833924ceccc493337 100644 (file)
@@ -642,7 +642,8 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
 
           CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
           $this->_fields[$key] = $field;
-          if ($field['add_captcha']) {
+          // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
+          if ($field['add_captcha'] && !$this->_contactId) {
             $addCaptcha = TRUE;
           }
         }
@@ -650,9 +651,7 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
         // initialize the state country map
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
 
-        if ($addCaptcha &&
-          !$viewOnly
-        ) {
+        if ($addCaptcha && !$viewOnly) {
           $captcha = CRM_Utils_ReCAPTCHA::singleton();
           $captcha->add($this);
           $this->assign("isCaptcha", TRUE);
index cba721e901b40da8d22c371e9807b1a77297ea23..df47a2b74b252b66ca87de4e128662cfec894c3c 100644 (file)
@@ -716,7 +716,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
             );
             $this->_fields[$key] = $field;
           }
-          if ($field['add_captcha']) {
+          // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
+          if ($field['add_captcha'] && !$this->_userID) {
             $addCaptcha = TRUE;
           }
         }
index ae41826ccb7b71c091263eeb12fd8bbf93a544ca..a6f08e5d72eebff4d174e1ab9b2c5b46c8a4a42c 100644 (file)
@@ -646,12 +646,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
           //have been skip the additional participant.
           if ($button == 'skip') {
             $field['is_required'] = FALSE;
-          }
-          elseif ($field['add_captcha']) {
+          }          
+          // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
+          elseif ($field['add_captcha']  && !$contactID) {
             // only add captcha for first page
             $addCaptcha = TRUE;
           }
-
           list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
           if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
             if (!array_key_exists($index, $stateCountryMap)) {
index 041ecac28541778b0566916aa0f6655b9971ed76..9742f501cb00f19b3820d92e4dc1f661f9e02031 100644 (file)
@@ -130,11 +130,15 @@ ORDER BY title";
 
     $addCaptcha = TRUE;
 
-    // if recaptcha is not set, then dont add it
+    // if recaptcha is not configured, then dont add it
+    // CRM-11316 Only enable ReCAPTCHA for anonymous visitors
     $config = CRM_Core_Config::singleton();
+    $session   = CRM_Core_Session::singleton();
+    $contactID = $session->get('userID');
+    
     if (empty($config->recaptchaPublicKey) ||
-      empty($config->recaptchaPrivateKey)
-    ) {
+      empty($config->recaptchaPrivateKey) ||
+      $contactID) {
       $addCaptcha = FALSE;
     }
     else {
@@ -152,6 +156,7 @@ ORDER BY title";
       // add captcha
       $captcha = CRM_Utils_ReCAPTCHA::singleton();
       $captcha->add($this);
+      $this->assign('isCaptcha', TRUE);
     }
 
     $this->addButtons(array(
index 8f1be0354466d8cffd525cc02fa107012655fac7..7de81d9b2821478e0945d51b357a1b6ba17493d9 100644 (file)
@@ -56,6 +56,15 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form {
    */
   public $_single;
 
+  /**
+   * the default values for the form
+   *
+   * @var array
+   * @protected
+   */
+  protected $_defaults;
+
+
   public function preProcess() {
     $session          = CRM_Core_Session::singleton();
     $config           = CRM_Core_Config::singleton();
@@ -108,6 +117,7 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form {
   }
 
   function setDefaultValues() {
+    $this->_defaults = array();
     if ($this->_contactID) {
       foreach ($this->_fields as $name => $dontcare) {
         $fields[$name] = 1;
@@ -177,7 +187,9 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form {
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
         $this->_fields[$key] = $field;
-        if ($field['add_captcha']) {
+
+        // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
+        if ($field['add_captcha'] && !$this->_contactID) {
           $addCaptcha = TRUE;
         }
       }
index 0736f23007dac43ea6fbbbe2af776099a31f6a96..bfa14f62975502bc6b8bca5297d99e0a2a0d8008 100644 (file)
@@ -56,6 +56,10 @@ Please check your email inbox for the confirmation email. If you don't find it,
     {include file="CRM/Campaign/Form/Petition/Block.tpl" fields=$petitionActivityProfile}
   </div>
 
+  {if $isCaptcha}
+      {include file='CRM/common/ReCAPTCHA.tpl'}
+  {/if}
+
   <div class="crm-submit-buttons">
     {include file="CRM/common/formButtons.tpl" location="bottom"}
   </div>
index c81cd8c12f7aa3d228621139a3036e214dcb5b8f..f60dd4139d5317e402d3132a4d3f4996eeb9bd4b 100644 (file)
   {/if}
 
   {if $isCaptcha}
-  {include file='CRM/common/ReCAPTCHA.tpl'}
+    {include file='CRM/common/ReCAPTCHA.tpl'}
   {/if}
   <div id="crm-submit-buttons" class="crm-submit-buttons">
   {include file="CRM/common/formButtons.tpl" location="bottom"}
index 887b790221f450376ac2fe1e68d65670fc5999fa..5837371c6a1d5fcbea03bc1f576546d4c0dd080a 100644 (file)
 {include file="CRM/UF/Form/Block.tpl" fields=$customPost}
 
 {if $isCaptcha}
-    {include file='CRM/common/ReCAPTCHA.tpl'}
+  {include file='CRM/common/ReCAPTCHA.tpl'}
 {/if}
 
 <div id="crm-submit-buttons" class="crm-submit-buttons">
index 7001c3f3a6d31b1c66d468698615e669f6c90e83..65da92d9ead43a2c4d58f423d0a873e2af183ca5 100644 (file)
@@ -56,6 +56,8 @@
         </td>
     </tr>
 </table>
-{include file='CRM/common/ReCAPTCHA.tpl'}
+{if $isCaptcha}
+  {include file='CRM/common/ReCAPTCHA.tpl'}
+{/if}
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
 </div><!-- end crm-block -->