CRM-16189, added code to validate financial type for contribution
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage.php
index 09889fd4538c6346ccf066d2192f312484d3607e..e196b61c7fbbb677c759afed7b59e78f5c96fd09 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 /**
@@ -136,10 +136,19 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
       if (isset($this->_id) && $this->_id) {
         $params = array('id' => $this->_id);
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values);
+        CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
       }
       $this->set('values', $this->_values);
     }
 
+    // Check permission to edit contribution page
+    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE) {
+      $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
+      if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
+        CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
+      }
+    }
+
     // Preload libraries required by the "Profiles" tab
     $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
     if (in_array('CiviMember', CRM_Core_Config::singleton()->enableComponents)) {