Merge pull request #7240 from sudhabisht/WebtestFix46
[civicrm-core.git] / CRM / Contribute / BAO / ContributionPage.php
index c95cb01373866ccfd549fee3ddfb4c716b67497c..5c426b9464cbc43ae85403deedf7135417c53404 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -39,7 +39,7 @@
 class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage {
 
   /**
-   * Takes an associative array and creates a contribution page object
+   * Takes an associative array and creates a contribution page object.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
@@ -64,7 +64,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Update the is_active flag in the db
+   * Update the is_active flag in the db.
    *
    * @param int $id
    *   Id of the database record.
@@ -110,7 +110,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Send the emails
+   * Send the emails.
    *
    * @param int $contactID
    *   Contact id.
@@ -405,7 +405,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
         $taxAmt = $template->get_template_vars('dataArray');
         $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
-        if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
+        if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
           $sendTemplateParams['isEmailPdf'] = TRUE;
           $sendTemplateParams['contributionId'] = $values['contribution_id'];
         }
@@ -431,7 +431,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Construct the message to be sent by the send function
+   * Construct the message to be sent by the send function.
    *
    * @param array $tplParams
    * @param int $contactID
@@ -460,7 +460,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Send the emails for Recurring Contribution Notication
+   * Send the emails for Recurring Contribution Notication.
    *
    * @param string $type
    *   TxnType.
@@ -471,11 +471,10 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
    * @param object $recur
    *   Object of recurring contribution table.
    * @param bool|object $autoRenewMembership is it a auto renew membership.
-   *
-   * @return void
    */
   public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
     $value = array();
+    $isEmailReceipt = FALSE;
     if ($pageID) {
       CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
         'title',
@@ -485,9 +484,9 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
         'cc_receipt',
         'bcc_receipt',
       ));
+      $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]);
     }
 
-    $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]);
     $isOfflineRecur = FALSE;
     if (!$pageID && $recur->id) {
       $isOfflineRecur = TRUE;
@@ -674,6 +673,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
       'entity_table' => 'civicrm_contribution_page',
     ), array(
       'entity_id' => $copy->id,
+      'target_entity_id' => $copy->id,
     ));
 
     $copyPremium = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', array(
@@ -838,7 +838,9 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
    * @return array|string
    */
   public static function formatMultilingualHonorParams($params, $setDefault = FALSE) {
+    global $tsLocale;
     $config = CRM_Core_Config::singleton();
+
     $sctJson = $sctJsonDecode = NULL;
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
@@ -852,12 +854,12 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
         //monolingual state
         $sctJsonDecode += (array) $sctJsonDecode['default'];
       }
-      elseif (!empty($sctJsonDecode[$config->lcMessages])) {
+      elseif (!empty($sctJsonDecode[$tsLocale])) {
         //multilingual state
-        foreach ($sctJsonDecode[$config->lcMessages] as $column => $value) {
+        foreach ($sctJsonDecode[$tsLocale] as $column => $value) {
           $sctJsonDecode[$column] = $value;
         }
-        unset($sctJsonDecode[$config->lcMessages]);
+        unset($sctJsonDecode[$tsLocale]);
       }
       return $sctJsonDecode;
     }
@@ -904,7 +906,7 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
   }
 
   /**
-   * Generate html for pdf in confirmation receipt email  attachment
+   * Generate html for pdf in confirmation receipt email  attachment.
    * @param int $contributionId
    *   Contribution Page Id.
    * @param int $userID
@@ -924,7 +926,8 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
   }
 
   /**
-   * Helper to determine if the page supports separate membership payments
+   * Helper to determine if the page supports separate membership payments.
+   *
    * @param int $id form id
    *
    * @return bool