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