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 Options. |
6a488035 TO |
36 | */ |
37 | class CRM_Admin_Form_Options extends CRM_Admin_Form { | |
38 | ||
39 | /** | |
eceb18cc | 40 | * The option group name. |
6a488035 TO |
41 | * |
42 | * @var array | |
6a488035 TO |
43 | */ |
44 | protected $_gName; | |
45 | ||
46 | /** | |
47 | * The option group name in display format (capitalized, without underscores...etc) | |
48 | * | |
49 | * @var array | |
6a488035 | 50 | */ |
6c2473d5 | 51 | protected $_gLabel; |
6a488035 | 52 | |
82f3aedc SL |
53 | /** |
54 | * Is this Option Group Domain Specific | |
55 | * @var bool | |
56 | */ | |
57 | protected $_domainSpecific = FALSE; | |
58 | ||
6a488035 | 59 | /** |
100fef9d | 60 | * Pre-process |
6a488035 TO |
61 | */ |
62 | public function preProcess() { | |
63 | parent::preProcess(); | |
64 | $session = CRM_Core_Session::singleton(); | |
118e964e CW |
65 | if (!$this->_gName && !empty($this->urlPath[3])) { |
66 | $this->_gName = $this->urlPath[3]; | |
67 | } | |
68 | if (!$this->_gName && !empty($_GET['gid'])) { | |
69 | $this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', (int) $_GET['gid'], 'name'); | |
6a488035 TO |
70 | } |
71 | if ($this->_gName) { | |
72 | $this->set('gName', $this->_gName); | |
73 | } | |
74 | else { | |
75 | $this->_gName = $this->get('gName'); | |
76 | } | |
118e964e CW |
77 | $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', |
78 | $this->_gName, | |
79 | 'id', | |
80 | 'name' | |
81 | ); | |
faa2cea0 | 82 | $this->_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title'); |
8326c4b5 | 83 | $this->_domainSpecific = in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups); |
353ffa53 TO |
84 | $url = "civicrm/admin/options/{$this->_gName}"; |
85 | $params = "reset=1"; | |
6a488035 TO |
86 | |
87 | if (($this->_action & CRM_Core_Action::DELETE) && | |
88 | in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee')) | |
89 | ) { | |
90 | // Don't allow delete if the option value belongs to addressee, postal or email greetings and is in use. | |
353ffa53 | 91 | $findValue = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'value'); |
6a488035 TO |
92 | $queryParam = array(1 => array($findValue, 'Integer')); |
93 | $columnName = $this->_gName . "_id"; | |
353ffa53 TO |
94 | $sql = "SELECT count(id) FROM civicrm_contact WHERE " . $columnName . " = %1"; |
95 | $isInUse = CRM_Core_DAO::singleValueQuery($sql, $queryParam); | |
6a488035 TO |
96 | if ($isInUse) { |
97 | $scriptURL = "<a href='" . CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', TRUE, NULL, NULL, NULL, "wiki") . "'>" . ts('Learn more about a script that can automatically update contact addressee and greeting options.') . "</a>"; | |
353ffa53 TO |
98 | CRM_Core_Session::setStatus(ts('The selected %1 option has <strong>not been deleted</strong> because it is currently in use. Please update these contacts to use a different format before deleting this option. %2', array( |
99 | 1 => $this->_gLabel, | |
8d7a9d07 | 100 | 2 => $scriptURL, |
353ffa53 | 101 | )), ts('Sorry'), 'error'); |
6a488035 TO |
102 | $redirect = CRM_Utils_System::url($url, $params); |
103 | CRM_Utils_System::redirect($redirect); | |
104 | } | |
105 | } | |
106 | ||
6a488035 TO |
107 | $session->pushUserContext(CRM_Utils_System::url($url, $params)); |
108 | $this->assign('id', $this->_id); | |
109 | ||
110 | if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) { | |
111 | $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id'); | |
112 | if (CRM_Core_Config::domainID() != $domainID) { | |
0499b0ad | 113 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
114 | } |
115 | } | |
116 | } | |
117 | ||
118 | /** | |
c490a46a | 119 | * Set default values for the form. |
6a488035 | 120 | */ |
00be9182 | 121 | public function setDefaultValues() { |
6a488035 TO |
122 | $defaults = parent::setDefaultValues(); |
123 | ||
2b90b596 CW |
124 | // Default weight & value |
125 | $fieldValues = array('option_group_id' => $this->_gid); | |
126 | foreach (array('weight', 'value') as $field) { | |
127 | if (empty($defaults[$field])) { | |
128 | $defaults[$field] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, $field); | |
129 | } | |
6a488035 TO |
130 | } |
131 | ||
132 | //setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575 | |
133 | if (in_array($this->_gName, array( | |
353ffa53 TO |
134 | 'email_greeting', |
135 | 'postal_greeting', | |
8d7a9d07 | 136 | 'addressee', |
353ffa53 | 137 | ))) { |
6a488035 TO |
138 | $defaults['contactOptions'] = (CRM_Utils_Array::value('filter', $defaults)) ? $defaults['filter'] : NULL; |
139 | } | |
140 | // CRM-11516 | |
141 | if ($this->_gName == 'payment_instrument' && $this->_id) { | |
74afdc40 | 142 | $defaults['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($this->_id, NULL, 'civicrm_option_value'); |
6a488035 | 143 | } |
b62580ac CW |
144 | if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'color')) { |
145 | $defaults['color'] = '#ffffff'; | |
146 | } | |
6a488035 TO |
147 | return $defaults; |
148 | } | |
149 | ||
150 | /** | |
eceb18cc | 151 | * Build the form object. |
6a488035 TO |
152 | */ |
153 | public function buildQuickForm() { | |
154 | parent::buildQuickForm(); | |
e2046b33 CW |
155 | $this->setPageTitle(ts('%1 Option', array(1 => $this->_gLabel))); |
156 | ||
6a488035 TO |
157 | if ($this->_action & CRM_Core_Action::DELETE) { |
158 | return; | |
159 | } | |
160 | ||
161 | $this->applyFilter('__ALL__', 'trim'); | |
162 | ||
163 | $isReserved = FALSE; | |
164 | if ($this->_id) { | |
165 | $isReserved = (bool) CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'is_reserved'); | |
166 | } | |
167 | ||
168 | $this->add('text', | |
169 | 'label', | |
170 | ts('Label'), | |
171 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), | |
172 | TRUE | |
173 | ); | |
e5720c45 | 174 | |
635a99e5 CW |
175 | if ($this->_gName != 'activity_type') { |
176 | $this->add('text', | |
177 | 'value', | |
178 | ts('Value'), | |
179 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'), | |
180 | TRUE | |
181 | ); | |
82f3aedc SL |
182 | $this->addRule('value', |
183 | ts('This Value already exists in the database for this option group. Please select a different Value.'), | |
184 | 'optionExists', | |
185 | array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'value', $this->_domainSpecific) | |
186 | ); | |
635a99e5 | 187 | } |
0c6fe5b5 CW |
188 | else { |
189 | $this->add('text', 'icon', ts('Icon'), array('class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE)); | |
190 | } | |
49c233c1 | 191 | |
6f5ac62a | 192 | if (in_array($this->_gName, array('activity_status', 'case_status'))) { |
b62580ac CW |
193 | $this->add('color', 'color', ts('Color')); |
194 | } | |
195 | ||
6a488035 | 196 | if (!in_array($this->_gName, array( |
353ffa53 TO |
197 | 'email_greeting', |
198 | 'postal_greeting', | |
8d7a9d07 | 199 | 'addressee', |
353ffa53 TO |
200 | )) && !$isReserved |
201 | ) { | |
6a488035 | 202 | $this->addRule('label', |
82f3aedc | 203 | ts('This Label already exists in the database for this option group. Please select a different Label.'), |
6a488035 | 204 | 'optionExists', |
82f3aedc | 205 | array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label', $this->_domainSpecific) |
6a488035 TO |
206 | ); |
207 | } | |
208 | ||
209 | if ($this->_gName == 'case_status') { | |
02fc859b | 210 | $classes = array( |
353ffa53 | 211 | 'Opened' => ts('Opened'), |
6a488035 TO |
212 | 'Closed' => ts('Closed'), |
213 | ); | |
214 | ||
215 | $grouping = $this->add('select', | |
216 | 'grouping', | |
217 | ts('Status Class'), | |
218 | $classes | |
219 | ); | |
220 | if ($isReserved) { | |
221 | $grouping->freeze(); | |
222 | } | |
223 | } | |
224 | // CRM-11516 | |
225 | if ($this->_gName == 'payment_instrument') { | |
f743a6eb | 226 | $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' "); |
6a488035 | 227 | $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType)); |
8ef12e64 | 228 | |
229 | $this->add('select', 'financial_account_id', ts('Financial Account'), | |
fd1ae183 PN |
230 | array('' => ts('- select -')) + $financialAccount, |
231 | TRUE | |
6a488035 TO |
232 | ); |
233 | } | |
234 | ||
760ac501 CW |
235 | if ($this->_gName == 'activity_status') { |
236 | $this->add('select', | |
237 | 'filter', | |
238 | ts('Status Type'), | |
ce9d78e1 CW |
239 | array( |
240 | CRM_Activity_BAO_Activity::INCOMPLETE => ts('Incomplete'), | |
241 | CRM_Activity_BAO_Activity::COMPLETED => ts('Completed'), | |
242 | CRM_Activity_BAO_Activity::CANCELLED => ts('Cancelled'), | |
243 | ) | |
760ac501 | 244 | ); |
6a488035 | 245 | } |
760ac501 CW |
246 | if ($this->_gName == 'redaction_rule') { |
247 | $this->add('checkbox', | |
248 | 'filter', | |
249 | ts('Regular Expression?') | |
250 | ); | |
6a488035 TO |
251 | } |
252 | if ($this->_gName == 'participant_listing') { | |
253 | $this->add('text', | |
254 | 'description', | |
255 | ts('Description'), | |
256 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description') | |
257 | ); | |
258 | } | |
259 | else { | |
260 | // Hard-coding attributes here since description is still stored as varchar and not text in the schema. dgg | |
5d51a2f9 | 261 | $this->add('wysiwyg', 'description', |
6a488035 TO |
262 | ts('Description'), |
263 | array('rows' => 4, 'cols' => 80), | |
760ac501 | 264 | $this->_gName == 'custom_search' |
6a488035 TO |
265 | ); |
266 | } | |
267 | ||
268 | if ($this->_gName == 'event_badge') { | |
269 | $this->add('text', | |
270 | 'name', | |
271 | ts('Class Name'), | |
272 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'name') | |
273 | ); | |
274 | } | |
275 | ||
276 | $this->add('text', | |
277 | 'weight', | |
7ecddde4 | 278 | ts('Order'), |
6a488035 TO |
279 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), |
280 | TRUE | |
281 | ); | |
282 | $this->addRule('weight', ts('is a numeric field'), 'numeric'); | |
283 | ||
284 | // If CiviCase enabled AND "Add" mode OR "edit" mode for non-reserved activities, only allow user to pick Core or CiviCase component. | |
285 | // FIXME: Each component should define whether adding new activity types is allowed. | |
286 | $config = CRM_Core_Config::singleton(); | |
287 | if ($this->_gName == 'activity_type' && in_array("CiviCase", $config->enableComponents) && | |
288 | (($this->_action & CRM_Core_Action::ADD) || !$isReserved) | |
289 | ) { | |
290 | $caseID = CRM_Core_Component::getComponentID('CiviCase'); | |
5ce691e5 | 291 | $components = array('' => ts('Contacts AND Cases'), $caseID => ts('Cases Only')); |
6a488035 TO |
292 | $this->add('select', |
293 | 'component_id', | |
294 | ts('Component'), | |
295 | $components, FALSE | |
296 | ); | |
297 | } | |
298 | ||
299 | $enabled = $this->add('checkbox', 'is_active', ts('Enabled?')); | |
300 | ||
301 | if ($isReserved) { | |
302 | $enabled->freeze(); | |
303 | } | |
304 | ||
305 | //fix for CRM-3552, CRM-4575 | |
9eab4fdd | 306 | $showIsDefaultGroups = array( |
307 | 'email_greeting', | |
308 | 'postal_greeting', | |
309 | 'addressee', | |
310 | 'from_email_address', | |
311 | 'case_status', | |
312 | 'encounter_medium', | |
313 | 'case_type', | |
314 | 'payment_instrument', | |
315 | 'communication_style', | |
694ca46e | 316 | 'soft_credit_type', |
3fff8d1e | 317 | 'website_type', |
9eab4fdd | 318 | ); |
319 | ||
320 | if (in_array($this->_gName, $showIsDefaultGroups)) { | |
6a488035 TO |
321 | $this->assign('showDefault', TRUE); |
322 | $this->add('checkbox', 'is_default', ts('Default Option?')); | |
323 | } | |
324 | ||
325 | //get contact type for which user want to create a new greeting/addressee type, CRM-4575 | |
326 | if (in_array($this->_gName, array( | |
353ffa53 TO |
327 | 'email_greeting', |
328 | 'postal_greeting', | |
8d7a9d07 | 329 | 'addressee', |
353ffa53 TO |
330 | )) && !$isReserved |
331 | ) { | |
02fc859b | 332 | $values = array( |
353ffa53 | 333 | 1 => ts('Individual'), |
6a488035 TO |
334 | 2 => ts('Household'), |
335 | 3 => ts('Organization'), | |
336 | 4 => ts('Multiple Contact Merge'), | |
337 | ); | |
338 | $this->add('select', 'contactOptions', ts('Contact Type'), array('' => '-select-') + $values, TRUE); | |
339 | $this->assign('showContactFilter', TRUE); | |
340 | } | |
341 | ||
342 | if ($this->_gName == 'participant_status') { | |
343 | // For Participant Status options, expose the 'filter' field to track which statuses are "Counted", and the Visibility field | |
344 | $element = $this->add('checkbox', 'filter', ts('Counted?')); | |
345 | $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility()); | |
346 | } | |
347 | if ($this->_gName == 'participant_role') { | |
348 | // For Participant Role options, expose the 'filter' field to track which statuses are "Counted" | |
349 | $this->add('checkbox', 'filter', ts('Counted?')); | |
350 | } | |
351 | ||
352 | $this->addFormRule(array('CRM_Admin_Form_Options', 'formRule'), $this); | |
353 | } | |
354 | ||
355 | /** | |
eceb18cc | 356 | * Global form rule. |
6a488035 | 357 | * |
5173bd95 TO |
358 | * @param array $fields |
359 | * The input form values. | |
360 | * @param array $files | |
361 | * The uploaded files if any. | |
362 | * @param array $self | |
363 | * Current form object. | |
6a488035 | 364 | * |
a6c01b45 CW |
365 | * @return array |
366 | * array of errors / empty array. | |
6a488035 | 367 | */ |
00be9182 | 368 | public static function formRule($fields, $files, $self) { |
6a488035 | 369 | $errors = array(); |
8cc574cf | 370 | if ($self->_gName == 'case_status' && empty($fields['grouping'])) { |
6a488035 TO |
371 | $errors['grouping'] = ts('Status class is a required field'); |
372 | } | |
373 | ||
353ffa53 TO |
374 | if (in_array($self->_gName, array( |
375 | 'email_greeting', | |
376 | 'postal_greeting', | |
8d7a9d07 | 377 | 'addressee', |
353ffa53 TO |
378 | )) && empty($self->_defaultValues['is_reserved']) |
379 | ) { | |
380 | $label = $fields['label']; | |
381 | $condition = " AND v.label = '{$label}' "; | |
382 | $values = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter'); | |
6a488035 TO |
383 | $checkContactOptions = TRUE; |
384 | ||
385 | if ($self->_id && ($self->_defaultValues['contactOptions'] == $fields['contactOptions'])) { | |
386 | $checkContactOptions = FALSE; | |
387 | } | |
388 | ||
389 | if ($checkContactOptions && in_array($fields['contactOptions'], $values)) { | |
390 | $errors['label'] = ts('This Label already exists in the database for the selected contact type.'); | |
391 | } | |
392 | } | |
393 | ||
394 | if ($self->_gName == 'from_email_address') { | |
395 | $formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']); | |
396 | if (!CRM_Utils_Rule::email($formEmail)) { | |
f289559e | 397 | $errors['label'] = ts('Please enter a valid email address.'); |
6a488035 TO |
398 | } |
399 | ||
400 | $formName = explode('"', $fields['label']); | |
a7488080 | 401 | if (empty($formName[1]) || count($formName) != 3) { |
6a488035 TO |
402 | $errors['label'] = ts('Please follow the proper format for From Email Address'); |
403 | } | |
404 | } | |
405 | ||
d3b018ea | 406 | $dataType = self::getOptionGroupDataType($self->_gName); |
89c05afc | 407 | if ($dataType && $self->_gName !== 'activity_type') { |
d67d221a SL |
408 | $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE); |
409 | if (!$validate) { | |
410 | CRM_Core_Session::setStatus( | |
411 | ts('Data Type of the value field for this option value does not match ' . $dataType), | |
412 | ts('Value field Data Type mismatch')); | |
413 | } | |
414 | } | |
6a488035 TO |
415 | return $errors; |
416 | } | |
417 | ||
c62c37c7 SL |
418 | /** |
419 | * Get the DataType for a specified Option Group. | |
420 | * | |
1d4e5453 | 421 | * @param string $optionGroupName name of the option group |
c62c37c7 | 422 | * |
1d4e5453 | 423 | * @return string|null |
c62c37c7 SL |
424 | */ |
425 | public static function getOptionGroupDataType($optionGroupName) { | |
89c05afc | 426 | $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupName, 'id', 'name'); |
c62c37c7 | 427 | |
89c05afc | 428 | $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroupId); |
c62c37c7 SL |
429 | return $dataType; |
430 | } | |
431 | ||
6a488035 | 432 | /** |
eceb18cc | 433 | * Process the form submission. |
6a488035 TO |
434 | */ |
435 | public function postProcess() { | |
436 | if ($this->_action & CRM_Core_Action::DELETE) { | |
437 | $fieldValues = array('option_group_id' => $this->_gid); | |
438 | $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); | |
439 | ||
440 | if (CRM_Core_BAO_OptionValue::del($this->_id)) { | |
441 | if ($this->_gName == 'phone_type') { | |
442 | CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); | |
443 | } | |
444 | ||
6c2473d5 | 445 | CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success'); |
6a488035 TO |
446 | } |
447 | else { | |
6c2473d5 | 448 | CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error'); |
6a488035 TO |
449 | CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); |
450 | } | |
451 | } | |
452 | else { | |
6a488035 TO |
453 | $params = $this->exportValues(); |
454 | ||
455 | // allow multiple defaults within group. | |
456 | $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); | |
457 | if (in_array($this->_gName, $allowMultiDefaults)) { | |
458 | if ($this->_gName == 'from_email_address') { | |
459 | $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); | |
460 | } | |
461 | elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { | |
462 | $params['filter'] = $filter; | |
463 | $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); | |
464 | } | |
465 | ||
466 | //make sure we should has to have space, CRM-6977 | |
467 | if ($this->_gName == 'from_email_address') { | |
468 | $params['label'] = str_replace('"<', '" <', $params['label']); | |
469 | } | |
470 | } | |
471 | ||
74b187a2 KJ |
472 | // set value of filter if not present in params |
473 | if ($this->_id && !array_key_exists('filter', $params)) { | |
474 | if ($this->_gName == 'participant_role') { | |
475 | $params['filter'] = 0; | |
0db6c3e1 TO |
476 | } |
477 | else { | |
74b187a2 KJ |
478 | $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); |
479 | } | |
6a488035 TO |
480 | } |
481 | ||
b62580ac CW |
482 | if (isset($params['color']) && strtolower($params['color']) == '#ffffff') { |
483 | $params['color'] = 'null'; | |
484 | } | |
485 | ||
6a488035 TO |
486 | $groupParams = array('name' => ($this->_gName)); |
487 | $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); | |
8ef12e64 | 488 | |
6a488035 | 489 | // CRM-11516 |
a7488080 | 490 | if (!empty($params['financial_account_id'])) { |
f743a6eb | 491 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); |
6a488035 TO |
492 | $params = array( |
493 | 'entity_table' => 'civicrm_option_value', | |
494 | 'entity_id' => $optionValue->id, | |
495 | 'account_relationship' => $relationTypeId, | |
21dfd5f5 | 496 | 'financial_account_id' => $params['financial_account_id'], |
6a488035 TO |
497 | ); |
498 | CRM_Financial_BAO_FinancialTypeAccount::add($params); | |
499 | } | |
500 | ||
353ffa53 TO |
501 | CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array( |
502 | 1 => $this->_gLabel, | |
8d7a9d07 | 503 | 2 => $optionValue->label, |
353ffa53 | 504 | )), ts('Saved'), 'success'); |
7c2b40d1 CW |
505 | |
506 | $this->ajaxResponse['optionValue'] = $optionValue->toArray(); | |
6a488035 TO |
507 | } |
508 | } | |
e2046b33 | 509 | |
6a488035 | 510 | } |