3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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();
119 * @param string $fileName
120 * @param bool $lineMode
122 public static function loadCaseSampleData($dsn, $fileName, $lineMode = FALSE) {
123 $db = &DB
::connect($dsn);
124 if (PEAR
::isError($db)) {
125 die("Cannot open $dsn: " . $db->getMessage());
128 $domain = new CRM_Core_DAO_Domain();
130 $multiLingual = (bool) $domain->locales
;
131 $smarty = CRM_Core_Smarty
::singleton();
132 $smarty->assign('multilingual', $multiLingual);
133 $smarty->assign('locales', explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
));
137 $string = $smarty->fetch($fileName);
138 // change \r\n to fix windows issues
139 $string = str_replace("\r\n", "\n", $string);
141 //get rid of comments starting with # and --
143 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
144 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
146 $queries = preg_split('/;$/m', $string);
147 foreach ($queries as $query) {
148 $query = trim($query);
149 if (!empty($query)) {
150 $res = &$db->query($query);
151 if (PEAR
::isError($res)) {
152 die("Cannot execute $query: " . $res->getMessage());
158 $fd = fopen($fileName, "r");
159 while ($string = fgets($fd)) {
160 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
161 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
163 $string = trim($string);
164 if (!empty($string)) {
165 $res = &$db->query($string);
166 if (PEAR
::isError($res)) {
167 die("Cannot execute $string: " . $res->getMessage());