Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
ce064e4f | 19 | * This class generates form components for Options. |
6a488035 TO |
20 | */ |
21 | class CRM_Admin_Form_Options extends CRM_Admin_Form { | |
22 | ||
23 | /** | |
eceb18cc | 24 | * The option group name. |
6a488035 TO |
25 | * |
26 | * @var array | |
6a488035 TO |
27 | */ |
28 | protected $_gName; | |
29 | ||
30 | /** | |
31 | * The option group name in display format (capitalized, without underscores...etc) | |
32 | * | |
33 | * @var array | |
6a488035 | 34 | */ |
6c2473d5 | 35 | protected $_gLabel; |
6a488035 | 36 | |
82f3aedc SL |
37 | /** |
38 | * Is this Option Group Domain Specific | |
39 | * @var bool | |
40 | */ | |
41 | protected $_domainSpecific = FALSE; | |
42 | ||
88aae6d4 A |
43 | /** |
44 | * @var bool | |
45 | */ | |
46 | public $submitOnce = TRUE; | |
47 | ||
6a488035 | 48 | /** |
100fef9d | 49 | * Pre-process |
6a488035 TO |
50 | */ |
51 | public function preProcess() { | |
52 | parent::preProcess(); | |
53 | $session = CRM_Core_Session::singleton(); | |
118e964e CW |
54 | if (!$this->_gName && !empty($this->urlPath[3])) { |
55 | $this->_gName = $this->urlPath[3]; | |
56 | } | |
57 | if (!$this->_gName && !empty($_GET['gid'])) { | |
58 | $this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', (int) $_GET['gid'], 'name'); | |
6a488035 TO |
59 | } |
60 | if ($this->_gName) { | |
61 | $this->set('gName', $this->_gName); | |
62 | } | |
63 | else { | |
64 | $this->_gName = $this->get('gName'); | |
65 | } | |
118e964e CW |
66 | $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', |
67 | $this->_gName, | |
68 | 'id', | |
69 | 'name' | |
70 | ); | |
faa2cea0 | 71 | $this->_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title'); |
2bf24361 | 72 | $this->_domainSpecific = CRM_Core_OptionGroup::isDomainOptionGroup($this->_gName); |
353ffa53 TO |
73 | $url = "civicrm/admin/options/{$this->_gName}"; |
74 | $params = "reset=1"; | |
6a488035 TO |
75 | |
76 | if (($this->_action & CRM_Core_Action::DELETE) && | |
be2fb01f | 77 | in_array($this->_gName, ['email_greeting', 'postal_greeting', 'addressee']) |
6a488035 TO |
78 | ) { |
79 | // Don't allow delete if the option value belongs to addressee, postal or email greetings and is in use. | |
353ffa53 | 80 | $findValue = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'value'); |
be2fb01f | 81 | $queryParam = [1 => [$findValue, 'Integer']]; |
6a488035 | 82 | $columnName = $this->_gName . "_id"; |
353ffa53 TO |
83 | $sql = "SELECT count(id) FROM civicrm_contact WHERE " . $columnName . " = %1"; |
84 | $isInUse = CRM_Core_DAO::singleValueQuery($sql, $queryParam); | |
6a488035 TO |
85 | if ($isInUse) { |
86 | $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>"; | |
be2fb01f | 87 | 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', [ |
0d48f1cc TO |
88 | 1 => $this->_gLabel, |
89 | 2 => $scriptURL, | |
90 | ]), ts('Sorry'), 'error'); | |
6a488035 TO |
91 | $redirect = CRM_Utils_System::url($url, $params); |
92 | CRM_Utils_System::redirect($redirect); | |
93 | } | |
94 | } | |
95 | ||
6a488035 TO |
96 | $session->pushUserContext(CRM_Utils_System::url($url, $params)); |
97 | $this->assign('id', $this->_id); | |
98 | ||
2bf24361 | 99 | if ($this->_id && CRM_Core_OptionGroup::isDomainOptionGroup($this->_gName)) { |
6a488035 TO |
100 | $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id'); |
101 | if (CRM_Core_Config::domainID() != $domainID) { | |
beb414cc | 102 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
6a488035 TO |
103 | } |
104 | } | |
105 | } | |
106 | ||
107 | /** | |
c490a46a | 108 | * Set default values for the form. |
6a488035 | 109 | */ |
00be9182 | 110 | public function setDefaultValues() { |
6a488035 TO |
111 | $defaults = parent::setDefaultValues(); |
112 | ||
2b90b596 | 113 | // Default weight & value |
be2fb01f CW |
114 | $fieldValues = ['option_group_id' => $this->_gid]; |
115 | foreach (['weight', 'value'] as $field) { | |
e09f60e4 | 116 | if (!isset($defaults[$field]) || $defaults[$field] === '') { |
2b90b596 CW |
117 | $defaults[$field] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, $field); |
118 | } | |
6a488035 TO |
119 | } |
120 | ||
0ef97236 | 121 | // setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575 |
be2fb01f | 122 | if (in_array($this->_gName, [ |
353ffa53 TO |
123 | 'email_greeting', |
124 | 'postal_greeting', | |
8d7a9d07 | 125 | 'addressee', |
be2fb01f | 126 | ])) { |
6a488035 TO |
127 | $defaults['contactOptions'] = (CRM_Utils_Array::value('filter', $defaults)) ? $defaults['filter'] : NULL; |
128 | } | |
129 | // CRM-11516 | |
130 | if ($this->_gName == 'payment_instrument' && $this->_id) { | |
74afdc40 | 131 | $defaults['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($this->_id, NULL, 'civicrm_option_value'); |
6a488035 | 132 | } |
b62580ac CW |
133 | if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'color')) { |
134 | $defaults['color'] = '#ffffff'; | |
135 | } | |
6a488035 TO |
136 | return $defaults; |
137 | } | |
138 | ||
139 | /** | |
eceb18cc | 140 | * Build the form object. |
6a488035 TO |
141 | */ |
142 | public function buildQuickForm() { | |
143 | parent::buildQuickForm(); | |
be2fb01f | 144 | $this->setPageTitle(ts('%1 Option', [1 => $this->_gLabel])); |
e2046b33 | 145 | |
6a488035 TO |
146 | if ($this->_action & CRM_Core_Action::DELETE) { |
147 | return; | |
148 | } | |
149 | ||
c9ae8a39 CW |
150 | $optionGroup = \Civi\Api4\OptionGroup::get(FALSE) |
151 | ->addWhere('id', '=', $this->_gid) | |
152 | ->execute()->first(); | |
153 | ||
6a488035 TO |
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 | ); | |
e5720c45 | 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 | ); | |
82f3aedc SL |
175 | $this->addRule('value', |
176 | ts('This Value already exists in the database for this option group. Please select a different Value.'), | |
177 | 'optionExists', | |
be2fb01f | 178 | ['CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'value', $this->_domainSpecific] |
82f3aedc | 179 | ); |
635a99e5 | 180 | } |
c9ae8a39 CW |
181 | |
182 | // Add icon & color if this option group supports it. | |
183 | if ($optionGroup['option_value_fields'] && in_array('icon', $optionGroup['option_value_fields'])) { | |
be2fb01f | 184 | $this->add('text', 'icon', ts('Icon'), ['class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE]); |
0c6fe5b5 | 185 | } |
c9ae8a39 | 186 | if ($optionGroup['option_value_fields'] && in_array('color', $optionGroup['option_value_fields'])) { |
b62580ac CW |
187 | $this->add('color', 'color', ts('Color')); |
188 | } | |
189 | ||
0d48f1cc TO |
190 | if (!in_array($this->_gName, ['email_greeting', 'postal_greeting', 'addressee']) |
191 | && !$isReserved | |
353ffa53 | 192 | ) { |
6a488035 | 193 | $this->addRule('label', |
82f3aedc | 194 | ts('This Label already exists in the database for this option group. Please select a different Label.'), |
6a488035 | 195 | 'optionExists', |
be2fb01f | 196 | ['CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label', $this->_domainSpecific] |
6a488035 TO |
197 | ); |
198 | } | |
199 | ||
200 | if ($this->_gName == 'case_status') { | |
be2fb01f | 201 | $classes = [ |
353ffa53 | 202 | 'Opened' => ts('Opened'), |
6a488035 | 203 | 'Closed' => ts('Closed'), |
be2fb01f | 204 | ]; |
6a488035 TO |
205 | |
206 | $grouping = $this->add('select', | |
207 | 'grouping', | |
208 | ts('Status Class'), | |
209 | $classes | |
210 | ); | |
211 | if ($isReserved) { | |
212 | $grouping->freeze(); | |
213 | } | |
214 | } | |
215 | // CRM-11516 | |
216 | if ($this->_gName == 'payment_instrument') { | |
f743a6eb | 217 | $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' "); |
6a488035 | 218 | $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType)); |
8ef12e64 | 219 | |
220 | $this->add('select', 'financial_account_id', ts('Financial Account'), | |
be2fb01f | 221 | ['' => ts('- select -')] + $financialAccount, |
fd1ae183 | 222 | TRUE |
6a488035 TO |
223 | ); |
224 | } | |
225 | ||
760ac501 CW |
226 | if ($this->_gName == 'activity_status') { |
227 | $this->add('select', | |
228 | 'filter', | |
229 | ts('Status Type'), | |
be2fb01f | 230 | [ |
ce9d78e1 CW |
231 | CRM_Activity_BAO_Activity::INCOMPLETE => ts('Incomplete'), |
232 | CRM_Activity_BAO_Activity::COMPLETED => ts('Completed'), | |
233 | CRM_Activity_BAO_Activity::CANCELLED => ts('Cancelled'), | |
be2fb01f | 234 | ] |
760ac501 | 235 | ); |
6a488035 | 236 | } |
760ac501 CW |
237 | if ($this->_gName == 'redaction_rule') { |
238 | $this->add('checkbox', | |
239 | 'filter', | |
240 | ts('Regular Expression?') | |
241 | ); | |
6a488035 TO |
242 | } |
243 | if ($this->_gName == 'participant_listing') { | |
244 | $this->add('text', | |
245 | 'description', | |
246 | ts('Description'), | |
247 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description') | |
248 | ); | |
249 | } | |
250 | else { | |
251 | // Hard-coding attributes here since description is still stored as varchar and not text in the schema. dgg | |
5d51a2f9 | 252 | $this->add('wysiwyg', 'description', |
6a488035 | 253 | ts('Description'), |
be2fb01f | 254 | ['rows' => 4, 'cols' => 80], |
760ac501 | 255 | $this->_gName == 'custom_search' |
6a488035 TO |
256 | ); |
257 | } | |
258 | ||
259 | if ($this->_gName == 'event_badge') { | |
260 | $this->add('text', | |
261 | 'name', | |
262 | ts('Class Name'), | |
263 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'name') | |
264 | ); | |
265 | } | |
266 | ||
d70ada2a | 267 | $this->add('number', |
6a488035 | 268 | 'weight', |
7ecddde4 | 269 | ts('Order'), |
6a488035 TO |
270 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), |
271 | TRUE | |
272 | ); | |
273 | $this->addRule('weight', ts('is a numeric field'), 'numeric'); | |
274 | ||
275 | // If CiviCase enabled AND "Add" mode OR "edit" mode for non-reserved activities, only allow user to pick Core or CiviCase component. | |
276 | // FIXME: Each component should define whether adding new activity types is allowed. | |
e46f73c7 | 277 | if ($this->_gName == 'activity_type' && CRM_Core_Component::isEnabled("CiviCase") && |
6a488035 TO |
278 | (($this->_action & CRM_Core_Action::ADD) || !$isReserved) |
279 | ) { | |
280 | $caseID = CRM_Core_Component::getComponentID('CiviCase'); | |
be2fb01f | 281 | $components = ['' => 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 | ||
0ef97236 | 295 | // fix for CRM-3552, CRM-4575 |
be2fb01f | 296 | $showIsDefaultGroups = [ |
9eab4fdd | 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', |
be2fb01f | 308 | ]; |
9eab4fdd | 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 | ||
0ef97236 | 315 | // get contact type for which user want to create a new greeting/addressee type, CRM-4575 |
0d48f1cc TO |
316 | if (in_array($this->_gName, ['email_greeting', 'postal_greeting', 'addressee']) |
317 | && !$isReserved | |
353ffa53 | 318 | ) { |
be2fb01f | 319 | $values = [ |
353ffa53 | 320 | 1 => ts('Individual'), |
6a488035 TO |
321 | 2 => ts('Household'), |
322 | 3 => ts('Organization'), | |
323 | 4 => ts('Multiple Contact Merge'), | |
be2fb01f CW |
324 | ]; |
325 | $this->add('select', 'contactOptions', ts('Contact Type'), ['' => '-select-'] + $values, TRUE); | |
6a488035 TO |
326 | $this->assign('showContactFilter', TRUE); |
327 | } | |
328 | ||
329 | if ($this->_gName == 'participant_status') { | |
330 | // For Participant Status options, expose the 'filter' field to track which statuses are "Counted", and the Visibility field | |
0ef97236 | 331 | $this->add('checkbox', 'filter', ts('Counted?')); |
6a488035 TO |
332 | $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility()); |
333 | } | |
334 | if ($this->_gName == 'participant_role') { | |
335 | // For Participant Role options, expose the 'filter' field to track which statuses are "Counted" | |
336 | $this->add('checkbox', 'filter', ts('Counted?')); | |
337 | } | |
338 | ||
be2fb01f | 339 | $this->addFormRule(['CRM_Admin_Form_Options', 'formRule'], $this); |
6a488035 TO |
340 | } |
341 | ||
342 | /** | |
eceb18cc | 343 | * Global form rule. |
6a488035 | 344 | * |
5173bd95 TO |
345 | * @param array $fields |
346 | * The input form values. | |
347 | * @param array $files | |
348 | * The uploaded files if any. | |
e0f5b841 | 349 | * @param self $self |
5173bd95 | 350 | * Current form object. |
6a488035 | 351 | * |
a6c01b45 CW |
352 | * @return array |
353 | * array of errors / empty array. | |
0ef97236 | 354 | * @throws \CRM_Core_Exception |
6a488035 | 355 | */ |
00be9182 | 356 | public static function formRule($fields, $files, $self) { |
be2fb01f | 357 | $errors = []; |
8cc574cf | 358 | if ($self->_gName == 'case_status' && empty($fields['grouping'])) { |
6a488035 TO |
359 | $errors['grouping'] = ts('Status class is a required field'); |
360 | } | |
361 | ||
0d48f1cc TO |
362 | if (in_array($self->_gName, ['email_greeting', 'postal_greeting', 'addressee']) |
363 | && empty($self->_defaultValues['is_reserved']) | |
353ffa53 TO |
364 | ) { |
365 | $label = $fields['label']; | |
366 | $condition = " AND v.label = '{$label}' "; | |
367 | $values = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter'); | |
6a488035 TO |
368 | $checkContactOptions = TRUE; |
369 | ||
370 | if ($self->_id && ($self->_defaultValues['contactOptions'] == $fields['contactOptions'])) { | |
371 | $checkContactOptions = FALSE; | |
372 | } | |
373 | ||
374 | if ($checkContactOptions && in_array($fields['contactOptions'], $values)) { | |
375 | $errors['label'] = ts('This Label already exists in the database for the selected contact type.'); | |
376 | } | |
377 | } | |
378 | ||
379 | if ($self->_gName == 'from_email_address') { | |
380 | $formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']); | |
381 | if (!CRM_Utils_Rule::email($formEmail)) { | |
f289559e | 382 | $errors['label'] = ts('Please enter a valid email address.'); |
6a488035 TO |
383 | } |
384 | ||
385 | $formName = explode('"', $fields['label']); | |
a7488080 | 386 | if (empty($formName[1]) || count($formName) != 3) { |
6a488035 TO |
387 | $errors['label'] = ts('Please follow the proper format for From Email Address'); |
388 | } | |
389 | } | |
390 | ||
d3b018ea | 391 | $dataType = self::getOptionGroupDataType($self->_gName); |
89c05afc | 392 | if ($dataType && $self->_gName !== 'activity_type') { |
d67d221a | 393 | $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE); |
ce7ccb1e | 394 | if ($validate === FALSE) { |
d67d221a | 395 | CRM_Core_Session::setStatus( |
6dabf459 | 396 | ts('Data Type of the value field for this option value does not match %1.', [1 => $dataType]), |
d67d221a SL |
397 | ts('Value field Data Type mismatch')); |
398 | } | |
399 | } | |
6a488035 TO |
400 | return $errors; |
401 | } | |
402 | ||
c62c37c7 SL |
403 | /** |
404 | * Get the DataType for a specified Option Group. | |
405 | * | |
1d4e5453 | 406 | * @param string $optionGroupName name of the option group |
c62c37c7 | 407 | * |
1d4e5453 | 408 | * @return string|null |
c62c37c7 SL |
409 | */ |
410 | public static function getOptionGroupDataType($optionGroupName) { | |
89c05afc | 411 | $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupName, 'id', 'name'); |
c62c37c7 | 412 | |
89c05afc | 413 | $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroupId); |
c62c37c7 SL |
414 | return $dataType; |
415 | } | |
416 | ||
6a488035 | 417 | /** |
eceb18cc | 418 | * Process the form submission. |
6a488035 TO |
419 | */ |
420 | public function postProcess() { | |
421 | if ($this->_action & CRM_Core_Action::DELETE) { | |
be2fb01f | 422 | $fieldValues = ['option_group_id' => $this->_gid]; |
0ef97236 | 423 | CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); |
6a488035 TO |
424 | |
425 | if (CRM_Core_BAO_OptionValue::del($this->_id)) { | |
426 | if ($this->_gName == 'phone_type') { | |
427 | CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); | |
428 | } | |
429 | ||
be2fb01f | 430 | CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', [1 => $this->_gLabel]), ts('Record Deleted'), 'success'); |
6a488035 TO |
431 | } |
432 | else { | |
be2fb01f | 433 | CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', [1 => $this->_gLabel]), ts('Sorry'), 'error'); |
6a488035 TO |
434 | CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); |
435 | } | |
436 | } | |
437 | else { | |
6a488035 TO |
438 | $params = $this->exportValues(); |
439 | ||
440 | // allow multiple defaults within group. | |
be2fb01f | 441 | $allowMultiDefaults = ['email_greeting', 'postal_greeting', 'addressee', 'from_email_address']; |
6a488035 TO |
442 | if (in_array($this->_gName, $allowMultiDefaults)) { |
443 | if ($this->_gName == 'from_email_address') { | |
be2fb01f | 444 | $params['reset_default_for'] = ['domain_id' => CRM_Core_Config::domainID()]; |
6a488035 TO |
445 | } |
446 | elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { | |
447 | $params['filter'] = $filter; | |
be2fb01f | 448 | $params['reset_default_for'] = ['filter' => "0, " . $params['filter']]; |
6a488035 TO |
449 | } |
450 | ||
c65ce897 | 451 | //make sure we only have a single space, CRM-6977 and dev/mail/15 |
6a488035 | 452 | if ($this->_gName == 'from_email_address') { |
ccbfdc72 | 453 | $params['label'] = $this->sanitizeFromEmailAddress($params['label']); |
6a488035 TO |
454 | } |
455 | } | |
456 | ||
74b187a2 KJ |
457 | // set value of filter if not present in params |
458 | if ($this->_id && !array_key_exists('filter', $params)) { | |
459 | if ($this->_gName == 'participant_role') { | |
460 | $params['filter'] = 0; | |
0db6c3e1 TO |
461 | } |
462 | else { | |
74b187a2 KJ |
463 | $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); |
464 | } | |
6a488035 TO |
465 | } |
466 | ||
b62580ac CW |
467 | if (isset($params['color']) && strtolower($params['color']) == '#ffffff') { |
468 | $params['color'] = 'null'; | |
469 | } | |
470 | ||
ff625280 | 471 | $optionValue = CRM_Core_OptionValue::addOptionValue($params, $this->_gName, $this->_action, $this->_id); |
8ef12e64 | 472 | |
be2fb01f | 473 | CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', [ |
0d48f1cc TO |
474 | 1 => $this->_gLabel, |
475 | 2 => $optionValue->label, | |
476 | ]), ts('Saved'), 'success'); | |
7c2b40d1 CW |
477 | |
478 | $this->ajaxResponse['optionValue'] = $optionValue->toArray(); | |
6a488035 TO |
479 | } |
480 | } | |
e2046b33 | 481 | |
ccbfdc72 MM |
482 | public function sanitizeFromEmailAddress($email) { |
483 | preg_match("/^\"(.*)\" *<([^@>]*@[^@>]*)>$/", $email, $parts); | |
484 | return "\"{$parts[1]}\" <$parts[2]>"; | |
485 | } | |
486 | ||
6a488035 | 487 | } |