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::staticGet('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!'));
69 if ($field->validate())
72 $this->clientError(_('There was an error with the field data.'));
85 class ProfilefieldsAdminForm extends AdminForm
90 return 'form_profilefields_admin_panel';
95 return 'form_settings';
100 return '/admin/profilefields';
110 $fieldsettitle = _("New Profile Field");
112 if ($this->out->trimmed('edit')) {
113 $field = GNUsocialProfileExtensionField::staticGet('id', $this->out->trimmed('edit'));
114 $title = $field->title;
115 $description = $field->description;
116 $type = $field->type;
117 $systemname = $field->systemname;
118 $this->out->hidden('id', $field->id, 'id');
119 $fieldsettitle = _("Edit Profile Field");
121 //Don't show the list of all fields when editing one
123 $this->out->elementStart('fieldset');
124 $this->out->element('legend', null, _('Existing Custom Profile Fields'));
125 $this->out->elementStart('ul', 'form_data');
126 $fields = GNUsocialProfileExtensionField::allFields();
127 foreach ($fields as $field) {
130 $this->out->elementStart('div');
131 $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
133 $this->out->text(' (' . $field->type . '): ' . $field->description);
134 $this->out->elementEnd('div');
137 $this->out->elementEnd('ul');
138 $this->out->elementEnd('fieldset');
142 $this->out->elementStart('fieldset');
143 $this->out->element('legend', null, $fieldsettitle);
144 $this->out->elementStart('ul', 'form_data');
147 $this->out->input('title', _('Title'), $title,
148 _('The title of the field'));
151 $this->out->input('systemname', _('Internal name'), $systemname,
152 _('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)'));
155 $this->out->input('description', _('Description'), $description,
156 _('An optional more detailed description of the field'));
159 $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
160 'str' => _("String")),
161 _('The type of the datafield'), false, $type);
163 $this->out->elementEnd('ul');
164 $this->out->elementEnd('fieldset');
173 function formActions()
175 $this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));