groupeditform.php 5.88 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
<?php
/**
 * Laconica, the distributed open-source microblogging tool
 *
 * Form for editing a group
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Form
 * @package   Laconica
 * @author    Evan Prodromou <evan@controlyourself.ca>
 * @author    Sarven Capadisli <csarven@controlyourself.ca>
 * @copyright 2009 Control Yourself, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://laconi.ca/
 */

if (!defined('LACONICA')) {
    exit(1);
}

require_once INSTALLDIR.'/lib/form.php';

/**
 * Form for editing a group
 *
 * @category Form
 * @package  Laconica
 * @author   Evan Prodromou <evan@controlyourself.ca>
 * @author   Sarven Capadisli <csarven@controlyourself.ca>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://laconi.ca/
 *
 * @see      UnsubscribeForm
 */

class GroupEditForm extends Form
{
    /**
     * group for user to join
     */

    var $group = null;

    /**
     * Constructor
     *
     * @param Action     $out   output channel
     * @param User_group $group group to join
     */

    function __construct($out=null, $group=null)
    {
        parent::__construct($out);

        $this->group = $group;
    }

    /**
     * ID of the form
     *
     * @return string ID of the form
     */

    function id()
    {
        if ($this->group) {
81
            return 'form_group_edit-' . $this->group->id;
Evan Prodromou's avatar
Evan Prodromou committed
82
        } else {
83
            return 'form_group_add';
Evan Prodromou's avatar
Evan Prodromou committed
84 85 86 87 88 89 90 91 92 93 94
        }
    }

    /**
     * class of the form
     *
     * @return string of the form class
     */

    function formClass()
    {
95
        return 'form_settings';
Evan Prodromou's avatar
Evan Prodromou committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    }

    /**
     * Action of the form
     *
     * @return string URL of the action
     */

    function action()
    {
        if ($this->group) {
            return common_local_url('editgroup',
                                    array('nickname' => $this->group->nickname));
        } else {
            return common_local_url('newgroup');
        }
    }

114 115 116 117 118 119 120 121 122 123 124
    /**
     * Name of the form
     *
     * @return void
     */

    function formLegend()
    {
        $this->out->element('legend', null, _('Create a new group'));
    }

Evan Prodromou's avatar
Evan Prodromou committed
125 126 127 128 129 130 131 132
    /**
     * Data elements of the form
     *
     * @return void
     */

    function formData()
    {
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
        if ($this->group) {
            $id = $this->group->id;
            $nickname = $this->group->nickname;
            $fullname = $this->group->fullname;
            $homepage = $this->group->homepage;
            $description = $this->group->description;
            $location = $this->group->location;
        } else {
            $id = '';
            $nickname = '';
            $fullname = '';
            $homepage = '';
            $description = '';
            $location = '';
        }

Evan Prodromou's avatar
Evan Prodromou committed
149 150
        $this->out->elementStart('ul', 'form_data');
        $this->out->elementStart('li');
151
        $this->out->hidden('groupid', $id);
Evan Prodromou's avatar
Evan Prodromou committed
152
        $this->out->input('nickname', _('Nickname'),
153 154
                          ($this->out->arg('nickname')) ? $this->out->arg('nickname') : $nickname,
                          _('1-64 lowercase letters or numbers, no punctuation or spaces'));
Evan Prodromou's avatar
Evan Prodromou committed
155 156 157
        $this->out->elementEnd('li');
        $this->out->elementStart('li');
        $this->out->input('fullname', _('Full name'),
158
                          ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $fullname);
Evan Prodromou's avatar
Evan Prodromou committed
159 160 161
        $this->out->elementEnd('li');
        $this->out->elementStart('li');
        $this->out->input('homepage', _('Homepage'),
162 163
                          ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
                          _('URL of the homepage or blog of the group or topic'));
Evan Prodromou's avatar
Evan Prodromou committed
164 165
        $this->out->elementEnd('li');
        $this->out->elementStart('li');
166
        $this->out->textarea('description', _('Description'),
167 168
                             ($this->out->arg('description')) ? $this->out->arg('description') : $description,
                             _('Describe the group or topic in 140 chars'));
Evan Prodromou's avatar
Evan Prodromou committed
169 170 171
        $this->out->elementEnd('li');
        $this->out->elementStart('li');
        $this->out->input('location', _('Location'),
172 173
                          ($this->out->arg('location')) ? $this->out->arg('location') : $location,
                          _('Location for the group, if any, like "City, State (or Region), Country"'));
Evan Prodromou's avatar
Evan Prodromou committed
174
        $this->out->elementEnd('li');
175 176 177 178 179 180 181 182 183 184
        if (common_config('group', 'maxaliases') > 0) {
            $aliases = (empty($this->group)) ? array() : $this->group->getAliases();
            $this->out->elementStart('li');
            $this->out->input('aliases', _('Aliases'),
                              ($this->out->arg('aliases')) ? $this->out->arg('aliases') :
                              (!empty($aliases)) ? implode(' ', $aliases) : '',
                              sprintf(_('Extra nicknames for the group, comma- or space- separated, max %d'),
                                      common_config('group', 'maxaliases')));;
            $this->out->elementEnd('li');
        }
Evan Prodromou's avatar
Evan Prodromou committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198
        $this->out->elementEnd('ul');
    }

    /**
     * Action elements
     *
     * @return void
     */

    function formActions()
    {
        $this->out->submit('submit', _('Save'));
    }
}