3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class generates form components for Component
39 class CRM_Admin_Form_Setting_Component
extends CRM_Admin_Form_Setting
{
40 protected $_components;
43 * Function to build the form
48 public function buildQuickForm() {
49 CRM_Utils_System
::setTitle(ts('Settings - Enable Components'));
50 $components = $this->_getComponentSelectValues();
51 $include = &$this->addElement('advmultiselect', 'enableComponents',
52 ts('Components') . ' ', $components,
55 'style' => 'width:150px',
56 'class' => 'advmultiselect',
60 $include->setButtonAttributes('add', array('value' => ts('Enable >>')));
61 $include->setButtonAttributes('remove', array('value' => ts('<< Disable')));
63 $this->addFormRule(array('CRM_Admin_Form_Setting_Component', 'formRule'), $this);
65 parent
::buildQuickForm();
71 * @param array $fields the input form values
72 * @param array $files the uploaded files if any
73 * @param array $options additional user data
75 * @return true if no errors, else array of errors
79 static function formRule($fields, $files, $options) {
82 if (array_key_exists('enableComponents', $fields) && is_array($fields['enableComponents'])) {
83 if (in_array('CiviPledge', $fields['enableComponents']) &&
84 !in_array('CiviContribute', $fields['enableComponents'])
86 $errors['enableComponents'] = ts('You need to enable CiviContribute before enabling CiviPledge.');
88 if (in_array('CiviCase', $fields['enableComponents']) &&
89 !CRM_Core_DAO
::checkTriggerViewPermission(TRUE, FALSE)
91 $errors['enableComponents'] = ts('CiviCase requires CREATE VIEW and DROP VIEW permissions for the database.');
98 private function _getComponentSelectValues() {
100 $this->_components
= CRM_Core_Component
::getComponents();
101 foreach ($this->_components
as $name => $object) {
102 $ret[$name] = $object->info
['translatedName'];
108 public function postProcess() {
109 $params = $this->controller
->exportValues($this->_name
);
111 CRM_Case_Info
::onToggleComponents($this->_defaults
['enableComponents'], $params['enableComponents'], NULL);
112 parent
::commonProcess($params);
114 // reset navigation when components are enabled / disabled
115 CRM_Core_BAO_Navigation
::resetNavigation();
118 public static function loadCaseSampleData($dsn, $fileName, $lineMode = FALSE) {
121 $db = &DB
::connect($dsn);
122 if (PEAR
::isError($db)) {
123 die("Cannot open $dsn: " . $db->getMessage());
127 $string = file_get_contents($fileName);
129 // change \r\n to fix windows issues
130 $string = str_replace("\r\n", "\n", $string);
132 //get rid of comments starting with # and --
134 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
135 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
137 $queries = preg_split('/;$/m', $string);
138 foreach ($queries as $query) {
139 $query = trim($query);
140 if (!empty($query)) {
141 $res = &$db->query($query);
142 if (PEAR
::isError($res)) {
143 die("Cannot execute $query: " . $res->getMessage());
149 $fd = fopen($fileName, "r");
150 while ($string = fgets($fd)) {
151 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
152 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
154 $string = trim($string);
155 if (!empty($string)) {
156 $res = &$db->query($string);
157 if (PEAR
::isError($res)) {
158 die("Cannot execute $string: " . $res->getMessage());