Passed
Pull Request — development (#3837)
by Spuds
08:46
created

ManageCustomProfile   F

Complexity

Total Complexity 84

Size/Duplication

Total Lines 691
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 379
dl 0
loc 691
rs 2
c 1
b 0
f 0
wmc 84

4 Methods

Rating   Name   Duplication   Size   Complexity  
A pre_dispatch() 0 6 1
A action_index() 0 13 1
F action_profileedit() 0 348 61
F action_profile() 0 295 21

How to fix   Complexity   

Complex Class

Complex classes like ManageCustomProfile often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ManageCustomProfile, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Manage custom profile fields administration page.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * This file contains code covered by:
11
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
12
 *
13
 * @version 2.0 Beta 1
14
 *
15
 */
16
17
namespace ElkArte\AdminController;
18
19
use ElkArte\AbstractController;
20
use ElkArte\Action;
21
use ElkArte\Exceptions\Exception;
22
use ElkArte\Helper\Util;
23
use ElkArte\Languages\Txt;
24
25
/**
26
 * Custom Profile fields administration controller.
27
 * This class allows modifying custom profile fields for the forum.
28
 */
29
class ManageCustomProfile extends AbstractController
30
{
31
	/**
32
	 * Pre-dispatch, called before other methods.
33
	 */
34
	public function pre_dispatch()
35
	{
36
		// We need this in a few places, so it's easier to have it loaded here
37
		require_once(SUBSDIR . '/ManageFeatures.subs.php');
38
39
		Txt::load('Help+ManageSettings');
40
	}
41
42
	/**
43
	 * Default action for this controller.
44
	 */
45
	public function action_index()
46
	{
47
		$subActions = [
48
			'profile' => [$this, 'action_profile', 'enabled' => featureEnabled('cp'), 'permission' => 'admin_forum'],
49
			'profileedit' => [$this, 'action_profileedit', 'enabled' => featureEnabled('cp'), 'permission' => 'admin_forum'],
50
		];
51
52
		// Set up the action control
53
		$action = new Action('modify_profile');
54
55
		// By default, do the profile list
56
		$subAction = $action->initialize($subActions, 'profile');
57
		$action->dispatch($subAction);
58
	}
59
60
	/**
61
	 * Show all the custom profile fields available to the user.
62
	 *
63
	 * - Allows for drag/drop sorting of custom profile fields
64
	 * - Accessed with ?action=admin;area=featuresettings;sa=profile
65
	 *
66
	 * @uses sub template show_custom_profile
67
	 */
68
	public function action_profile(): void
69
	{
70
		global $txt, $context;
71
72
		theme()->getTemplates()->load('ManageFeatures');
73
		$context['page_title'] = $txt['custom_profile_title'];
74
		$context['sub_template'] = 'show_custom_profile';
75
76
		// What about standard fields they can tweak?
77
		$standard_fields = ['website', 'posts', 'warning_status', 'date_registered', 'action'];
78
79
		// What fields can't you put on the registration page?
80
		$context['fields_no_registration'] = ['posts', 'warning_status', 'date_registered', 'action'];
81
82
		// Are we saving any standard field changes?
83
		if ($this->_req->hasPost('save'))
84
		{
85
			checkSession();
86
			validateToken('admin-scp');
87
88
			$changes = [];
89
90
			// Do the active ones first.
91
			$disable_fields = array_flip($standard_fields);
92
			if (!empty($this->_req->post->active))
93
			{
94
				foreach ($this->_req->post->active as $value)
95
				{
96
					if (isset($disable_fields[$value]))
97
					{
98
						unset($disable_fields[$value]);
99
					}
100
				}
101
			}
102
103
			// What we have left!
104
			$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
105
106
			// Things we want to show on registration?
107
			$reg_fields = [];
108
			if (!empty($this->_req->post->reg))
109
			{
110
				foreach ($this->_req->post->reg as $value)
111
				{
112
					if (!in_array($value, $standard_fields))
113
					{
114
						continue;
115
					}
116
117
					if (isset($disable_fields[$value]))
118
					{
119
						continue;
120
					}
121
122
					$reg_fields[] = $value;
123
				}
124
			}
125
126
			// What we have left!
127
			$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
128
129
			updateSettings($changes);
130
		}
131
132
		createToken('admin-scp');
133
134
		// Create a listing for all our standard fields
135
		$listOptions = [
136
			'id' => 'standard_profile_fields',
137
			'title' => $txt['standard_profile_title'],
138
			'base_href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']),
139
			'get_items' => [
140
				'function' => 'list_getProfileFields',
141
				'params' => [
142
					true,
143
				],
144
			],
145
			'columns' => [
146
				'field' => [
147
					'header' => [
148
						'value' => $txt['standard_profile_field'],
149
					],
150
					'data' => [
151
						'db' => 'label',
152
						'style' => 'width: 60%;',
153
					],
154
				],
155
				'active' => [
156
					'header' => [
157
						'value' => $txt['custom_edit_active'],
158
						'class' => 'centertext',
159
					],
160
					'data' => [
161
						'function' => static function ($rowData) {
162
							$isChecked = $rowData['disabled'] ? '' : ' checked="checked"';
163
							$onClickHandler = $rowData['can_show_register'] ? sprintf('onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
164
165
							return sprintf('<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" class="input_check" %2$s %3$s />', $rowData['id'], $isChecked, $onClickHandler);
166
						},
167
						'style' => 'width: 20%;',
168
						'class' => 'centertext',
169
					],
170
				],
171
				'show_on_registration' => [
172
					'header' => [
173
						'value' => $txt['custom_edit_registration'],
174
						'class' => 'centertext',
175
					],
176
					'data' => [
177
						'function' => static function ($rowData) {
178
							$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked="checked"' : '';
179
							$isDisabled = $rowData['can_show_register'] ? '' : ' disabled="disabled"';
180
181
							return sprintf('<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" class="input_check" %2$s %3$s />', $rowData['id'], $isChecked, $isDisabled);
182
						},
183
						'style' => 'width: 20%;',
184
						'class' => 'centertext',
185
					],
186
				],
187
			],
188
			'form' => [
189
				'href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']),
190
				'name' => 'standardProfileFields',
191
				'token' => 'admin-scp',
192
			],
193
			'additional_rows' => [
194
				[
195
					'position' => 'below_table_data',
196
					'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="right_submit" />',
197
				],
198
			],
199
		];
