create.php 4.75 KB
Newer Older
Martyn Smith's avatar
Martyn Smith committed
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
Martyn Smith's avatar
Martyn Smith committed
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Martyn Smith's avatar
Martyn Smith committed
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * 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 General Public License for more details.
Martyn Smith's avatar
Martyn Smith committed
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Martyn Smith's avatar
Martyn Smith committed
19
20
21
 *
 * @package    mahara
 * @subpackage core
22
 * @author     Catalyst IT Ltd
Martyn Smith's avatar
Martyn Smith committed
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
Martyn Smith's avatar
Martyn Smith committed
25
26
27
28
 *
 */

define('INTERNAL', 1);
29
define('MENUITEM', 'groups/groupsiown');
30
require(dirname(dirname(__FILE__)) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
31
require_once('pieforms/pieform.php');
32
require_once('group.php');
33
define('TITLE', get_string('creategroup', 'group'));
Martyn Smith's avatar
Martyn Smith committed
34

35
36
37
38
if (!group_can_create_groups()) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}

39
40
$creategroup = pieform(array(
    'name'     => 'creategroup',
Martyn Smith's avatar
Martyn Smith committed
41
    'method'   => 'post',
42
    'plugintype' => 'core',
43
    'pluginname' => 'groups',
Martyn Smith's avatar
Martyn Smith committed
44
45
46
    'elements' => array(
        'name' => array(
            'type'         => 'text',
47
            'title'        => get_string('groupname', 'group'),
Penny Leach's avatar
Penny Leach committed
48
            'rules'        => array( 'required' => true, 'maxlength' => 128 ),
Martyn Smith's avatar
Martyn Smith committed
49
50
51
        ),
        'description' => array(
            'type'         => 'wysiwyg',
52
            'title'        => get_string('groupdescription', 'group'),
Martyn Smith's avatar
Martyn Smith committed
53
            'rows'         => 10,
54
            'cols'         => 55,
Martyn Smith's avatar
Martyn Smith committed
55
        ),
56
        'grouptype' => array(
Martyn Smith's avatar
Martyn Smith committed
57
            'type'         => 'select',
58
            'title'        => get_string('grouptype', 'group'),
59
            'options'      => group_get_grouptype_options(),
60
            'defaultvalue' => 'standard.open',
61
            'help'         => true,
Martyn Smith's avatar
Martyn Smith committed
62
        ),
63
64
65
66
67
68
69
70
71
72
        'public' => array(
            'type'         => 'select',
            'title'        => get_string('publiclyviewablegroup', 'group'),
            'description'  => get_string('publiclyviewablegroupdescription', 'group'),
            'options'      => array(true  => get_string('yes'),
                                    false => get_string('no')),
            'defaultvalue' => 'no',
            'help'         => true,
            'ignore'       => !(get_config('createpublicgroups') == 'all' || get_config('createpublicgroups') == 'admins' && $USER->get('admin')),
        ),
73
74
75
76
77
78
79
80
81
82
        'usersautoadded' => array(
            'type'         => 'select',
            'title'        => get_string('usersautoadded', 'group'),
            'description'  => get_string('usersautoaddeddescription', 'group'),
            'options'      => array(true  => get_string('yes'),
                                    false => get_string('no')),
            'defaultvalue' => 'no',
            'help'         => true,
            'ignore'       => !$USER->get('admin'),
        ),
Martyn Smith's avatar
Martyn Smith committed
83
84
        'submit'   => array(
            'type'  => 'submitcancel',
85
            'value' => array(get_string('savegroup', 'group'), get_string('cancel')),
Martyn Smith's avatar
Martyn Smith committed
86
87
88
89
        ),
    ),
));

90
$smarty = smarty();
91
$smarty->assign('form', $creategroup);
92
$smarty->assign('PAGEHEADING', hsc(TITLE));
93
$smarty->display('form.tpl');
Martyn Smith's avatar
Martyn Smith committed
94
95


96
97
function creategroup_validate(Pieform $form, $values) {
    if (get_field('group', 'id', 'name', $values['name'])) {
98
        $form->set_error('name', get_string('groupalreadyexists', 'group'));
Martyn Smith's avatar
Martyn Smith committed
99
100
101
    }
}

102
function creategroup_cancel_submit() {
103
    redirect('/group/mygroups.php');
Martyn Smith's avatar
Martyn Smith committed
104
105
}

106
function creategroup_submit(Pieform $form, $values) {
Martyn Smith's avatar
Martyn Smith committed
107
108
109
    global $USER;
    global $SESSION;

110
    list($grouptype, $jointype) = explode('.', $values['grouptype']);
111
    $values['public'] = (isset($values['public'])) ? $values['public'] : 0;
112
    $values['usersautoadded'] = (isset($values['usersautoadded'])) ? $values['usersautoadded'] : 0;
113

114
    $id = group_create(array(
115
116
117
118
119
120
121
        'name'           => $values['name'],
        'description'    => $values['description'],
        'grouptype'      => $grouptype,
        'jointype'       => $jointype,
        'public'         => intval($values['public']),
        'usersautoadded' => intval($values['usersautoadded']),
        'members'        => array($USER->get('id') => 'admin'),
122
    ));
123

124
125
    $USER->reset_grouproles();

126
    $SESSION->add_ok_msg(get_string('groupsaved', 'group'));
Martyn Smith's avatar
Martyn Smith committed
127

128
    redirect('/group/view.php?id=' . $id);
Martyn Smith's avatar
Martyn Smith committed
129
130
131
}

?>