3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
35 * This class generates form components for Component.
37 class CRM_Admin_Form_Setting_Component
extends CRM_Admin_Form_Setting
{
38 protected $_components;
41 * Build the form object.
43 public function buildQuickForm() {
44 CRM_Utils_System
::setTitle(ts('Settings - Enable Components'));
45 $components = $this->_getComponentSelectValues();
46 $include = &$this->addElement('advmultiselect', 'enableComponents',
47 ts('Components') . ' ', $components,
50 'style' => 'width:150px',
51 'class' => 'advmultiselect',
55 $include->setButtonAttributes('add', array('value' => ts('Enable >>')));
56 $include->setButtonAttributes('remove', array('value' => ts('<< Disable')));
58 $this->addFormRule(array('CRM_Admin_Form_Setting_Component', 'formRule'), $this);
60 parent
::buildQuickForm();
66 * @param array $fields
67 * The input form values.
69 * The uploaded files if any.
70 * @param array $options
71 * Additional user data.
74 * true if no errors, else array of errors
76 public static function formRule($fields, $files, $options) {
79 if (array_key_exists('enableComponents', $fields) && is_array($fields['enableComponents'])) {
80 if (in_array('CiviPledge', $fields['enableComponents']) &&
81 !in_array('CiviContribute', $fields['enableComponents'])
83 $errors['enableComponents'] = ts('You need to enable CiviContribute before enabling CiviPledge.');
85 if (in_array('CiviCase', $fields['enableComponents']) &&
86 !CRM_Core_DAO
::checkTriggerViewPermission(TRUE, FALSE)
88 $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 parent
::commonProcess($params);
113 // reset navigation when components are enabled / disabled
114 CRM_Core_BAO_Navigation
::resetNavigation();
118 * Load case sample data.
120 * @param string $fileName
121 * @param bool $lineMode
123 public static function loadCaseSampleData($fileName, $lineMode = FALSE) {
124 $dao = new CRM_Core_DAO();
125 $db = $dao->getDatabaseConnection();
127 $domain = new CRM_Core_DAO_Domain();
129 $multiLingual = (bool) $domain->locales
;
130 $smarty = CRM_Core_Smarty
::singleton();
131 $smarty->assign('multilingual', $multiLingual);
132 $smarty->assign('locales', explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
));
136 $string = $smarty->fetch($fileName);
137 // change \r\n to fix windows issues
138 $string = str_replace("\r\n", "\n", $string);
140 //get rid of comments starting with # and --
142 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
143 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
145 $queries = preg_split('/;$/m', $string);
146 foreach ($queries as $query) {
147 $query = trim($query);
148 if (!empty($query)) {
149 $res = &$db->query($query);
150 if (PEAR
::isError($res)) {
151 die("Cannot execute $query: " . $res->getMessage());
157 $fd = fopen($fileName, "r");
158 while ($string = fgets($fd)) {
159 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
160 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
162 $string = trim($string);
163 if (!empty($string)) {
164 $res = &$db->query($string);
165 if (PEAR
::isError($res)) {
166 die("Cannot execute $string: " . $res->getMessage());