4 * Copyright (C) 2010, Free Software Foundation, Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Max Shinn <trombonechamp@gmail.com>
25 * @copyright 2010 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 if (!defined('STATUSNET')) {
33 require_once INSTALLDIR . '/lib/adminpanelaction.php';
35 class ProfilefieldsAdminPanelAction extends AdminPanelAction
40 return _('Profile fields');
43 function getInstructions()
45 return _('GNU Social custom profile fields');
50 $form = new ProfilefieldsAdminForm($this);
55 function saveSettings()
57 $field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
59 $field = new GNUsocialProfileExtensionField();
60 $field->title = $this->trimmed('title');
61 $field->description = $this->trimmed('description');
62 $field->type = $this->trimmed('type');
63 $field->systemname = $this->trimmed('systemname');
64 if (!gnusocial_field_systemname_validate($field->systemname)) {
65 $this->clientError(_('Internal system name must be unique and consist of only alphanumeric characters!'));
68 if ($field->validate())
71 $this->clientError(_('There was an error with the field data.'));
83 class ProfilefieldsAdminForm extends AdminForm
88 return 'form_profilefields_admin_panel';
93 return 'form_settings';
98 return '/admin/profilefields';
108 $fieldsettitle = _("New Profile Field");
110 if ($this->out->trimmed('edit')) {
111 $field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit'));
112 $title = $field->title;
113 $description = $field->description;
114 $type = $field->type;
115 $systemname = $field->systemname;
116 $this->out->hidden('id', $field->id, 'id');
117 $fieldsettitle = _("Edit Profile Field");
119 //Don't show the list of all fields when editing one
121 $this->out->elementStart('fieldset');
122 $this->out->element('legend', null, _('Existing Custom Profile Fields'));
123 $this->out->elementStart('ul', 'form_data');
124 $fields = GNUsocialProfileExtensionField::allFields();
125 foreach ($fields as $field) {
128 $this->out->elementStart('div');
129 $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
131 $this->out->text(' (' . $field->type . '): ' . $field->description);
132 $this->out->elementEnd('div');
135 $this->out->elementEnd('ul');
136 $this->out->elementEnd('fieldset');
140 $this->out->elementStart('fieldset');
141 $this->out->element('legend', null, $fieldsettitle);
142 $this->out->elementStart('ul', 'form_data');
145 $this->out->input('title', _('Title'), $title,
146 _('The title of the field'));
149 $this->out->input('systemname', _('Internal name'), $systemname,
150 _('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)'));
153 $this->out->input('description', _('Description'), $description,
154 _('An optional more detailed description of the field'));
157 $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
158 'str' => _("String")),
159 _('The type of the datafield'), false, $type);
161 $this->out->elementEnd('ul');
162 $this->out->elementEnd('fieldset');
171 function formActions()
173 $this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));