]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialProfileExtensions/actions/profilefields.php
Merge remote-tracking branch 'upstream/master' into social-master
[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         }
67         if ($field->id) {
68             if ($field->validate())
69                 $field->update();
70             else {
71                 $this->clientError(_('There was an error with the field data.'));
72             }
73         }
74         else {
75             $field->insert();
76         }
77
78         return;
79     }
80
81 }
82
83 class ProfilefieldsAdminForm extends AdminForm
84 {
85
86     function id()
87     {
88         return 'form_profilefields_admin_panel';
89     }
90
91     function formClass()
92     {
93         return 'form_settings';
94     }
95
96     function action()
97     {
98         return '/admin/profilefields';
99     }
100
101     function formData()
102     {
103         $title = null;
104         $description = null;
105         $type = null;
106         $systemname = null;
107         $id = null;
108         $fieldsettitle = _("New Profile Field");
109         //Edit a 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");
118         }
119         //Don't show the list of all fields when editing one
120         else { 
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) {
126                 $this->li();
127                 $content = 
128                 $this->out->elementStart('div');
129                 $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
130                                     $field->title);
131                 $this->out->text(' (' . $field->type . '): ' . $field->description);
132                 $this->out->elementEnd('div');
133                 $this->unli();
134             }
135             $this->out->elementEnd('ul');
136             $this->out->elementEnd('fieldset');
137         }
138
139         //New fields
140         $this->out->elementStart('fieldset');
141         $this->out->element('legend', null, $fieldsettitle);
142         $this->out->elementStart('ul', 'form_data');
143
144         $this->li();
145         $this->out->input('title', _('Title'), $title,
146                      _('The title of the field'));
147         $this->unli();
148         $this->li();
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)'));
151         $this->unli();
152         $this->li();
153         $this->out->input('description', _('Description'), $description,
154                      _('An optional more detailed description of the field'));
155         $this->unli();
156         $this->li();
157         $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
158                                                       'str' => _("String")), 
159                              _('The type of the datafield'), false, $type);
160         $this->unli();
161         $this->out->elementEnd('ul');
162         $this->out->elementEnd('fieldset');
163     }
164
165     /**
166      * Action elements
167      *
168      * @return void
169      */
170
171     function formActions()
172     {
173         $this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));
174     }
175 }