200
		createList($listOptions);
201
202
		// And now we do the same for all of our custom ones
203
		$token = createToken('admin-sort');
204
		$listOptions = [
205
			'id' => 'custom_profile_fields',
206
			'title' => $txt['custom_profile_title'],
207
			'base_href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']),
208
			'default_sort_col' => 'vieworder',
209
			'no_items_label' => $txt['custom_profile_none'],
210
			'items_per_page' => 25,
211
			'sortable' => true,
212
			'get_items' => [
213
				'function' => 'list_getProfileFields',
214
				'params' => [
215
					false,
216
				],
217
			],
218
			'get_count' => [
219
				'function' => 'list_getProfileFieldSize',
220
			],
221
			'columns' => [
222
				'vieworder' => [
223
					'header' => [
224
						'value' => '',
225
						'class' => 'hide',
226
					],
227
					'data' => [
228
						'db' => 'vieworder',
229
						'class' => 'hide',
230
					],
231
					'sort' => [
232
						'default' => 'vieworder',
233
					],
234
				],
235
				'field_name' => [
236
					'header' => [
237
						'value' => $txt['custom_profile_fieldname'],
238
					],
239
					'data' => [
240
						'function' => static fn($rowData) => sprintf('<a href="%1$s">%2$s</a><div class="smalltext">%3$s</div>', getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit', 'fid' => (int) $rowData['id_field']]), $rowData['field_name'], $rowData['field_desc']),
241
						'style' => 'width: 65%;',
242
					],
243
					'sort' => [
244
						'default' => 'field_name',
245
						'reverse' => 'field_name DESC',
246
					],
247
				],
248
				'field_type' => [
249
					'header' => [
250
						'value' => $txt['custom_profile_fieldtype'],
251
					],
252
					'data' => [
253
						'function' => static function ($rowData) {
254
							global $txt;
255
256
							$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
257
258
							return $txt[$textKey] ?? $textKey;
259
						},
260
						'style' => 'width: 10%;',
261
					],
262
					'sort' => [
263
						'default' => 'field_type',
264
						'reverse' => 'field_type DESC',
265
					],
266
				],
267
				'cust' => [
268
					'header' => [
269
						'value' => $txt['custom_profile_active'],
270
						'class' => 'centertext',
271
					],
272
					'data' => [
273
						'function' => static function ($rowData) {
274
							$isChecked = $rowData['active'] === '1' ? ' checked="checked"' : '';
275
276
							return sprintf('<input type="checkbox" name="cust[]" id="cust_%1$s" value="%1$s" class="input_check"%2$s />', $rowData['id_field'], $isChecked);
277
						},
278
						'style' => 'width: 8%;',
279
						'class' => 'centertext',
280
					],
281
					'sort' => [
282
						'default' => 'active DESC',
283
						'reverse' => 'active',
284
					],
285
				],
286
				'placement' => [
287
					'header' => [
288
						'value' => $txt['custom_profile_placement'],
289
					],
290
					'data' => [
291
						'function' => static function ($rowData) {
292
							global $txt;
293
294
							$placement = 'custom_profile_placement_';
295
							switch ((int) $rowData['placement'])
296
							{
297
								case 0:
298
									$placement .= 'standard';
299
									break;
300
								case 1:
301
									$placement .= 'withicons';
302
									break;
303
								case 2:
304
									$placement .= 'abovesignature';
305
									break;
306
								case 3:
307
									$placement .= 'aboveicons';
308
									break;
309
							}
310
311
							return $txt[$placement];
312
						},
313
						'style' => 'width: 5%;',
314
					],
315
					'sort' => [
316
						'default' => 'placement DESC',
317
						'reverse' => 'placement',
318
					],
319
				],
320
				'modify' => [
321
					'data' => [
322
						'sprintf' => [
323
							'format' => '<a href="' . getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit']) . ';fid=%1$s">' . $txt['modify'] . '</a>',
324
							'params' => [
325
								'id_field' => false,
326
							],
327
						],
328
						'style' => 'width: 5%;',
329
					],
330
				],
331
			],
332
			'form' => [
333
				'href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit']),
