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 $this->group = User_group::staticGet('nickname', $nickname);
94 $this->clientError(_('No such group'), 404);
98 $cur = common_current_user();
100 if (!$cur->isAdmin($group)) {
101 $this->clientError(_('You must be an admin to edit the group'), 403);
111 * On GET, show the form. On POST, try to save the group.
113 * @param array $args unused
118 function handle($args)
120 parent::handle($args);
121 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
128 function showForm($msg=null)
134 function showLocalNav()
136 $nav = new GroupNav($this, $this->group);
140 function showContent()
142 $form = new GroupEditForm($this, $this->group);
146 function showPageNotice()
149 $this->element('p', 'error', $this->msg);
151 $this->element('p', 'instructions',
152 _('Use this form to edit the group.'));
158 $nickname = common_canonical_nickname($this->trimmed('nickname'));
159 $fullname = $this->trimmed('fullname');
160 $homepage = $this->trimmed('homepage');
161 $description = $this->trimmed('description');
162 $location = $this->trimmed('location');
164 if (!Validate::string($nickname, array('min_length' => 1,
166 'format' => NICKNAME_FMT))) {
167 $this->showForm(_('Nickname must have only lowercase letters '.
168 'and numbers and no spaces.'));
170 } else if ($this->nicknameExists($nickname)) {
171 $this->showForm(_('Nickname already in use. Try another one.'));
173 } else if (!User_group::allowedNickname($nickname)) {
174 $this->showForm(_('Not a valid nickname.'));
176 } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
177 !Validate::uri($homepage,
178 array('allowed_schemes' =>
179 array('http', 'https')))) {
180 $this->showForm(_('Homepage is not a valid URL.'));
182 } else if (!is_null($fullname) && strlen($fullname) > 255) {
183 $this->showForm(_('Full name is too long (max 255 chars).'));
185 } else if (!is_null($description) && strlen($description) > 140) {
186 $this->showForm(_('description is too long (max 140 chars).'));
188 } else if (!is_null($location) && strlen($location) > 255) {
189 $this->showForm(_('Location is too long (max 255 chars).'));
193 $orig = clone($this->group);
195 $this->group->nickname = $nickname;
196 $this->group->fullname = $fullname;
197 $this->group->homepage = $homepage;
198 $this->group->description = $description;
199 $this->group->location = $location;
200 $this->group->created = common_sql_now();
202 $result = $this->group->update($orig);
205 common_log_db_error($this->group, 'UPDATE', __FILE__);
206 $this->serverError(_('Could not update group.'));
209 if ($this->group->nickname != $orig->nickname) {
210 common_redirect(common_local_url('editgroup',
211 array('nickname' => $nickname)),
214 $this->showForm(_('Options saved.'));
218 function nicknameExists($nickname)
220 $group = User_group::staticGet('nickname', $nickname);
221 return (!is_null($group) &&
223 $group->id != $this->group->id);