123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- require_once INSTALLDIR . '/lib/adminpanelaction.php';
- class ProfilefieldsAdminPanelAction extends AdminPanelAction
- {
- function title()
- {
- return _('Profile fields');
- }
- function getInstructions()
- {
- return _('GNU Social custom profile fields');
- }
- function showForm()
- {
- $form = new ProfilefieldsAdminForm($this);
- $form->show();
- return;
- }
- function saveSettings()
- {
- $field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
- if (!$field)
- $field = new GNUsocialProfileExtensionField();
- $field->title = $this->trimmed('title');
- $field->description = $this->trimmed('description');
- $field->type = $this->trimmed('type');
- $field->systemname = $this->trimmed('systemname');
- if (!gnusocial_field_systemname_validate($field->systemname)) {
- $this->clientError(_('Internal system name must be unique and consist of only alphanumeric characters!'));
- }
- if ($field->id) {
- if ($field->validate())
- $field->update();
- else {
- $this->clientError(_('There was an error with the field data.'));
- }
- }
- else {
- $field->insert();
- }
- return;
- }
- }
- class ProfilefieldsAdminForm extends AdminForm
- {
- function id()
- {
- return 'form_profilefields_admin_panel';
- }
- function formClass()
- {
- return 'form_settings';
- }
- function action()
- {
- return '/admin/profilefields';
- }
- function formData()
- {
- $title = null;
- $description = null;
- $type = null;
- $systemname = null;
- $id = null;
- $fieldsettitle = _("New Profile Field");
-
- if ($this->out->trimmed('edit')) {
- $field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit'));
- $title = $field->title;
- $description = $field->description;
- $type = $field->type;
- $systemname = $field->systemname;
- $this->out->hidden('id', $field->id, 'id');
- $fieldsettitle = _("Edit Profile Field");
- }
-
- else {
- $this->out->elementStart('fieldset');
- $this->out->element('legend', null, _('Existing Custom Profile Fields'));
- $this->out->elementStart('ul', 'form_data');
- $fields = GNUsocialProfileExtensionField::allFields();
- foreach ($fields as $field) {
- $this->li();
- $content =
- $this->out->elementStart('div');
- $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
- $field->title);
- $this->out->text(' (' . $field->type . '): ' . $field->description);
- $this->out->elementEnd('div');
- $this->unli();
- }
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- }
-
- $this->out->elementStart('fieldset');
- $this->out->element('legend', null, $fieldsettitle);
- $this->out->elementStart('ul', 'form_data');
- $this->li();
- $this->out->input('title', _('Title'), $title,
- _('The title of the field'));
- $this->unli();
- $this->li();
- $this->out->input('systemname', _('Internal name'), $systemname,
- _('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)'));
- $this->unli();
- $this->li();
- $this->out->input('description', _('Description'), $description,
- _('An optional more detailed description of the field'));
- $this->unli();
- $this->li();
- $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
- 'str' => _("String")),
- _('The type of the datafield'), false, $type);
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- }
-
- function formActions()
- {
- $this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));
- }
- }
|