334
				'name' => 'customProfileFields',
335
				'token' => 'admin-scp',
336
			],
337
			'additional_rows' => [
338
				[
339
					'class' => 'submitbutton flow_flex_additional_row',
340
					'position' => 'below_table_data',
341
					'value' => '
342
						<input type="submit" name="onoff" value="' . $txt['save'] . '" />
343
						<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" />',
344
				],
345
				[
346
					'position' => 'top_of_list',
347
					'value' => '<p class="infobox">' . $txt['custom_profile_sort'] . '</p>',
348
				],
349
			],
350
			'javascript' => '
351
				$().elkSortable({
352
					sa: "profileorder",
353
					error: "' . $txt['admin_order_error'] . '",
354
					title: "' . $txt['admin_order_title'] . '",
355
					placeholder: "ui-state-highlight",
356
					href: "?action=admin;area=featuresettings;sa=profile",
357
					token: {token_var: "' . $token['admin-sort_token_var'] . '", token_id: "' . $token['admin-sort_token'] . '"}
358
				});
359
			',
360
		];
361
362
		createList($listOptions);
363
	}
364
365
	/**
366
	 * Edit some profile fields?
367
	 *
368
	 * - Accessed with ?action=admin;area=featuresettings;sa=profileedit
369
	 *
370
	 * @uses sub template edit_profile_field
371
	 */
372
	public function action_profileedit(): void
