3 * Laconica, the distributed open-source microblogging tool
5 * Edit an existing group
9 * LICENCE: 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 Evan Prodromou <evan@controlyourself.ca>
25 * @author Sarven Capadisli <csarven@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
38 * This is the form for adding a new group
42 * @author Evan Prodromou <evan@controlyourself.ca>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://laconi.ca/
47 class EditgroupAction extends Action
54 return sprintf(_('Edit %s group'), $this->group->nickname);
61 function prepare($args)
63 parent::prepare($args);
65 if (!common_config('inboxes','enabled')) {
66 $this->serverError(_('Inboxes must be enabled for groups to work'));
70 if (!common_logged_in()) {
71 $this->clientError(_('You must be logged in to create a group.'));
75 $nickname_arg = $this->trimmed('nickname');
76 $nickname = common_canonical_nickname($nickname_arg);
78 // Permanent redirect on non-canonical nickname
80 if ($nickname_arg != $nickname) {
81 $args = array('nickname' => $nickname);
82 common_redirect(common_local_url('editgroup', $args), 301);
87 $this->clientError(_('No nickname'), 404);
91 $groupid = $this->trimmed('groupid');
93 $this->group = User_group::staticGet('id', $groupid);
95 $this->group = User_group::staticGet('nickname', $nickname);
99 $this->clientError(_('No such group'), 404);
103 $cur = common_current_user();
105 if (!$cur->isAdmin($this->group)) {
106 $this->clientError(_('You must be an admin to edit the group'), 403);
116 * On GET, show the form. On POST, try to save the group.
118 * @param array $args unused
123 function handle($args)
125 parent::handle($args);
126 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
133 function showForm($msg=null)
139 function showLocalNav()
141 $nav = new GroupNav($this, $this->group);
145 function showContent()
147 $form = new GroupEditForm($this, $this->group);
151 function showPageNotice()
154 $this->element('p', 'error', $this->msg);
156 $this->element('p', 'instructions',
157 _('Use this form to edit the group.'));
163 $cur = common_current_user();
164 if (!$cur->isAdmin($this->group)) {
165 $this->clientError(_('You must be an admin to edit the group'), 403);
169 $nickname = common_canonical_nickname($this->trimmed('nickname'));
170 $fullname = $this->trimmed('fullname');
171 $homepage = $this->trimmed('homepage');
172 $description = $this->trimmed('description');
173 $location = $this->trimmed('location');
175 if (!Validate::string($nickname, array('min_length' => 1,
177 'format' => NICKNAME_FMT))) {
178 $this->showForm(_('Nickname must have only lowercase letters '.
179 'and numbers and no spaces.'));
181 } else if ($this->nicknameExists($nickname)) {
182 $this->showForm(_('Nickname already in use. Try another one.'));
184 } else if (!User_group::allowedNickname($nickname)) {
185 $this->showForm(_('Not a valid nickname.'));
187 } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
188 !Validate::uri($homepage,
189 array('allowed_schemes' =>
190 array('http', 'https')))) {
191 $this->showForm(_('Homepage is not a valid URL.'));
193 } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
194 $this->showForm(_('Full name is too long (max 255 chars).'));
196 } else if (!is_null($description) && mb_strlen($description) > 140) {
197 $this->showForm(_('description is too long (max 140 chars).'));
199 } else if (!is_null($location) && mb_strlen($location) > 255) {
200 $this->showForm(_('Location is too long (max 255 chars).'));
204 $orig = clone($this->group);
206 $this->group->nickname = $nickname;
207 $this->group->fullname = $fullname;
208 $this->group->homepage = $homepage;
209 $this->group->description = $description;
210 $this->group->location = $location;
211 $this->group->created = common_sql_now();
213 $result = $this->group->update($orig);
216 common_log_db_error($this->group, 'UPDATE', __FILE__);
217 $this->serverError(_('Could not update group.'));
220 if ($this->group->nickname != $orig->nickname) {
221 common_redirect(common_local_url('editgroup',
222 array('nickname' => $nickname)),
225 $this->showForm(_('Options saved.'));
229 function nicknameExists($nickname)
231 $group = User_group::staticGet('nickname', $nickname);
232 return (!is_null($group) &&
234 $group->id != $this->group->id);