Fix button breakage on viewContribution
[civicrm-core.git] / CRM / Contribute / Form / ContributionView.php
index aa54df0c8331010f20dde3e5868a05e5d82406ca..b16ec29a04b24170db8c7d9c00d9ee9020d01575 100644 (file)
@@ -31,6 +31,11 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
   public function preProcess() {
     $id = $this->getID();
 
+    // Check permission for action.
+    if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
+      CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
+    }
+    $params = ['id' => $id];
     $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
     $this->assign('context', $context);
 
@@ -44,6 +49,15 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $values = (array) $contribution;
     $contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $values['contribution_status_id']);
 
+    $this->addExpectedSmartyVariables([
+      'hookDiscount',
+      'pricesetFieldsCount',
+      'pcp_id',
+      'getTaxDetails',
+      // currencySymbol maybe doesn't make sense but is probably old?
+      'currencySymbol',
+    ]);
+
     // @todo - it might have been better to create a new form that extends this
     // for template contributions rather than overloading this form.
     $force_create_template = CRM_Utils_Request::retrieve('force_create_template', 'Boolean', $this, FALSE, FALSE);
@@ -60,6 +74,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
 
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
 
+    $values['contribution_page_title'] = '';
     if (!empty($values['contribution_page_id'])) {
       $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
       $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
@@ -68,6 +83,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     // get received into i.e to_financial_account_id from last trxn
     $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($this->getID(), 'DESC');
     $values['to_financial_account'] = '';
+    $values['payment_processor_name'] = '';
     if (!empty($financialTrxnId['financialTrxnId'])) {
       $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
       if ($values['to_financial_account_id']) {
@@ -90,26 +106,30 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
       }
     }
 
-    $participantLineItems = \Civi\Api4\LineItem::get()
-      ->addSelect('entity_id', 'participant.role_id:label', 'participant.fee_level', 'participant.contact_id', 'contact.display_name')
-      ->addJoin('Participant AS participant', 'LEFT', ['participant.id', '=', 'entity_id'])
-      ->addJoin('Contact AS contact', 'LEFT', ['contact.id', '=', 'participant.contact_id'])
-      ->addWhere('entity_table', '=', 'civicrm_participant')
-      ->addWhere('contribution_id', '=', $id)
-      ->execute();
+    try {
+      $participantLineItems = \Civi\Api4\LineItem::get()
+        ->addSelect('entity_id', 'participant.role_id:label', 'participant.fee_level', 'participant.contact_id', 'contact.display_name')
+        ->addJoin('Participant AS participant', 'LEFT', ['participant.id', '=', 'entity_id'])
+        ->addJoin('Contact AS contact', 'LEFT', ['contact.id', '=', 'participant.contact_id'])
+        ->addWhere('entity_table', '=', 'civicrm_participant')
+        ->addWhere('contribution_id', '=', $id)
+        ->execute();
+    }
+    catch (API_Exception $e) {
+      // likely don't have permission for events/participants
+      $participantLineItems = [];
+    }
 
     $associatedParticipants = FALSE;
-    if ($participantLineItems->count()) {
-      foreach ($participantLineItems as $participant) {
-        $associatedParticipants[] = [
-          'participantLink' => CRM_Utils_System::url('civicrm/contact/view/participant',
-            "action=view&reset=1&id={$participant['entity_id']}&cid={$participant['participant.contact_id']}&context=home"
-          ),
-          'participantName' => $participant['contact.display_name'],
-          'fee' => implode(', ', $participant['participant.fee_level']),
-          'role' => implode(', ', $participant['participant.role_id:label']),
-        ];
-      }
+    foreach ($participantLineItems as $participant) {
+      $associatedParticipants[] = [
+        'participantLink' => CRM_Utils_System::url('civicrm/contact/view/participant',
+          "action=view&reset=1&id={$participant['entity_id']}&cid={$participant['participant.contact_id']}&context=home"
+        ),
+        'participantName' => $participant['contact.display_name'],
+        'fee' => implode(', ', $participant['participant.fee_level']),
+        'role' => implode(', ', $participant['participant.role_id:label']),
+      ];
     }
     $this->assign('associatedParticipants', $associatedParticipants);
 
@@ -125,6 +145,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
       $productID = $dao->product_id;
     }
 
+    $this->assign('premium', '');
     if ($premiumId) {
       $productDAO = new CRM_Contribute_DAO_Product();
       $productDAO->id = $productID;
@@ -140,6 +161,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $values['note'] = array_values($noteValue);
 
     // show billing address location details, if exists
+    $values['billing_address'] = '';
     if (!empty($values['address_id'])) {
       $addressParams = ['id' => $values['address_id']];
       $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
@@ -149,12 +171,9 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
 
     //assign soft credit record if exists.
     $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($this->getID(), TRUE);
-    if (!empty($SCRecords['soft_credit'])) {
-      $this->assign('softContributions', $SCRecords['soft_credit']);
-      unset($SCRecords['soft_credit']);
-    }
-
-    //assign pcp record if exists
+    $this->assign('softContributions', empty($SCRecords['soft_credit']) ? NULL : $SCRecords['soft_credit']);
+    // unset doesn't complain if array member missing
+    unset($SCRecords['soft_credit']);
     foreach ($SCRecords as $name => $value) {
       $this->assign($name, $value);
     }
@@ -165,6 +184,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $this->assign('displayLineItemFinancialType', TRUE);
 
     //do check for campaigns
+    $values['campaign'] = '';
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
       $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
       $values['campaign'] = $campaigns[$campaignId];
@@ -249,7 +269,10 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
         'url' => 'civicrm/contact/view/contribution',
         'qs' => $urlParams,
         'icon' => 'fa-pencil',
-        'accesskey' => 'e',
+        'accessKey' => 'e',
+        'ref' => '',
+        'name' => '',
+        'extra' => '',
       ];
     }
 
@@ -263,6 +286,10 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
         'url' => 'civicrm/contact/view/contribution',
         'qs' => $urlParams,
         'icon' => 'fa-trash',
+        'accessKey' => '',
+        'ref' => '',
+        'name' => '',
+        'extra' => '',
       ];
     }
 
@@ -328,6 +355,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($id, 'contribution', TRUE);
     $title = ts('View Payment');
     $this->assign('transaction', TRUE);
+    // Used in paymentInfoBlock.tpl
     $this->assign('payments', $paymentInfo['transaction']);
     $this->assign('paymentLinks', $paymentInfo['payment_links']);
     return $title;