373
	{
374
		global $txt, $context;
375
376
		theme()->getTemplates()->load('ManageFeatures');
377
378
		// Sort out the context!
379
		$context['fid'] = $this->_req->getQuery('fid', 'intval', 0);
380
		$context[$context['admin_menu_name']]['current_subsection'] = 'profile';
381
		$context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
382
		$context['sub_template'] = 'edit_profile_field';
383
384
		// Any error messages to show?
385
		if ($this->_req->hasQuery('msg'))
386
		{
387
			Txt::load('Errors');
388
			$msg_key = $this->_req->getQuery('msg', 'trim|strval', '');
389
			if (isset($txt['custom_option_' . $msg_key]))
390
			{
391
				$context['custom_option__error'] = $txt['custom_option_' . $msg_key];
392
			}
393
		}
394
395
		// Load the profile language for section names.
396
		Txt::load('Profile');
397
398
		// Load up the profile field if one was supplied
399
		if ($context['fid'])
400
		{
401
			$context['field'] = getProfileField($context['fid']);
402
		}
403
404
		// Set up the default values as needed.
405
		if (empty($context['field']))
406
		{
407
			$context['field'] = [
408
				'name' => '',
409
				'colname' => '???',
410
				'desc' => '',
411
				'profile_area' => 'forumprofile',
412
				'reg' => false,
413
				'display' => false,
414
				'memberlist' => false,
415
				'type' => 'text',
416
				'max_length' => 255,
417
				'rows' => 4,
418
				'cols' => 30,
419
				'bbc' => false,
420
				'default_check' => false,
421
				'default_select' => '',
422
				'default_value' => '',
423
				'options' => ['', '', ''],
424
				'active' => true,
425
				'private' => false,
426
				'can_search' => false,
427
				'mask' => 'nohtml',
428
				'regex' => '',
429
				'enclose' => '',
430
				'placement' => 0,
431
			];
432
		}
433
434
		// All the JavaScript for this page... everything else is in admin.js
435
		theme()->addJavascriptVar(['startOptID' => count($context['field']['options'])]);
436
		theme()->addInlineJavascript('updateInputBoxes();', true);
437
438
		// Are we toggling which ones are active?
439
		if (isset($this->_req->post->onoff))
440
		{
441
			checkSession();
442
			validateToken('admin-scp');
443
444
			// Enable and disable custom fields as required.
445
			$enabled = [0];
446
			if (isset($this->_req->post->cust) && is_array($this->_req->post->cust))
447
			{
448
				foreach ($this->_req->post->cust as $id)
449
				{
450
					$enabled[] = (int) $id;
451
				}
452
			}
453
454
			updateRenamedProfileStatus($enabled);
455
		}
456
		// Are we saving?
457
		elseif ($this->_req->hasPost('save'))
458
		{
459
			checkSession();
460
			validateToken('admin-ecp');
461
462
			// Everyone needs a name - even the (bracket) unknown...
463
			if (trim($this->_req->post->field_name) === '')
464
			{
465
				redirectexit('action=admin;area=featuresettings;sa=profileedit;fid=' . (int) $context['fid'] . ';msg=need_name');
466
			}
467
468
			// Regex, you say?  Do a very basic test to see if the pattern is valid
469
			if (!empty($this->_req->post->regex) && @preg_match($this->_req->post->regex, 'dummy') === false)
470
			{
471
				redirectexit('action=admin;area=featuresettings;sa=profileedit;fid=' . (int) $context['fid'] . ';msg=regex_error');
472
			}
473
474
			$this->_req->post->field_name = $this->_req->getPost('field_name', 'Util::htmlspecialchars');
475
			$this->_req->post->field_desc = $this->_req->getPost('field_desc', 'Util::htmlspecialchars');
476
477
			$rows = isset($this->_req->post->rows) ? (int) $this->_req->post->rows : 4;
478
			$cols = isset($this->_req->post->cols) ? (int) $this->_req->post->cols : 30;
479
480
			// Checkboxes...
481
			$show_reg = $this->_req->getPost('reg', 'intval', 0);
482
			$show_display = isset($this->_req->post->display) ? 1 : 0;
483
			$show_memberlist = isset($this->_req->post->memberlist) ? 1 : 0;
484
			$bbc = isset($this->_req->post->bbc) ? 1 : 0;
485
			$show_profile = $this->_req->post->profile_area;
486
			$active = isset($this->_req->post->active) ? 1 : 0;
487
			$private = $this->_req->getPost('private', 'intval', 0);
488
			$can_search = isset($this->_req->post->can_search) ? 1 : 0;
489
490
			// Some masking stuff...
491
			$mask = $this->_req->getPost('mask', 'strval', '');
492
			if ($mask === 'regex' && isset($this->_req->post->regex))
493
			{
494
				$mask .= $this->_req->post->regex;
495
			}
496
497
			$field_length = $this->_req->getPost('max_length', 'intval', 255);
498
			$enclose = $this->_req->getPost('enclose', 'strval', '');
499
			$placement = $this->_req->getPost('placement', 'intval', 0);
500
501
			// Select options?
502
			$field_options = '';
503
			$newOptions = [];
504
505
			// Set default
506
			$default = '';
507
508
			switch ($this->_req->post->field_type)
509
			{
510
				case 'check':
511
					$default = isset($this->_req->post->default_check) ? 1 : '';
512
					break;
513
				case 'select':
514
				case 'radio':
515
					if (!empty($this->_req->post->select_option))
516
					{
517
						foreach ($this->_req->post->select_option as $k => $v)
518
						{
519
							// Clean, clean, clean...
520
							$v = Util::htmlspecialchars($v);
521
							$v = strtr($v, [',' => '']);
522
523
							// Nada, zip, etc...
524
							if (trim($v) === '')
525
							{
526
								continue;
527
							}
528
529
							// Otherwise, save it boy.
530
							$field_options .= $v . ',';
531
532
							// This is just for working out what happened with old options...
533
							$newOptions[$k] = $v;
534
535
							// Is it default?
536
							if (!isset($this->_req->post->default_select))
537
							{
538
								continue;
539
							}
540
541
							if ($this->_req->post->default_select != $k)
542
							{
543
								continue;
544
							}
545
546
							$default = $v;
547
						}
548
549
						if (isset($_POST['default_select']) && $_POST['default_select'] === 'no_default')
550
						{
551
							$default = 'no_default';
552
						}
553
554
						$field_options = substr($field_options, 0, -1);
555
					}
556
557
					break;
558
				default:
559
					$default = $this->_req->post->default_value ?? '';
560
			}
561
562
			// Come up with the unique name?
563
			if (empty($context['fid']))
564
			{
565
				$colname = Util::substr(strtr($this->_req->post->field_name, [' ' => '']), 0, 6);
566
				preg_match('~([\w_-]+)~', $colname, $matches);
567
568
				// If there is nothing to the name, then let's start our own - for foreign languages etc.
569
				if (isset($matches[1]))
570
				{
571
					$colname = 'cust_' . strtolower($matches[1]);
572
					$initial_colname = 'cust_' . strtolower($matches[1]);
573
				}
574
				else
575
				{
576
					$colname = 'cust_' . mt_rand(1, 999999);
577
					$initial_colname = 'cust_' . mt_rand(1, 999999);
578
				}
579
580
				$unique = ensureUniqueProfileField($colname, $initial_colname);
581
582
				// Still not a unique column name? Leave it up to the user, then.
583
				if (!$unique)
584
				{
585
					throw new Exception('custom_option_not_unique');
586
				}
587
588
				// And create a new field
589
				$new_field = [
590
					'col_name' => $colname,
591
					'field_name' => $this->_req->post->field_name,
592
					'field_desc' => $this->_req->post->field_desc,
593
					'field_type' => $this->_req->post->field_type,
594
					'field_length' => $field_length,
595
					'field_options' => $field_options,
596
					'show_reg' => $show_reg,
597
					'show_display' => $show_display,
598
					'show_memberlist' => $show_memberlist,
599
					'show_profile' => $show_profile,
600
					'private' => $private,
601
					'active' => $active,
602
					'default_value' => $default,
603
					'rows' => $rows,
604
					'cols' => $cols,
605
					'can_search' => $can_search,
606
					'bbc' => $bbc,
607
					'mask' => $mask,
608
					'enclose' => $enclose,
609
					'placement' => $placement,
610
					'vieworder' => list_getProfileFieldSize() + 1,
611
				];
612
				addProfileField($new_field);
613
			}
614
			// Work out what to do with the user data otherwise...
615
			else
616
			{
617
				// Anything going to check or select is pointless keeping - as is anything coming from check!
618
				if (($this->_req->post->field_type === 'check' && $context['field']['type'] !== 'check')
619
					|| (($this->_req->post->field_type === 'select' || $this->_req->post->field_type === 'radio') && $context['field']['type'] !== 'select' && $context['field']['type'] !== 'radio')
620
					|| ($context['field']['type'] === 'check' && $this->_req->post->field_type !== 'check'))
621
				{
622
					deleteProfileFieldUserData($context['field']['colname']);
623
				}
624
				// Otherwise - if the select is edited may need to adjust!
625
				elseif ($this->_req->post->field_type === 'select' || $this->_req->post->field_type === 'radio')
626
				{
627
					$optionChanges = $context['field']['options'];
628
					$takenKeys = [];
629
630
					// Work out what's changed!
631
					foreach ($optionChanges as $k => $option)
632
					{
633
						if (trim($option) === '')
634
						{
635
							continue;
636
						}
637
638
						// Still exists?
639
						if (in_array($option, $newOptions))
640
						{
641
							$takenKeys[] = $k;
642
						}
643
					}
644
645
					// Finally - have we renamed it - or is it really gone?
646
					foreach ($optionChanges as $k => $option)
647
					{
648
						// Just been renamed?
649
						if (in_array($k, $takenKeys))
650
						{
651
							continue;
652
						}
653
654
						if (empty($newOptions[$k]))
655
						{
656
							continue;
657
						}
658
659
						updateRenamedProfileField($k, $newOptions, $context['field']['colname'], $option);
660
					}
661
				}
662
663
				// @todo Maybe we should adjust based on new text length limits?
664
665
				// And finally update an existing field
666
				$field_data = [
667
					'field_length' => $field_length,
668
					'show_reg' => $show_reg,
669
					'show_display' => $show_display,
670
					'show_memberlist' => $show_memberlist,
671
					'private' => $private,
672
					'active' => $active,
673
					'can_search' => $can_search,
674
					'bbc' => $bbc,
675
					'current_field' => $context['fid'],
676
					'field_name' => $this->_req->post->field_name,
677
					'field_desc' => $this->_req->post->field_desc,
678
					'field_type' => $this->_req->post->field_type,
679
					'field_options' => $field_options,
680
					'show_profile' => $show_profile,
681
					'default_value' => $default,
682
					'mask' => $mask,
683
					'enclose' => $enclose,
684
					'placement' => $placement,
685
					'rows' => $rows,
686
					'cols' => $cols,
687
				];
688
689
				updateProfileField($field_data);
690
691
				// Just clean up any old selects - these are a pain!
692
				if (($this->_req->post->field_type === 'select' || $this->_req->post->field_type === 'radio') && !empty($newOptions))
693
				{
694
					deleteOldProfileFieldSelects($newOptions, $context['field']['colname']);
695
				}
696
			}
697
		}
698
		// Deleting?
699
		elseif (isset($this->_req->post->delete) && $context['field']['colname'])
700
		{
701
			checkSession();
702
			validateToken('admin-ecp');
703
704
			// Delete the old data first, then the field.
705
			deleteProfileFieldUserData($context['field']['colname']);
706
			deleteProfileField($context['fid']);
707
		}
708
709
		// Rebuild display cache etc.
710
		if (isset($this->_req->post->delete) || isset($this->_req->post->save) || isset($this->_req->post->onoff))
711
		{
712
			checkSession();
713
714
			// Update the display cache
715
			updateDisplayCache();
716
			redirectexit('action=admin;area=featuresettings;sa=profile');
717
		}
718
719
		createToken('admin-ecp');
720
	}
721
}
722