Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
ce064e4f | 35 | * This class generates form components for Component. |
6a488035 TO |
36 | */ |
37 | class CRM_Admin_Form_Setting_Component extends CRM_Admin_Form_Setting { | |
38 | protected $_components; | |
39 | ||
40 | /** | |
eceb18cc | 41 | * Build the form object. |
6a488035 TO |
42 | */ |
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, | |
48 | array( | |
49 | 'size' => 5, | |
50 | 'style' => 'width:150px', | |
51 | 'class' => 'advmultiselect', | |
52 | ) | |
53 | ); | |
54 | ||
55 | $include->setButtonAttributes('add', array('value' => ts('Enable >>'))); | |
56 | $include->setButtonAttributes('remove', array('value' => ts('<< Disable'))); | |
57 | ||
58 | $this->addFormRule(array('CRM_Admin_Form_Setting_Component', 'formRule'), $this); | |
59 | ||
60 | parent::buildQuickForm(); | |
61 | } | |
62 | ||
63 | /** | |
eceb18cc | 64 | * Global form rule. |
6a488035 | 65 | * |
5173bd95 TO |
66 | * @param array $fields |
67 | * The input form values. | |
68 | * @param array $files | |
69 | * The uploaded files if any. | |
70 | * @param array $options | |
71 | * Additional user data. | |
6a488035 | 72 | * |
72b3a70c CW |
73 | * @return bool|array |
74 | * true if no errors, else array of errors | |
6a488035 | 75 | */ |
00be9182 | 76 | public static function formRule($fields, $files, $options) { |
6a488035 TO |
77 | $errors = array(); |
78 | ||
6f98c8ae | 79 | if (array_key_exists('enableComponents', $fields) && is_array($fields['enableComponents'])) { |
6a488035 TO |
80 | if (in_array('CiviPledge', $fields['enableComponents']) && |
81 | !in_array('CiviContribute', $fields['enableComponents']) | |
82 | ) { | |
83 | $errors['enableComponents'] = ts('You need to enable CiviContribute before enabling CiviPledge.'); | |
84 | } | |
85 | if (in_array('CiviCase', $fields['enableComponents']) && | |
86 | !CRM_Core_DAO::checkTriggerViewPermission(TRUE, FALSE) | |
87 | ) { | |
88 | $errors['enableComponents'] = ts('CiviCase requires CREATE VIEW and DROP VIEW permissions for the database.'); | |
89 | } | |
90 | } | |
91 | ||
92 | return $errors; | |
93 | } | |
94 | ||
e0ef6999 EM |
95 | /** |
96 | * @return array | |
97 | */ | |
6a488035 TO |
98 | private function _getComponentSelectValues() { |
99 | $ret = array(); | |
100 | $this->_components = CRM_Core_Component::getComponents(); | |
101 | foreach ($this->_components as $name => $object) { | |
102 | $ret[$name] = $object->info['translatedName']; | |
103 | } | |
104 | ||
105 | return $ret; | |
106 | } | |
107 | ||
108 | public function postProcess() { | |
109 | $params = $this->controller->exportValues($this->_name); | |
110 | ||
6a488035 TO |
111 | parent::commonProcess($params); |
112 | ||
113 | // reset navigation when components are enabled / disabled | |
114 | CRM_Core_BAO_Navigation::resetNavigation(); | |
115 | } | |
116 | ||
e0ef6999 | 117 | /** |
bf48aa29 | 118 | * Load case sample data. |
119 | * | |
100fef9d | 120 | * @param string $fileName |
e0ef6999 EM |
121 | * @param bool $lineMode |
122 | */ | |
02b862ef TO |
123 | public static function loadCaseSampleData($fileName, $lineMode = FALSE) { |
124 | $dao = new CRM_Core_DAO(); | |
125 | $db = $dao->getDatabaseConnection(); | |
6a488035 | 126 | |
d72f7af5 | 127 | $domain = new CRM_Core_DAO_Domain(); |
128 | $domain->find(TRUE); | |
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)); | |
133 | ||
6a488035 | 134 | if (!$lineMode) { |
6a488035 | 135 | |
d72f7af5 | 136 | $string = $smarty->fetch($fileName); |
6a488035 TO |
137 | // change \r\n to fix windows issues |
138 | $string = str_replace("\r\n", "\n", $string); | |
139 | ||
140 | //get rid of comments starting with # and -- | |
141 | ||
142 | $string = preg_replace("/^#[^\n]*$/m", "\n", $string); | |
143 | $string = preg_replace("/^(--[^-]).*/m", "\n", $string); | |
144 | ||
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()); | |
152 | } | |
153 | } | |
154 | } | |
155 | } | |
156 | else { | |
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); | |
161 | ||
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()); | |
167 | } | |
168 | } | |
169 | } | |
170 | } | |
171 | } | |
96025800 | 172 | |
6a488035 | 173 | } |