Merge pull request #3868 from rohankatkar/CRM_14961_webtest
[civicrm-core.git] / CRM / Price / Form / Set.php
index 32a29101264bd761ff735c9a3ad8eb69d2f10992..7c4fc525420bea6ae5ac8ea03bed77042b6ea53e 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -134,46 +134,47 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
 
     $config           = CRM_Core_Config::singleton();
     $showContribution = FALSE;
-    $components       = array('CiviEvent' => array('title' => ts('Event'),
-        'extend' => CRM_Core_Component::getComponentID('CiviEvent'),
-        'tables' => array(
-          'civicrm_event',
-          'civicrm_participant',
-        ),
-      ),
-      'CiviContribute' => array('title' => ts('Contribution'),
-        'extend' => CRM_Core_Component::getComponentID('CiviContribute'),
-        'tables' => array(
-          'civicrm_contribution',
-          'civicrm_contribution_page',
-        ),
-      ),
-      'CiviMember' => array('title' => ts('Membership'),
-        'extend' => CRM_Core_Component::getComponentID('CiviMember'),
-        'tables' => array(
-          'civicrm_membership',
-          'civicrm_contribution_page',
-        ),
-      ),
-    );
-    foreach ($components as $compName => $compValues) {
-      // take only enabled components.
-      if (!in_array($compName, $config->enableComponents)) {
-        continue;
-      }
-      $option = $this->createElement('checkbox', $compValues['extend'], NULL, $compValues['title']);
-
-      //if price set is used than freeze it.
-      if (!empty($priceSetUsedTables)) {
-        foreach ($compValues['tables'] as $table) {
+    $enabledComponents = CRM_Core_Component::getEnabledComponents();
 
-          if (in_array($table, $priceSetUsedTables)) {
-            $option->freeze();
-            break;
+    foreach ($enabledComponents as $name => $compObj) {
+      switch ($name) {
+        case 'CiviEvent':
+          $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Event'));
+          if (!empty($priceSetUsedTables)) {
+            foreach (array('civicrm_event', 'civicrm_participant') as $table) {
+              if (in_array($table, $priceSetUsedTables)) {
+                $option->freeze();
+                break;
+              }
+            }
+          }
+          $extends[] = $option;
+          break;
+        case 'CiviContribute':
+          $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Contribution'));
+          if (!empty($priceSetUsedTables)) {
+            foreach (array('civicrm_contribution', 'civicrm_contribution_page') as $table) {
+              if (in_array($table, $priceSetUsedTables)) {
+                $option->freeze();
+                break;
+              }
+            }
+          }
+          $extends[] = $option;
+          break;
+        case 'CiviMember':
+          $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Membership'));
+          if (!empty($priceSetUsedTables)) {
+            foreach (array('civicrm_membership', 'civicrm_contribution_page') as $table) {
+              if (in_array($table, $priceSetUsedTables)) {
+                $option->freeze();
+                break;
+              }
+            }
           }
-        }
+          $extends[] = $option;
+          break;
       }
-      $extends[] = $option;
     }
 
     if (CRM_Utils_System::isNull($extends)) {
@@ -286,7 +287,9 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
       CRM_Core_Session::setStatus(ts('The Set \'%1\' has been saved.', array(1 => $set->title)), ts('Saved'), 'success');
     }
     else {
-      $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $set->id);
+      // Jump directly to adding a field if popups are disabled
+      $action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? 'browse' : 'add';
+      $url = CRM_Utils_System::url('civicrm/admin/price/field', array('reset' => 1, 'action' => $action, 'sid' => $set->id));
       CRM_Core_Session::setStatus(ts("Your Set '%1' has been added. You can add fields to this set now.",
           array(1 => $set->title)
         ), ts('Saved'), 'success');