Merge pull request #2288 from eileenmcnaughton/CRM-14043
[civicrm-core.git] / CRM / Contribute / Form / Contribution / Main.php
index 358a90de472e636c6d77f5795d0f043352496c86..68918da67f3ac9f4b627c5f1845fee03545f5c33 100644 (file)
@@ -508,21 +508,32 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
     if ($this->_pcpId) {
       if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) {
-        $this->assign('pcpSupporterText', ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter)));
+        $pcp_supporter_text = ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
+        // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field.
+        $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute');
+        if(!empty($text)) {
+          $pcp_supporter_text .= "You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!";
+        }
+        $this->assign('pcpSupporterText', $pcp_supporter_text);
+      }
+      $prms = array('id' => $this->_pcpId);
+      CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
+      if ($pcpInfo['is_honor_roll']) {
+        $this->assign('isHonor', TRUE);
+        $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL,
+          array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
+        );
+        $extraOption = array('onclick' => "return pcpAnonymous( );");
+        $elements    = array();
+        $elements[]  = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
+        $elements[]  = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
+        $this->addGroup($elements, 'pcp_is_anonymous', NULL, '&nbsp;&nbsp;&nbsp;');
+        $this->setDefaults(array('pcp_display_in_roll' => 1));
+        $this->setDefaults(array('pcp_is_anonymous' => 1));
+
+        $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
+        $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
       }
-      $this->assign('pcp', TRUE);
-      $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL,
-        array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
-      );
-      $extraOption = array('onclick' => "return pcpAnonymous( );");
-      $elements    = array();
-      $elements[]  = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
-      $elements[]  = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
-      $this->addGroup($elements, 'pcp_is_anonymous', NULL, '&nbsp;&nbsp;&nbsp;');
-      $this->_defaults['pcp_is_anonymous'] = 0;
-
-      $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
-      $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
     }
 
     //we have to load confirm contribution button in template
@@ -544,15 +555,17 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) {
-      $this->addButtons(array(
-          array(
-            'type' => 'upload',
-            'name' => ts('Contribute'),
-            'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
-            'isDefault' => TRUE,
-          ),
-        )
+      $submitButton = array(
+        'type' => 'upload',
+        'name' => ts('Contribute'),
+        'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+        'isDefault' => TRUE,
       );
+      // Add submit-once behavior when confirm page disabled
+      if (empty($this->_values['is_confirm_enabled'])) {
+        $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
+      }
+      $this->addButtons(array($submitButton));
     }
 
     $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
@@ -964,7 +977,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       }
       elseif (CRM_Utils_Array::value('is_pledge', $fields)) {
         if (CRM_Utils_Rule::positiveInteger(CRM_Utils_Array::value('pledge_installments', $fields)) == FALSE) {
-          $errors['pledge_installments'] = ts('Please enter a valid pledge installment.');
+          $errors['pledge_installments'] = ts('Please enter a valid number of pledge installments.');
         }
         else {
           if (CRM_Utils_Array::value('pledge_installments', $fields) == NULL) {
@@ -1356,8 +1369,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
         // Add JS to show icons for the accepted credit cards
         $creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames();
         CRM_Core_Resources::singleton()
-          ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)))
-          ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js');
+          ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)
+          // workaround for CRM-13634
+          // ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)));
+          ->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
       }
     }
     $form->assign('ppType', $form->_ppType);