1<?php
2/**
3 * Elgg profile plugin edit default profile action
4 */
5
6$label = get_input('label');
7$type = get_input('type');
8$id = get_input('id');
9
10if (!$label || !$type) {
11	return elgg_error_response(elgg_echo('profile:editdefault:fail'));
12}
13
14if ($id === '') {
15	$custom_fields = elgg_get_config('profile_custom_fields');
16	$fieldlist = [];
17	if (!empty($custom_fields) || ($custom_fields === '0')) {
18		$fieldlist = explode(',', $custom_fields);
19	}
20
21	$id = (int) count($fieldlist) ? ((int) max($fieldlist) + 1) : 0;
22
23	$fieldlist[] = $id;
24
25	$fieldlist = implode(',', $fieldlist);
26
27	if (!elgg_save_config('profile_custom_fields', $fieldlist)) {
28		return elgg_error_response(elgg_echo('profile:editdefault:fail'));
29	}
30}
31
32if (!elgg_save_config("admin_defined_profile_$id", $label) || !elgg_save_config("admin_defined_profile_type_$id", $type)) {
33	return elgg_error_response(elgg_echo('profile:editdefault:fail'));
34}
35
36return elgg_ok_response('', elgg_echo('profile:editdefault:success'));
37