]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialProfileExtensions/actions/profilefields.php
0076af1bd658d3150d9175c00f75019772eb0015
[quix0rs-gnu-social.git] / plugins / GNUsocialProfileExtensions / actions / profilefields.php
1 <?php
2 /**
3  * GNU Social
4  * Copyright (C) 2010, Free Software Foundation, Inc.
5  *
6  * PHP version 5
7  *
8  * LICENCE:
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Widget
23  * @package   GNU Social
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
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 require_once INSTALLDIR . '/lib/adminpanelaction.php';
34
35 class ProfilefieldsAdminPanelAction extends AdminPanelAction
36 {
37
38     function title()
39     {
40         return _('Profile fields');
41     }
42
43     function getInstructions()
44     {
45         return _('GNU Social custom profile fields');
46     }
47
48     function showForm()
49     {
50         $form = new ProfilefieldsAdminForm($this);
51         $form->show();
52         return;
53     }
54
55     function saveSettings()
56     {
57         $field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
58         if (!$field)
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!'));
66             return false;
67         }
68         if ($field->id) {
69             if ($field->validate())
70                 $field->update();
71             else {
72                 $this->clientError(_('There was an error with the field data.'));
73                 return false;
74             }
75         }
76         else {
77             $field->insert();
78         }
79
80         return;
81     }
82
83 }
84
85 class ProfilefieldsAdminForm extends AdminForm
86 {
87
88     function id()
89     {
90         return 'form_profilefields_admin_panel';
91     }
92
93     function formClass()
94     {
95         return 'form_settings';
96     }
97
98     function action()
99     {
100         return '/admin/profilefields';
101     }
102
103     function formData()
104     {
105         $title = null;
106         $description = null;
107         $type = null;
108         $systemname = null;
109         $id = null;
110         $fieldsettitle = _("New Profile Field");
111         //Edit a field
112         if ($this->out->trimmed('edit')) { 
113             $field = GNUsocialProfileExtensionField::getKV('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");
120         }
121         //Don't show the list of all fields when editing one
122         else { 
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) {
128                 $this->li();
129                 $content = 
130                 $this->out->elementStart('div');
131                 $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
132                                     $field->title);
133                 $this->out->text(' (' . $field->type . '): ' . $field->description);
134                 $this->out->elementEnd('div');
135                 $this->unli();
136             }
137             $this->out->elementEnd('ul');
138             $this->out->elementEnd('fieldset');
139         }
140
141         //New fields
142         $this->out->elementStart('fieldset');
143         $this->out->element('legend', null, $fieldsettitle);
144         $this->out->elementStart('ul', 'form_data');
145
146         $this->li();
147         $this->out->input('title', _('Title'), $title,
148                      _('The title of the field'));
149         $this->unli();
150         $this->li();
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)'));
153         $this->unli();
154         $this->li();
155         $this->out->input('description', _('Description'), $description,
156                      _('An optional more detailed description of the field'));
157         $this->unli();
158         $this->li();
159         $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
160                                                       'str' => _("String")), 
161                              _('The type of the datafield'), false, $type);
162         $this->unli();
163         $this->out->elementEnd('ul');
164         $this->out->elementEnd('fieldset');
165     }
166
167     /**
168      * Action elements
169      *
170      * @return void
171      */
172
173     function formActions()
174     {
175         $this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));
176     }
177 }